procedure TWilFile.StretchBlt(Index: Integer; DC: HDC; X, Y, Width, Height: Integer;
ROP: Cardinal);
var
ImageInfo: PImageInfo;
PBits: Pointer;
a : TFastDIB;
Bitmap: HBitmap;
begin
// 检查 Index 是否合法
if (Index < 0) or (Index >= FImageCount) then
raise Exception.Create('TWilFile.StretchBlt 数组超界!');
// 定位到图片位置
ImageInfo := IncPointer(FFilePointer, FIndexArr[Index]);
// 设置位图大小
with FBitmapInfo.bmiHeader do
begin
biWidth := ImageInfo^.Width;
biHeight := ImageInfo^.Height;
end;
// 填充调色板
Move(MainColorTable^, FBitmapInfo.bmiColors, SizeOf(FBitMapInfo.bmiColors));
// PBits 指向位图的 Bits
PBits := IncPointer(ImageInfo, SizeOf(TImageInfo) - 4);
// 缩放方式将 DIB Bits 写到设备环境
StretchDIBits(DC, X, Y, Width, Height, 0, 0, ImageInfo^.Width, ImageInfo^.Height,
PBits, PBitmapInfo(PBitmapInfo256(@FBitmapInfo))^, DIB_RGB_COLORS, ROP);
end;
这段代码可以正常显示出内存图片
下面这段为什么不行?
procedure TWilFile.StretchBlt(Index: Integer; DC: HDC; X, Y, Width, Height: Integer;
ROP: Cardinal);
var
ImageInfo: PImageInfo;
PBits: Pointer;
a : TFastDIB;
Bitmap: HBitmap;
begin
// 检查 Index 是否合法
if (Index < 0) or (Index >= FImageCount) then
raise Exception.Create('TWilFile.StretchBlt 数组超界!');
// 定位到图片位置
ImageInfo := IncPointer(FFilePointer, FIndexArr[Index]);
// 设置位图大小
with FBitmapInfo.bmiHeader do
begin
biWidth := ImageInfo^.Width;
biHeight := ImageInfo^.Height;
end;
Move(MainColorTable^, FBitmapInfo.bmiColors, SizeOf(FBitMapInfo.bmiColors));
PBits := IncPointer(ImageInfo, SizeOf(TImageInfo) - 4);
Bitmap:=CreateDIBSection(DC,PBitmapInfo(PBitmapInfo256(@FBitmapInfo))^, DIB_RGB_COLORS, PBits, 0, 0);
a := TFastDIB.Create ;
a.LoadFromHandle(bitmap);
a.Draw(DC,X,Y);
end;