Delphi如何将一张图片画在窗体上?

假如有了图片的句柄HBitmap,如何将它画在窗体上?
2025-05-13 22:33:35
推荐回答(3个)
回答1:

你的句柄是怎么来的?

procedure TForm1.FormPaint(Sender: TObject);
const
  ImgPath = 'c:\temp\test.bmp';
var
  img: TGPImage;
  bit: TBitmap;
  g: TGPGraphics;
begin
  bit := TBitmap.Create;
  bit.LoadFromFile(ImgPath);
  img := TGPBitmap.Create(bit.Handle, bit.Palette);
  g := TGPGraphics.Create(Canvas.Handle);
  g.DrawImage(img, 0, 0);
  g.Free;
  bit.Free;
  img.Free;
end;

回答2:

Form1.Canvas.Handle:= HBitmap;

回答3:

放TImage上行不?