Tencent QQ皮肤图像文件格式Gft转png或bmp源代码

Tencent QQ皮肤图像文件格式Gft转png或bmp源代码 

转载自CSDN,另附Delphi版代码:

http://topic.csdn.net/u/20111121/14/E545FC21-41CF-4341-BCA6-770AE91F9211.html

工具是为制作QQ皮肤的人准备的,源代码是为vc程序员准备的。本压缩包即提供编译好的可执行程序,又提供了程序的源代码。

工具的作用是把Tencent公司QQ皮肤使用的Gft图像格式,转成Png或Bmp格式,当选择包含Gft文件的文件夹时,支持批量转换文件夹下及子文件夹下所有Gft文件。

此工具是喜欢制作QQ皮肤的美工朋友或喜欢仿QQ界面的开发人员必备工具。

此工具界面图片,除Logo外,也都是直接使用的QQ皮肤中的图片,版权归腾讯公司所有。

程序截图: 

 

 

下载地址:

 

========================================================================

以下为Delphi代码:

 

  1 {*******************************************************************************
  2 
  3   Tencent QQ  gft图像格式转换单元 转换为BMP或PNG
  4 
  5   原作者 :  psbeond
  6   网  址 :  http://topic.csdn.net/u/20111121/14/E545FC21-41CF-4341-BCA6-770AE91F9211.html
  7  原始代码:http://download.csdn.net/download/psbeond/3821134
  8 
  9   本人只是对C++代码翻译翻译为Delphi代码 不做其他处理
 10   如需解包RDB文件,请自行百度 “RDB打包解包工具”
 11 
 12 *******************************************************************************}
 13 
 14 unit uGFT2Image;
 15 
 16 interface
 17 
 18 uses
 19   SysUtils, Classes;
 20 
 21 const
 22   E_GFT_FILE_OPEN           = -1;
 23   E_NOT_GFT_FILE           = -2;
 24   E_NO_IMAGE_DATA           = -3;
 25   E_NOT_SUPPORT_IMAGE     = -4;
 26 
 27 type
 28   TImageType = (IT_UNKNOWN,IT_BITMAP,IT_PNG);
 29 
 30 function ConvertGft2Image(strGftFile:string;Image:TStream;var ImageType:TImageType):Integer;
 31 
 32 implementation
 33 
 34 
 35 function ConvertGft2Image(strGftFile: string;
 36 Image:TStream;var ImageType:TImageType):Integer;
 37 const
 38   // Png and bmp file header
 39   btPngHeader : array [0..7of Byte = ($89, $50, $4E, $47, $0D, $0A, $1A, $0A);
 40   wBmpHeader  = $4D42;
 41 var
 42   fpGft : TFileStream;
 43   nGftFileLength : Int64;
 44   btImageOffset  : Byte;
 45   wHeader        : WORD;
 46   btHeader       : array [0..7of Byte;
 47   nImageLength   : Integer;
 48 begin
 49   // Open gft file
 50   if not FileExists(strGftFile) then
 51     begin
 52       Result := E_GFT_FILE_OPEN;
 53       Exit;
 54     end;  
 55   fpGft := TFileStream.Create(strGftFile,fmOpenRead);
 56 
 57   // Get Gft file length.
 58   nGftFileLength := fpGft.Size;
 59 
 60   // The byte of address 0x00000010 of gft file is specify the offset of image.
 61   if nGftFileLength < 17 then
 62     begin
 63       Result := E_NOT_GFT_FILE;
 64       Exit;
 65     end;
 66 
 67   // Get image offset
 68   // Seek to byte that specify the offset of image.
 69   fpGft.Seek($00000010,soFromBeginning);
 70   fpGft.Read(btImageOffset,SizeOf(Byte));
 71   if btImageOffset + 2 >= nGftFileLength then
 72     begin
 73       Result := E_NO_IMAGE_DATA;
 74       Exit;
 75     end;  
 76 
 77   // Check the image type.
 78   ImageType := IT_UNKNOWN;
 79   fpGft.Seek(btImageOffset,soFromBeginning);
 80   fpGft.Read(wHeader,SizeOf(WORD));
 81   if wHeader = wBmpHeader then
 82     ImageType := IT_BITMAP
 83   else
 84     begin
 85       if btImageOffset + 8 >= nGftFileLength then
 86         begin
 87           Result := E_NO_IMAGE_DATA;
 88           Exit;
 89         end;
 90 
 91       fpGft.Seek(btImageOffset,soFromBeginning);
 92       fpGft.Read(btHeader,SizeOf(Byte)*8);
 93       
 94       if CompareMem(@btHeader,@btPngHeader,8then
 95         begin
 96           ImageType := IT_PNG;
 97         end;
 98     end;
 99 
100   if ImageType = IT_UNKNOWN then
101     begin
102       Result := E_NOT_SUPPORT_IMAGE;
103       Exit;
104     end;
105 
106   // Convert gft to image
107   nImageLength := nGftFileLength - btImageOffset;
108   if nImageLength <= 0 then
109     begin
110       Result := E_NO_IMAGE_DATA;
111       Exit;
112     end;
113   fpGft.Seek(btImageOffset,soFromBeginning);
114   Image.Position := 0;
115   Image.CopyFrom(fpGft,nImageLength);
116   Image.Position := 0;
117   fpGft.Destroy;
118   Result := 0;
119 end;
120 end

另附Demo:

Gft2Image_Demo.rar 

posted @ 2011-11-24 15:05  LAHCS  阅读(1718)  评论(1编辑  收藏  举报