用这个两个API(DrawDibbegin ,DrawDibDraw)在Panel上画的图片怎么可以保存下来。比如:BMP.(50分)

  • 主题发起人 主题发起人 ansili
  • 开始时间 开始时间
A

ansili

Unregistered / Unconfirmed
GUEST, unregistred user!
用这个两个API(DrawDibBegin,DrawDibDraw)在Panel上画的图片怎么可以保存下来。比如:BMP文件,TBitmap.

代码如下:
procedure TPlayML20.DrawDiB;
var
hdib : HDRAWDIB;
m_hdc: HDC;
BitDecompressed : PBITMAPINFOHEADER;
BitBuffer : PBITMAPINFOHEADER;
begin
hdib := DrawDibOpen;
m_hdc := GetDC(FPlayHandle);
//New(BitDecompressed);
BitDecompressed := (FDecoder.BitDecompressed);

if(hdib <> 0) then
begin
DrawDibBegin(
hdib,
m_hdc,
-1,
-1,
BitDecompressed,
BitDecompressed^.biWidth,
BitDecompressed^.biHeight,
0
);
end;

DrawDibDraw(
hdib,
m_hdc,
0,
0,
-1,
-1,
BitDecompressed,
FDecoder.pout,// Pointer to the buffer that contains the bitmap bits
0,
0,
BitDecompressed^.biWidth,
BitDecompressed^.biHeight,
DDF_SAME_DRAW
);
DrawDibEnd(hdib);
DrawDibClose(hdib);
ReleaseDC(FPlayHandle,m_hdc);
end;
 
type
TPanelCrack = class(TPanel);

//以下方法会将Panel上所有东东都画出来
procedure TForm1.Button1Click(Sender: TObject);
begin
with TBitmap.Create do
try
Width := Panel1.Width;
Height := Panel1.Height;
PixelFormat := pf24bit;
BitBlt(Canvas.Handle, 0, 0, Width, Height, TPanelCrack(Panel1).Canvas.Handle, 0, 0, SRCCOPY);
SaveToFile('D:/Temp/test.bmp');
finally
Free;
end;
end;

//以下方法只画Panel本身及其上从TGraphicControl继承而来的组件
with TBitmap.Create do
try
Width := Panel1.Width;
Height := Panel1.Height;
PixelFormat := pf24bit;
Panel1.PaintTo(Canvas.Handle, 0, 0);
SaveToFile('D:/Temp/test.bmp');
finally
Free;
end;
 
To : dreamisx

帮我看看这个帖子: 如何用DrawDibDraw加载BMP文件的图片文件?
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3421417
 
to dreamisx:
你提供的代码我还是无法保存panel上的内容啊
怎么回事???
提示错误说设备未准备好
 
我搞定了,谢谢dreamisx~~
 
接受答案了.
 
后退
顶部