这是修正+取MD5的方法

function MD5FileTextPng(filename: AnsiString): AnsiString;
var
buf: array[..MAX_PATH - ] of Char;
path: AnsiString;
stream: TFileStream;
destStream: TMemoryStream;
destfile, tmpText: string;
I, len: Integer;
endbuf: array[..] of Byte;
firstChar: Byte;
strstream: TStringStream;
const
pngEndBuf: array[..] of Byte = ($AE, $, $, $);
begin
GetTempPath(Length(buf), @buf[]);
path := AnsiString(string(buf));
tmpText := ExtractFileName(filename);
tmpText := Copy(tmpText, , Length(tmpText) - ); strstream := TStringStream.Create(tmpText, TEncoding.UTF8);
strstream.Position := ; stream := TFileStream.Create(filename, fmOpenRead);
try
destStream := TMemoryStream.Create;
try
stream.Position := ;
for I := to stream.Size - do
begin
stream.Read(firstChar, );
if firstChar <> $AE then
Continue;
stream.Position := stream.Position - ;
stream.Read(endbuf[], );
if CompareMem(@endbuf[], @pngEndBuf[], ) then
begin
len := stream.Position;
Break;
end;
end; stream.Position := ;
destStream.CopyFrom(stream, len); destfile := path + '\' + GetRamdomText();
if FileExists(destfile) then
DeleteFile(destfile); destStream.CopyFrom(strstream, strstream.Size);
destStream.SaveToFile(destfile);
strstream.Free; Result := MD5F(destfile);
finally
destStream.Free;
end;
finally
stream.Free;
end; if FileExists(destfile) then
DeleteFile(destfile);
end;

这是批量修正PNG的代码,pas + dfm

uFixpng.pas
unit uFixpng;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, uMD5, Vcl.StdCtrls, Vcl.FileCtrl,
System.IOUtils, System.Types, Vcl.Samples.Gauges; type
TForm2 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
Gauge1: TGauge;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Edit1DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form2: TForm2; implementation {$R *.dfm} function FixPng(filename: AnsiString; destFileName: string): Boolean;
var
stream: TFileStream;
destStream: TMemoryStream;
I, len: Integer;
endbuf: array[..] of Byte;
firstChar: Byte;
const
pngEndBuf: array[..] of Byte = ($AE, $, $, $);
begin
stream := TFileStream.Create(filename, fmOpenRead);
try
destStream := TMemoryStream.Create;
try
stream.Position := ;
for I := to stream.Size - do
begin
stream.Read(firstChar, );
if firstChar <> $AE then Continue;
stream.Position := stream.Position - ;
stream.Read(endbuf[], );
if CompareMem(@endbuf[], @pngEndBuf[], ) then
begin
len := stream.Position;
Break;
end;
end; stream.Position := ;
destStream.CopyFrom(stream, len);
destStream.SaveToFile(destFileName);
finally
destStream.Free;
end;
finally
stream.Free;
end; Result := True;
end; procedure TForm2.Button1Click(Sender: TObject);
var
files: TStringDynArray;
path, destPath, destFile: string;
I: Integer;
begin
TButton(Sender).Enabled := False;
Gauge1.Visible := True;
try
path := Trim(Edit1.Text);
if not TDirectory.Exists(path) then Exit; files := TDirectory.GetFiles(path, '*.png'); destPath := TPath.Combine(path, 'Fix-' + FormatDateTime('hhnnss', Now)); if not TDirectory.Exists(destPath) then
TDirectory.CreateDirectory(destPath); Gauge1.Progress := ;
Gauge1.MinValue := ;
Gauge1.MaxValue := Length(files);
for I := Low(files) to High(files) do
begin
destFile := TPath.Combine(destPath, ExtractFileName(files[I]));
FixPng(files[I], destFile);
Gauge1.Progress := Gauge1.Progress + ;
Application.ProcessMessages;
end;
finally
TButton(Sender).Enabled := True;
Gauge1.Visible := False;
end;
end; procedure TForm2.Edit1DblClick(Sender: TObject);
var
path: string;
begin
SelectDirectory('选择png文件夹', '', path);
Edit1.Text := path;
end; procedure TForm2.FormCreate(Sender: TObject);
begin
Position := poScreenCenter;
end; end.

uFixpng.dfm

object Form2: TForm2
Left =
Top =
Caption = ##'png'
ClientHeight =
ClientWidth =
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch =
TextHeight =
object Label1: TLabel
Left =
Top =
Width =
Height =
Caption = 'PNG'####
end
object Gauge1: TGauge
Left =
Top =
Width =
Height =
Align = alBottom
Color = clNavy
ParentColor = False
Progress =
ShowText = False
Visible = False
end
object Edit1: TEdit
Left =
Top =
Width =
Height =
TabOrder =
OnDblClick = Edit1DblClick
end
object Button1: TButton
Left =
Top =
Width =
Height =
Caption = ####
TabOrder =
OnClick = Button1Click
end
end

最新文章

  1. git commit之后未submit,rebase之后找不到自己代码的处理方法
  2. Atitit.Atiposter&#160;发帖机&#160;信息发布器 v7 q516
  3. python 笔记
  4. 用户管理 之 Linux 用户(User)查询篇
  5. 【pyQuery】抓取startup news首页
  6. 想做一个整合开源安全代码扫描工具的代码安全分析平台 - Android方向调研
  7. mkimage使用详解
  8. C++获取当前机器内网IP地址
  9. Android应用性能測试
  10. 四个漂亮CSS样式表
  11. 老李推荐:第2章1节《MonkeyRunner源码剖析》了解你的测试对象: NotePad应用简介
  12. RDC去省赛玩前の日常训练 Chapter 1
  13. 001 UI介绍
  14. Android EventBus技能点梳理
  15. java中 &amp; ^ ~ 的运算
  16. 阿里云 轻量应用服务器(LAMP) 使用日志记录
  17. c# 中HttpClient访问Https网站
  18. rabbimq
  19. tp框架 php ajax 登陆
  20. MySql 常见错误代码大全 VV2

热门文章

  1. 学习笔记(2)- BioBERT
  2. Centos7 设置自定义安装nginx的systemctl启动方式
  3. windows 创建软连接
  4. vbs操作IE对象
  5. iOS收起键盘
  6. linux的ls -al指令
  7. QQ企业通---登录模块设计--知识点
  8. 【剑指Offer面试编程题】题目1384:二维数组中的查找--九度OJ
  9. 【转载】Git设置单个文件上传大小
  10. PAT B1020 月饼