It depends on where the image you want to insert in is bCan
.
Say it is in a directory, you can use the command bCan.LoadFromFile
Take a look at the variations of the command LoadFrom...
of TBitmap
Edit:
Take a look, see if this fits you:
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
type
TForm2 = class(TForm)
Panel1: TPanel;
btnPosicionarImagem: TButton;
btnCarregarImagem: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btnPosicionarImagemClick(Sender: TObject);
procedure btnCarregarImagemClick(Sender: TObject);
private
Image: TBitmap;
Canvas: TControlCanvas;
procedure CarregarImagemBitmap;
procedure PosicionarPainel;
procedure CarregarImagemCanvas;
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormCreate(Sender: TObject);
begin
Image := TBitmap.Create;
Canvas := TControlCanvas.Create;
end;
procedure TForm2.FormDestroy(Sender: TObject);
begin
FreeAndNil(Canvas);
FreeAndNil(Image);
end;
procedure TForm2.CarregarImagemBitmap;
begin
Image.LoadFromFile('C:\executaveis_01_256x256.bmp');
end;
procedure TForm2.PosicionarPainel;
begin
Panel1.Width := Image.Width;
Panel1.Height := Image.Height;
Panel1.Left := Random(100);
Panel1.Top := Random(100);
end;
procedure TForm2.CarregarImagemCanvas;
begin
Canvas.Control := Panel1;
BitBlt(Canvas.Handle, 0, 0, Image.Width, Image.Height, Image.Canvas.Handle, 0, 0, SRCCOPY);
end;
procedure TForm2.btnPosicionarImagemClick(Sender: TObject);
begin
CarregarImagemBitmap;
PosicionarPainel;
end;
procedure TForm2.btnCarregarImagemClick(Sender: TObject);
begin
CarregarImagemCanvas;
end;
end.
Victor, I’m sorry for the delay... In the tests I did the program plays the image loaded by "Loadfromfile" into Tbitmap, leaving only the image. It does not allow me to position the image within the canvas area in the position I need... Thanks for the help.
– Rodrigo Tognin
@Rodrigotognin, take a look at the example I just posted
– Victor Tadashi