这是修正+取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

修正png的更多相关文章

  1. [修正] Firemonkey 中英文混排折行问题(移动平台)

    问题:FMX 在移动平台的文字显示并非由该平台的原生 API 来显示,而是由 FMX.TextLayout.GPU 来处理,也许是官方没留意到中文字符的问题,造成在中英文混排折行时,有些问题. 适用: ...

  2. [修正] Firemonkey Android 显示 Emoji (颜文字)

    问题:在 Android 平台下,显示 Emoji 文字,无法显示彩色(皆为黑色),例如 Edit 控件,即使将 Edit.ControlType = Platform 设为平台原生控件,还是没用(真 ...

  3. 2016 正确 sublime安装PHPcs PHPcodesniffer代码规范提示插件,修正网上部分不详细描述

    对你有助请点赞,请顶,不好请踩------送人玫瑰,手留余香!-------------------14:37 2016/3/212016 正确 sublime安装PHPcs PHPcodesniff ...

  4. Mint Linux 安装 DotnetCore 遭遇无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系

    evlon@evlon-ThinkPad-T530 ~ $ apt install dotnet-dev-1.0.0-preview2-003121 正在读取软件包列表... 完成 正在分析软件包的依 ...

  5. 修正IE6不支持position:fixed的bug(转)

    众所周知IE6不支持position:fixed,这个bug与IE6的双倍margin和不支持PNG透明等bug一样臭名昭著.前些天我做自己的博客模板的时候,遇到了这个问题.当时就简单的无视了IE6— ...

  6. [修正] 移动平台曲线不平滑的问题(如:TRectangle, TPath...等)

    问题:从 XE4 以来,Firemonkey 曲线绘图在移动平台不平滑的问题一直令人诟病,提交到官方的 QC 也是族繁不及备载,官方似乎有意的避开这个问题,迟迟没有修正. 适用版本:XE4 ~ Ber ...

  7. [修正] Firemonkey TSelection 控件等比缩放时,左下角拉动问题

    说明:TSelection 控件,当在属性 Proportional = True 为等比缩放时,拉动左下角,右上角会跟着移动. 适用:Berlin 10.1.1 (或之前版本) Firemonkey ...

  8. [修正] Berlin Firemonkey Windows 控件左方显示虚线问题

    说明:在 Wndows 显示时,有时控件左方会显示一条虚线 适用:Berlin Firemonkey 修正方法: 请将源码 FMX.Platform.Win.pas 复制到自己的工程目录里,再进行修改 ...

  9. 查看数据库表的数据量和SIZE大小的脚本修正

    在使用桦仔的分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间)的脚本时,遇到下面一些错误 这个是因为这些表的Schema是Maint,而不是默认的dbo,造成下面这段SQ ...

  10. WordPress基础:Gravatar头像修正

    WordPress会根据你的邮箱,从Gravatar获取你的头像,如果没有在Gravatar设置头像,将使用默认的,然而设置了之后显示还可能会出现以下问题: Gravatar头像读取困难,将影响网站读 ...

随机推荐

  1. mysql之魔鬼训练营

    普通 + 中等 难度练习题 测试数据: --建表 --学生表 CREATE TABLE `Student`( `s_id` VARCHAR(20), `s_name` VARCHAR(20) NOT ...

  2. 从零构建以太坊(Ethereum)智能合约到项目实战——第21章 搭建联盟链

    P78 .1-内容介绍 什么情况下建立自己测试用的PoA chain? 公司内网或无对外网络,无法同步区块 降低测试时等待区块的时间 不想碰到testrpc各种雷 PoA chain特点有 有别于Po ...

  3. C++常量表达式、const、constexpr(C++11新增)的区别

    常量表达式是指值不会改变且在编译过程中就能够得到计算结果的表达式,能在编译时求值的表达式. 程序先编译再运行:  在编译阶段, 编译器将在编译过程中把用到该常量的地方都全都替换为 常量的值. 但是常量 ...

  4. GitHub 网站汉化

    居然是一个中文Github网站!该不会是个假的吧? 2018-09-03 17:30 前几天分享了一篇文章——3个搜索技巧!在 GitHub上快速找到实用资源!眼尖心细的读者发现了文中的Github网 ...

  5. 一文解读CAP (转)

    分布式系统(distributed system)正变得越来越重要,大型网站几乎都是分布式的. 分布式系统的最大难点,就是各个节点的状态如何同步.CAP 定理是这方面的基本定理,也是理解分布式系统的起 ...

  6. 算法设计与分析 - AC 代码 - 第 6 弹(重复第 3 弹)

    PTA-算法设计与分析 - c++(g++) #include<bits/stdc++.h> using namespace std; long max3(long a,long b,lo ...

  7. vbs操作IE对象

    Dim fso,filepath,i 'Dim ExcelBook,ExcelSheet,MyExcelBook,MyExcelSheet Dim ie Set ie=WScript.CreateOb ...

  8. PHP 三元运算符

    $a = $a ? $a : 1;//第一种 $a = $a ? : 1;//第二种 第二种写法从 PHP 5.3 引入,表示若 $a 返回值为真时,取 $a 的返回值. 此外,在 PHP7 中引入了 ...

  9. 构建javascript array包

    //像一个数组添加数组. copyArray = function(inSrcArray,inDestArray){ var i; for(i=0;i<inSrcArray.length;i++ ...

  10. H5地理定位获取用户当前位置、城市

    第一步:需要在百度地图开发者平台创建一个应用:http://lbsyun.baidu.com/apiconsole/key/create 配置信息 申请配置成功以后返回一个AK 第二步:引入百度地图的 ...