FastBlt这个函数是在哪个包中或? ( 积分: 100 )

  • 主题发起人 主题发起人 happy_boy
  • 开始时间 开始时间
H

happy_boy

Unregistered / Unconfirmed
GUEST, unregistred user!
delphiX中有BltFast与FastBlt不太一样。参数个数不一样。
 
delphiX中有BltFast与FastBlt不太一样。参数个数不一样。
 
不太清楚,帮你提前一下。
 
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;
 
PBitmapInfo256 = ^TBitmapInfo256;
TBitmapInfo256 = record
bmiHeader : TBitmapInfoHeader;
bmiColors : array[0..255]of Longint;
end;
这是TBitmapInfo256的结构
 
你这么一说说混了 BltFast和FastBlt其中有一个是Windows API 一个是DelphiX 的函数
我忘了是哪个了 好像是FastBlt是WindowsAPI。。
 
FastBlt这个函数我是没查到
bltFast是DX函数,
 
It seems my code for MirClient.exe. Hehe. The FastBlt is here, in AdvDraw.pas:

procedure FastBlt(DstSurf: IDirectDrawSurface7; X, Y, DstWidth, DstHeight: Integer;
SrcSurf: IDirectDrawSurface7; SrcWidth, SrcHeight: Integer; Transparent: Boolean);
const
BltFastFlags: array[Boolean] of Integer =
(DDBLTFAST_WAIT or DDBLTFAST_NOCOLORKEY,
DDBLTFAST_WAIT or DDBLTFAST_SRCCOLORKEY);
var
SrcR: TRect;
Result: HRESULT;
begin
if DstSurf = nil then raise Exception.Create('DstSurf = nil!');
if SrcSurf = nil then raise Exception.Create('SrcSurf = nil!');

if X >= 0 then
begin
if X > DstWidth then Exit;
SrcR.Left := 0;
end
else begin
if -X >= SrcWidth then Exit;
SrcR.Left := -X;
end;

if Y >= 0 then
begin
if Y > DstHeight then Exit;
SrcR.Top := 0;
end
else begin
if -Y >= SrcHeight then Exit;
SrcR.Top := -Y;
end;

SrcR.Right := SrcWidth;
if X + SrcWidth > DstWidth then
Dec(SrcR.Right, (X + SrcWidth - DstWidth));

SrcR.Bottom := SrcHeight;
if Y + SrcHeight > DstHeight then
Dec(SrcR.Bottom, (Y + SrcHeight - DstHeight));

if (SrcR.Right = SrcR.Left) or (SrcR.Top = SrcR.Bottom) then Exit;

if X < 0 then X := 0;
if Y < 0 then Y := 0;

Result := DstSurf.BltFast(X, Y, SrcSurf, @SrcR, BltFastFlags[Transparent]);
if Result <> DD_OK then
begin
DebugOut('_debugout.txt', format('%d, %d, %d, %d', [srcr.Left, SrcR.top,
srcr.Right, srcr.Bottom]));
raise exception.CreateFmt('FastBlt failed in AdvDraw! [%x]', [Result]);
end;
end;
 
to savetime:
可是这个Draw与DrawEx要如何来用呢?请给段代码
谢谢
如果有时间请您帮我看一下我第二个问题
如果不用这个DX东东,怎么才能画出图片
哪个速度更好呢?
谢谢你...
 
(安装好输入法了 :)
Draw 和 DrawEx 在代码里到处都有例子,不必再给了吧。

不用DX,直接用下面这二个就可以了:
procedure TWilFile.BitBlt 或
procedure TWilFile.StretchBlt.

DX和GDI,哪个速度快,试试就知道了。
 
我还是没用DX,最后也是根据你的代码改了一下
我是这样做的把图片生成为TBitmap然后在显示出来速度还
可能
procedure TWilFile.MakeBMP(Bitmap:TBitmap;Index: Integer);
var
FileHeader: BITMAPFILEHEADER;
InfoHeader: BITMAPINFOHEADER;
ColorTableSize: Integer;
InfoPtr: PImageInfo;
PBits: PByte;
BitmapStream : TMemoryStream;
// Zoom : Integer;
begin
// 检查 AIndex 是否合法
if (Index < 0) or (Index >= FImageCount) then
raise Exception.Create('TWilFile.SaveToFile 数组超界!');

// 图片信息指针
InfoPtr := ImageInfo[Index];

// 色彩表内存大小
ColorTableSize := SizeOf(TRGBQuad) * 256;

// 位图文件头
FileHeader.bfType := MakeWord(Ord('B'), Ord('M'));
FileHeader.bfSize := SizeOf(FileHeader) + SizeOf(InfoHeader) + ColorTableSize +
InfoPtr^.Width * InfoPtr^.Height;
FileHeader.bfReserved1 := 0;
FileHeader.bfReserved2 := 0;
FileHeader.bfOffBits := SizeOf(FileHeader) + SizeOf(InfoHeader) + ColorTableSize;

// 位图信息头
InfoHeader.biSize := SizeOf(InfoHeader);
InfoHeader.biWidth := InfoPtr^.Width;
InfoHeader.biHeight := InfoPtr^.Height;
InfoHeader.biPlanes := 1;
InfoHeader.biBitCount := 8;
InfoHeader.biCompression := 0;
InfoHeader.biSizeImage := 0;
InfoHeader.biXPelsPerMeter := 0;
InfoHeader.biYPelsPerMeter := 0;
InfoHeader.biClrUsed := 0;
InfoHeader.biClrImportant := 0;

BitmapStream := TMemoryStream.Create ;
BitmapStream.Write(FileHeader, SizeOf(FileHeader));
BitmapStream.Write(InfoHeader, SizeOf(InfoHeader));
if ColorTableSize > 0 then
BitmapStream.Write(FMainColorTable^, ColorTableSize);
PBits := IncPointer(InfoPtr, SizeOf(TImageInfo) - 4);
try
BitmapStream.Write(PBits^, InfoPtr^.Width * InfoPtr^.Height);
except
raise Exception.Create('TWilFile.MakeBMP! '+IntToStr(Index));
end;
BitmapStream.Position := 0;
Bitmap.LoadFromStream(BitmapStream);
Bitmap.TransparentColor := clBlack;
Bitmap.Transparent := True;
BitmapStream.Free ;
end;
我现在还有点问题想请教一下.
你这个类只实现了读wil文件,
如果想对wil文件进行写操作应该如何办呢?
是用内存映像文件的方式(你的方式,速度快)还是文件
I/O方式(我感觉操作方便)?哪种更好呢?
 
接受答案了.
 
后退
顶部