Delphi7写的图片结构信息获取器
哎感觉没多大用处的,当时写这程序时主要用于研究图形图像验证码部分,后面没研究了。function ConverStr(S: String): String;
const
HexHead: String = ' Offset 0123456789ABCDEF';
var
SL: TStringList;
I,J,K,L: Integer;
StrHex,StrChr,StrOut: String;
begin
StrOut := '';
StrOut := StrOut + HexHead + #13#10;
if(Length(S) = 0) then
begin
Result := StrOut;
exit;
end;
SL := TStringList.Create;
SL.Text := StringReplace(Trim(S),' ',#13,);
J := 0;
StrOut := StrOut + IntToHex(J,8) + ' ';
StrHex := '';
StrChr := '';
for I := 0 to SL.Count - 1 do
begin
StrHex := StrHex + SL.Strings+' ';
if(SL.Strings = '00') or
(SL.Strings = '09') or
(SL.Strings = '0A') or
(SL.Strings = '0D') or
(SL.Strings = 'FF') then
begin
StrChr := StrChr + '.';
end
else begin
StrChr := StrChr + Char(StrToInt('$'+SL.Strings));
end;
if(((I+1) mod 16) = 0) then
begin
StrOut := StrOut + StrHex + #9 + StrChr + #9 + #9#13#10;
J := J + $10;
StrOut := StrOut + IntToHex(J,8) + ' ';
StrHex := '';
StrChr := '';
end;
if(I = SL.Count - 1) then
begin
K := 16 -(SL.Count mod 16);
for L := 0 to K - 1 do
begin
StrHex := StrHex + ' ';
end;
StrOut := StrOut + StrHex + #9 + StrChr;
end;
end;
SL.Free;
Result := StrOut;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
PicDataLen:Integer;//读取图片数据的字节总数
//PicDataArray:array of Byte ; //图片数据数组
i:Integer ;
PicTF:TFileStream ;
PicDataStr:string ;
PicPath:string ;
begin
OpenDialog1.Filter:='*.jpg';
PicPath :='https://www.wgbcw.com';
if OpenDialog1.Execute then
begin
try
Image1.Picture.LoadFromFile(OpenDialog1.FileName);//OpenDialog1.FileName
PicTF :=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
PicTF.Position :=0;
PicDataLen :=PicTF.Size ;
SetLength(PicDataArray,PicDataLen +1);
PicTF.Read(PicDataArray,PicDataLen );
if PicDataLen >0then
begin
for i:=0 to PicDataLen-1 do
PicDataStr :=PicDataStr + IntToHex(PicDataArray,2)+' ';
Memo1.Text :=ConverStr(PicDataStr);
end;
finally
PicTF.Free ;
end;
end;
end;
procedure WordLoHiExchange(var w:Word); //高低位互换
var
b:Byte;
begin
b:=WordRec(w).Lo;
WordRec(w).Lo:=WordRec(w).Hi;
WordRec(w).Hi:=b;
end;
function GetHiByte(B: Byte ):Byte;
begin
Result :=B shr 4;
end;
function GetLoByte(B: Byte ): byte;
begin
Result :=B and $0F;
end;
function GetPiCData(P:Pointer;nTpye:Integer):string ;
var
wStr:Word;
begin
case nTpye of
1:Result := IntToHex(Pbyte(DWORD(p))^,2);
2:begin
wStr := PWord(DWORD(p))^;
WordLoHiExchange(wStr);
Result := IntToHex(wStr,4);
end;
end;
end;
procedure AddListView(s:string ;nType:Integer );//取图形结构加进ListView列表
var
Listtmp:TListItem;
B:string;
LhbJD:Byte ;//量化表精度
LhbID:Byte ;//量化表ID
Lhblen:Integer ;//量化表长度
LhbStr:string ;//量化表字串
i:Integer ;
begin
B :='2字节';
Listtmp := Form1.ListView1.Items.Add ;
Listtmp.Caption :=IntToHex(nType,4);
case nType of
0:begin
Listtmp.SubItems.Add(IntToHex(nType,4));
Listtmp.SubItems.Add(B);
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('图像开始标识');
Listtmp.SubItems.Add('(SOI)Start of Image');
end;
2:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add(B);
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('APP0标识开始JFIF应用数据块');
Listtmp.SubItems.Add('APP0(JFIF application segment)');
end;
4:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add(B);
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('APP0块的长度');
Listtmp.SubItems.Add('length of APP0 block');
end;
6:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('5字节');
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('JFIF0标识符');
Listtmp.SubItems.Add('JFIF0 identifier');
end;
11:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add(b);
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('图形主版本号+次版本号');
Listtmp.SubItems.Add('Major version+Minor version');
end;
13:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('1字节');
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('X和Y的密度单位');
Listtmp.SubItems.Add('Units for the X and Y densities');
end;
14:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('2字节');
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('X方向像素密度');
Listtmp.SubItems.Add('Xdensity');
end;
16:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('2字节');
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('Y方向像素密度');
Listtmp.SubItems.Add('Ydensity');
end;
18:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('1字节');
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('缩略图水平像素数目');
Listtmp.SubItems.Add('thumbnail horizontal pixels');
end;
19:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('1字节');
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('缩略图垂直像素数目');
Listtmp.SubItems.Add('thumbnail vertical pixels');
end;
20:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('2字节');
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('量化表开始');
Listtmp.SubItems.Add('DQT(Difine Quantization Table)');
end;
22:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('2字节');
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('量化表长度');
Listtmp.SubItems.Add('DQT(Difine Quantization Table)');
end;
24:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('1字节');
LhbJD := GetHiByte(Pbyte(DWORD(@NewPicDataArray))^); //HiByte(StrToInt(s));
LhbID := GetLoByte(Pbyte(DWORD(@NewPicDataArray))^);//loByte(StrToInt(s));
case Integer(LhbJD) of //P/T(高四位:精度,低四位:表ID) mh 1字节 精度, 0 表示 8 bit, 1表示 16 bit;ID取值范围为0~3, 否则错误
0: Listtmp.SubItems.Add('高四位:精度0x'+ IntToHex(LhbJD,2)+'/8 bit'+'低四位:ID0x'+ IntToHex(LhbID,2));
1: Listtmp.SubItems.Add('高四位:精度0x'+ IntToHex(LhbJD,2)+'/16 bit'+'低四位:ID0x'+ IntToHex(LhbID,2));
end;
Listtmp.SubItems.Add('量化表精度/ID');
Listtmp.SubItems.Add('DQT(Difine Quantization Table)');
end;
25:begin
Lhblen :=64* (LhbJD +1);
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add(IntToHex(Lhblen,2)+'字节');
for i:=0 to Lhblen -1 do
begin
LhbStr := LhbStr +IntToHex(Pbyte(DWORD(@NewPicDataArray))^,2);
end;
Listtmp.SubItems.Add('0x'+ LhbStr);
Listtmp.SubItems.Add('量化表表项');
Listtmp.SubItems.Add('DQT(Difine Quantization Table)');
end;
89:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('2字节');
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('量化表开始');
Listtmp.SubItems.Add('DQT(Difine Quantization Table)');
end;
91:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('2字节');
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('量化表长度');
Listtmp.SubItems.Add('DQT(Difine Quantization Table)');
end;
93:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('1字节');
LhbJD := GetHiByte(Pbyte(DWORD(@NewPicDataArray))^); //HiByte(StrToInt(s));
LhbID := GetLoByte(Pbyte(DWORD(@NewPicDataArray))^);//loByte(StrToInt(s));
case Integer(LhbJD) of //P/T(高四位:精度,低四位:表ID) mh 1字节 精度, 0 表示 8 bit, 1表示 16 bit;ID取值范围为0~3, 否则错误
0: Listtmp.SubItems.Add('高四位:精度0x'+ IntToHex(LhbJD,2)+'/8 bit'+'低四位:ID0x'+ IntToHex(LhbID,2));
1: Listtmp.SubItems.Add('高四位:精度0x'+ IntToHex(LhbJD,2)+'/16 bit'+'低四位:ID0x'+ IntToHex(LhbID,2));
end;
Listtmp.SubItems.Add('量化表精度/ID');
Listtmp.SubItems.Add('DQT(Difine Quantization Table)');
end;
94:begin
Lhblen :=64* (LhbJD +1);
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add(IntToHex(Lhblen,2)+'字节');
for i:=0 to Lhblen -1 do
begin
LhbStr := LhbStr +IntToHex(Pbyte(DWORD(@NewPicDataArray))^,2);
end;
Listtmp.SubItems.Add('0x'+ LhbStr);
Listtmp.SubItems.Add('量化表表项');
Listtmp.SubItems.Add('DQT(Difine Quantization Table)');
end;
158:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('2字节');
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('帧图像开始');
Listtmp.SubItems.Add('SOF0(Start of Frame)');
end;
160:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('2字节');
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('帧图像总长度');
Listtmp.SubItems.Add('SOFL(start of frame length)');
end;
162:begin
Listtmp.SubItems.Add(IntToHex(nType-2,2));
Listtmp.SubItems.Add('1字节');
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('精度(precision),每个颜色分量每个像素的位数');
Listtmp.SubItems.Add('bits per pixel per color component');
end;
163:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('2字节');
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('图像高度');
Listtmp.SubItems.Add('image height');
end;
165:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('2字节');
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('图像宽度');
Listtmp.SubItems.Add('image width');
end;
167:begin
Listtmp.SubItems.Add(IntToHex(nType-2,4));
Listtmp.SubItems.Add('1字节');
Listtmp.SubItems.Add('0x'+ s);
Listtmp.SubItems.Add('颜色分量数');
Listtmp.SubItems.Add('number of color components');
Listtmp.SubItems.Add('灰度图是 1, YCbCr/YIQ 彩色图是 3, CMYK 彩色图是 4,我们这里讨论的JFIF使用的是YCbCr,故这里颜色分量数为3');
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
PicDataLen:Integer ;
i,j,k,m,n:Integer ;
//NewPicDataArray:array of Byte ;
sWord:Word ;
QTLLen:Word ;//量化表长度
begin
PicDataLen :=High(PicDataArray);
SetLength(NewPicDataArray,PicDataLen +1);
ifPicDataLen>0then
begin
for i:=0 to PicDataLen-1 do
begin
//ZeroMemory(@NewPicDataArray,PicDataLen );
CopyMemory(@NewPicDataArray,@PicDataArray,1);
end;
end;
ListView1.Clear ;
n:=0;
//m:=0;
for j:=0 to High(NewPicDataArray)-1 do
begin
case j of
0:AddListView(GetPiCData(@NewPicDataArray,2),j);
2:AddListView(GetPiCData(@NewPicDataArray,2),j);
4:AddListView(GetPiCData(@NewPicDataArray,2),j);
6:AddListView(GetPiCData(@NewPicDataArray,1)+
GetPiCData(@NewPicDataArray,2)+GetPiCData(@NewPicDataArray,2),j);
11:AddListView(GetPiCData(@NewPicDataArray,2),j);
13:begin
casePbyte(DWORD(@NewPicDataArray))^ of
0:AddListView('无',j);
1:AddListView('点数/英寸',j);
2:AddListView('点数/厘米',j);
end;
end;
14:AddListView(GetPiCData(@NewPicDataArray,2),j);
16:AddListView(GetPiCData(@NewPicDataArray,2),j);
18:AddListView(GetPiCData(@NewPicDataArray,1),j);
19:AddListView(GetPiCData(@NewPicDataArray,1),j);
20:begin //取量化表个数
//if (Pbyte(DWORD(@NewPicDataArray))^ =0) and(Pbyte(DWORD(@NewPicDataArray))^ =0) then
//ShowMessage('无缩略图RGB位图');//判断有无缩略图RGB位图
AddListView(GetPiCData(@NewPicDataArray,2),j) ;
m:=j;
for k:=m to High(NewPicDataArray)-j-1 do
begin
sWord := Pword(DWORD(@NewPicDataArray))^;
QTLLen :=Pword(DWORD(@NewPicDataArray))^;
WordLoHiExchange(QTLLen);
WordLoHiExchange(sWord);
if sWord= StrToInt('$'+'FFDB') then
begin
n:=n+1;
m:=m+ Integer( QTLLen)+2 ;
end else
Break ;
end;
//ShowMessage('有量化表:'+ IntToStr(n)+'个');
end;
22:AddListView(GetPiCData(@NewPicDataArray,2),j);
24:AddListView(GetPiCData(@NewPicDataArray,2),j);
25:AddListView(GetPiCData(@NewPicDataArray,2),j);
89:AddListView(GetPiCData(@NewPicDataArray,2),j);
91:AddListView(GetPiCData(@NewPicDataArray,2),j);
93:AddListView(GetPiCData(@NewPicDataArray,2),j);
94:AddListView(GetPiCData(@NewPicDataArray,2),j);
158:AddListView(GetPiCData(@NewPicDataArray,2),j); //2字节 0xFFC0
160:AddListView(GetPiCData(@NewPicDataArray,2),j); //2字节 帧图像数据长度
162:AddListView(GetPiCData(@NewPicDataArray,1),j);
163:AddListView(GetPiCData(@NewPicDataArray,2),j);
165:AddListView(GetPiCData(@NewPicDataArray,2),j);
167:AddListView(GetPiCData(@NewPicDataArray,1),j);
end;
end;
end;
页:
[1]