打印本文 打印本文 关闭窗口 关闭窗口
怎样读出不同格式图形的高和宽
作者:武汉SEO闵涛  文章来源:敏韬网  点击数611  更新时间:2009/4/23 18:26:01  文章录入:mintao  责任编辑:mintao

 

最近开发的一个系统,需根据用户提交的图片(图片文件以字符流的形式从客户机传到服务器)读出该图片的高和宽,通过下列代码实现了该功能,现在拿出来给大家参考。
……
type
  TGIFHeader = packed record
    Signature: array[0..2] of Char;
    Version: array[0..2] of Char;
    ScreenWidth: Word;
    ScreenHeight: Word;
    PackedFields,
    BackgroundColorIndex,
    AspectRatio: Byte;
  end;
    TGIFInfoHeader = TGIFHeader;
……   
procedure Ttempphoto.AddMediaRec(out content_no, succed, errno,
  errmsg: OleVariant; const PicName, Title, Author, Theme, PublishDate,
  KeyWord: WideString; Length: SYSUINT; const Memo: WideString; PicHight,
  PicWidth, Color_Pan: SYSUINT; content: OleVariant; PayNo: SYSINT;
  const GroupNo: WideString);
file://过程中部分相关的代码
var
    p : pwidechar;
    bb : string;
    tempchar : integer;
    mm : SYSUINT;
    jpeg: TJPEGImage;
    Gif:TGIFInfoHeader;
    bmp:TBitmapInfoHeader;
    phowidth: integer;
    Phoheight: integer;
    ss:TStringStream;
    fileheader:TBitmapfileheader;
begin
……
      
       p := Tvardata(content).volestr;
       setlength(bb,Length);
       mm := 1;
       while mm<=Length do
         begin
           tempchar := integer(p[(mm-1) div 2]);
           bb[mm]:= chr(tempchar mod 256);
           if mm           mm := mm+2;
         end;
       file://读取图片的高和宽
       ss:=tstringstream.Create(bb);
       if ((PicName=''''jpg'''')or(PicName=''''jpeg'''')) then begin
           jpeg:= TJPEGImage.Create;//需uses jpeg
           jpeg.LoadFromStream(ss);
           phowidth:=jpeg.width;
           phoheight:=jpeg.height;
           jpeg.free;
        end
        file://根据自己定义的gif格式图片文件头信息读取图片的高和宽
        else if (PicName=''''gif'''') then begin
             ss.Read(gif,sizeof(gif));
             phowidth:=gif.ScreenWidth;
             phoheight:=gif.ScreenHeight;
        end
        file://根据windows单元定义的bmp格式图片文件头信息读取图片的高和宽
        else if (PicName=''''bmp'''') then begin
             ss.Read(fileheader,sizeof(fileheader));       
             ss.Read(bmp,sizeof(bmp));
             phowidth:=bmp.biWidth;
             phoheight:=bmp.biHeight;
        end
        else begin
        end;
            ss.Free;
……           
end;

更详细资料请访问我的个人主页http://aton.126.com

打印本文 打印本文 关闭窗口 关闭窗口