delphi 计算文件的MD5值

delphi求文件的MD5值Delphi6/7uses IdHashMessageDigest function TForm1.GetImageMD5(cxImage: TcxImage): string;var tmpMD5: TIdHashMessageDigest5; ms: TMemoryStre

delphi求文件的MD5值


Delphi6/7

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;


Delphi2010实现方法:

uses IdHashMessageDigest


function 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);

    ms.Position:=0;

    result:=tmpMD5.HashStreamAsHex(ms);

  finally

    tmpMD5.Free;

     ms.Free;

  end;

end;



相关推荐

[!--temp.pl--]