将TPanel上显示的图片复制到TImage中

时间:2016-06-09 08:04:42

标签: delphi delphi-xe6 mplayer

我已成功将MPlayer视频结果嵌入TPanel,但无法将TPanel结果复制到TImage

仅将TPanel的正常图片复制到TImage

enter image description here

使用管道和MPlayer wid命令行参数执行嵌入。 MPlayer使用TPanel句柄来显示结果。

测试了以下代码段,但只是将TPanel图片复制到了TImage

  Image1.Picture.Bitmap.Canvas.CopyRect(
    Rect(0, 0, Image1.Width-1, Image1.Height-1),
    TMyPanel(Panel1).Canvas,     //TMyPanel is an empty class to access canvas property 
    Rect(0, 0, Panel1.Width-1, Panel1.Height-1)
  );

和此:

Function PanelToBmp ( Panel:TPanel):TBitmap;
VAR
  bmp : tBitmap;
  DC  : HDC;
Begin
  bmp := tBitmap.Create;
  bmp.width := Panel.Width;
  bmp.Height := Panel.Height;
  DC := GetDc ( Panel.Handle );
  Bitblt(bmp.canvas.handle, 0, 0, Panel.Width, Panel.Height, Dc, 0, 0, NOTSRCCOPY);
  Releasedc (Panel.handle,dc);
  result := bmp;
End;

1 个答案:

答案 0 :(得分:1)

你也可以通过剪贴板复制,试试这个:

uses ClipBrd;

procedure TForm1.Button1Click(Sender: TObject);
var
  lBmp: TBitmap;
begin
  lBmp := TBitmap.Create;
  try
    lBmp.SetSize(Panel1.ClientWidth, Panel1.ClientHeight);
    BitBlt(lBmp.Canvas.Handle, 0, 0, Panel1.ClientWidth, Panel1.ClientHeight, TMyPanel(Panel1).Canvas.Handle, 0, 0, SRCCOPY);
    Clipboard.Assign(lBmp);

   Image1.Picture.Bitmap.Assign( lBmp );
  finally
    lBmp.Free;
  end;
end;

我希望这对你有所帮助。