使用MD5的方法比对CXimage里图片是否改变:

Delphi7实现方法:

uses IdHashMessageDigest 

function TForm1.GetImageMD5(cxImage: TcxImage): string;
var
  tmpMD5: TIdHashMessageDigest5;
  ms: TMemoryStream;
begin
  result:='';
  if cxImage.Picture.Graphic=nil then exit;
  tmpMD5:=TIdHashMessageDigest5.Create;
  ms:= TMemoryStream.Create;
  try
    cxImage.Picture.Graphic.SaveToStream(ms);
    result:=tmpMD5.AsHex(tmpMD5.HashValue(ms));
  finally
    tmpMD5.Free;
    ms.Free;
  end;
end;
View Code

Delphi2010实现方法:

 1 uses IdHashMessageDigest
 2 
 3 function GetImageMD5(cxImage: TcxImage): string;
 4 var
 5   tmpMD5: TIdHashMessageDigest5;
 6   ms: TMemoryStream;
 7 begin
 8   result:='';
 9   if cxImage.Picture.Graphic=nil then exit;
10   tmpMD5:=TIdHashMessageDigest5.Create;
11   ms:= TMemoryStream.Create;
12   try
13     cxImage.Picture.Graphic.SaveToStream(ms);
14     ms.Position:=0;
15     result:=tmpMD5.HashStreamAsHex(ms);
16   finally
17     tmpMD5.Free;
18      ms.Free;
19   end;
20 end;
View Code

参考:http://www.cnblogs.com/jxsoft/archive/2011/08/08/2131436.html

posted on 2015-07-27 23:10  EEEEEEEEEEEEEEEEEEE  阅读(724)  评论(0编辑  收藏  举报