怎样读出不同格式图形的高和宽 (转)

怎样读出不同格式图形的高和宽 (转)[@more@]

 

最近开发的一个系统,需根据用户提交的图片(图片文件以字符流的形式从客户机传到服务器)读出该图片的高和宽,通过下列代码实现了该功能,现在拿出来给大家参考。
……
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


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-995903/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10752043/viewspace-995903/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值