{Demo for the Forum to show the problem with the yellow margin arround the
picture}
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, math;
const FileSpec = 'demo.png'; {picture file to show}
Margin = 10; {Margin for background-color in 'clYellow'}
type
{ TForm1 }
TForm1 = class(TForm)
Image1: TImage;
Picture1: TPicture;
ScrollBox1: TScrollBox;
procedure showPicture(fspec: string);
procedure FormActivate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.showPicture(fspec: string);
{shows the picture in file 'fspec' with a certain scaling factor 'f'}
const MaxFormWidth = 1000; {wanted max. Form.Width}
MaxFormHeight = 800; {wanted max. Form.Height}
var f: double;
pax,pay, w,h: integer;
begin
Picture1:=TPicture.Create;
try
Picture1.LoadFromFile(fspec);
except
on E:Exception do
begin
ShowMessage('Error on loading file!');
Picture1.Free;
exit;
end;
end; {try}
pax:=Picture1.Width; pay:=Picture1.Height; {store original picture size}
writeln('Original = ', pax, ' x ', pay);
Image1.Picture.Bitmap.SetSize(pax,pay); {set Image size}
f:=1.0; {select or compute the scaling factor: }
// f:=0.78; {for values <= 0.78 no scrollbars are neccessary}
w:=round(pax*f); {new picture width}
h:=round(pay*f); {new picture height}
Image1.Stretch:=true;
Image1.Left:=Margin;
Image1.Top:=Margin;
Image1.Width:=w;
Image1.Height:=h;
Image1.Picture.Bitmap.Canvas.Draw(0,0, Picture1.Bitmap); {show picture}
writeln('Image1 = ', Image1.Width, ' x ', Image1.Height);
inc(w,2*Margin); {set Form size: }
inc(h,2*Margin);
self.SetBounds(0,0,min(MaxFormWidth,w),min(MaxFormHeight,h));
Picture1.Free;
end; {showPicture}
procedure TForm1.FormActivate(Sender: TObject);
const first: boolean = true;
begin
if not first then exit;
first:=false;
ScrollBox1.Align:=alClient;
ScrollBox1.BorderStyle:=bsNone;
ScrollBox1.HorzScrollBar.Tracking:=true; {scroll in Realtime: }
ScrollBox1.VertScrollBar.Tracking:=true;
ScrollBox1.Color:=clYellow;
(* // enables a correct yellow Margin, but disables the ScrollBars:
Image1.Align:=alClient;
Image1.BorderSpacing.Left:=Margin;
Image1.BorderSpacing.Top:=Margin;
Image1.BorderSpacing.Right:=Margin;
Image1.BorderSpacing.Bottom:=Margin;
*)
showPicture(FileSpec); {shows the picture in file 'FileSpec'}
end;
end.