为什么bmp文件的分辨率去不出来(200分)

  • 主题发起人 主题发起人 lcflweb
  • 开始时间 开始时间
L

lcflweb

Unregistered / Unconfirmed
GUEST, unregistred user!
根据网上的资料,读取bmp文件的分辨率,却一直为0,请高手指教!
代码如下:
var
FormImage: TBitmap;
Info: PBitmapInfo;
InfoSize: DWORD;
Image: Pointer;
ImageSize: DWORD;
Bits: HBITMAP;
DIBWidth, DIBHeight: Longint;
px,py:integer;
Size: TPoint;
begin
FormImage := Tbitmap.Create;
formimage.loadfromfile('xxxxxxxx');
try
Bits := FormImage.Handle;
GetDIBSizes(Bits, InfoSize, ImageSize);
Info := AllocMem(InfoSize);
Image := AllocMem(ImageSize);
GetDIB(Bits, 0, Info^, Image^);

with Info^.bmiHeader do
begin
DIBWidth := biWidth;
DIBHeight := biHeight;
px:=biXPelsPerMeter; //每米的象素
py:=biXPelsPerMeter; //每米的象素
end;
finally;
formImage.free;
end;
end;
 
我试了,可以啊

var
FormImage: TBitmap;
Info: PBitmapInfo;
InfoSize: DWORD;
Image: Pointer;
ImageSize: DWORD;
Bits: HBITMAP;
DIBWidth, DIBHeight: Longint;
px,py:integer;
Size: TPoint;
begin
FormImage := Tbitmap.Create;
formimage.loadfromfile('d:/2.bmp');
try
Bits := FormImage.Handle;
GetDIBSizes(Bits, InfoSize, ImageSize);
Info := AllocMem(InfoSize);
Image := AllocMem(ImageSize);
GetDIB(Bits, 0, Info^, Image^);

with Info^.bmiHeader do
begin
DIBWidth := biWidth;
DIBHeight := biHeight;
px:=biXPelsPerMeter; //每米的象素
py:=biXPelsPerMeter; //每米的象素
edit1.text:=inttostr(px);
edit2.text:=inttostr(py);
end;
finally;
formImage.free;
end;
end;
 
后退
顶部