Just use something black larger than picture and put it behind the picture, maybe a TShape.
Below is an example using a TShape, all components are created runtime. Drop a button an a form and make sure you put
StdCtrls,
ExtDlgs,
ExtCtrls in the uses clause.
procedure TForm1.Button1Click(Sender: TObject);
const
ImageBorder = 5;
const
Image: TImage = nil;
Background: TShape = nil;
begin
with TOpenPictureDialog.Create(Form1) do
begin
if Execute then
begin
if not(Assigned(Image)) then
begin
Image := TImage.Create(Form1);
Image.Parent := Form1;
Image.Left := 50;
Image.Top := 50;
Background := TShape.Create(Form1);
Background.Parent := Form1;
Background.Brush.Color := clBlack;
Background.Pen.Style := psClear;
Background.Left := Image.Left - ImageBorder;
Background.Top := Image.Top - ImageBorder;
Background.SendToBack;
end;
Image.Picture.LoadFromFile(FileName);
Image.Height := Image.Picture.Height;
Image.Width := Image.Picture.Width;
Background.Height := Image.Picture.Height + 2*ImageBorder;
Background.Width := Image.Picture.Width + 2*ImageBorder;
end;
Free;
end;
end;
- Line #3 is for the thickness of the border.
- Line #24 is to make sure the background behind the image.