[SOLVED]Bitmap as a parameter lazarus / 39-Graphics ---------------------------------------------------------------------- Cliff48 · 2015-06-14 00:24 I have a function that takes an image and makes a Thumbnail image; So I want to call: CreateThumbnail(fname,  mybmp, thumbwidth, thumbheight); but I cannot work out how my CreateThumbnail parameters should be defined: Function CreateThumbnail(fname: String; var bmp: Tbitmap; tw, th: LongInt): Boolean; I try using type of Tbitmap, BITMAP but get  compile errors.  I cant find an acceptable combination that FPC will accept.  I want this as reusable code, so I dont want to code the bitmap name as a global variable.  ( I already have that working, but its hardly reusable in that form. Appreciate any help. ---------------------------------------------------------------------- typo · 2015-06-14 01:18 Code: [Select]function CreateThumbnail(AName: string; var ABitmap: TBitmap; TW, TH: LongInt): Boolean; var   ThumbNail: TBitmap;   R: TRect; begin   Result := False;   ThumbNail := TBitmap.Create;   try     ThumbNail.Width := TW;     ThumbNail.Height := TH;     ThumbNail.Canvas.StretchDraw(Rect(0,0,tw, th), ABitmap);     ABitmap.Assign(ThumbNail);     Result := True;   finally     ThumbNail.Free;   end; end;  usage: Code: [Select]procedure TForm1.Button1Click(Sender :TObject); var   bmp: TBitmap; begin   bmp := Image1.Picture.Bitmap;   CreateThumbnail('name', bmp, 100, 100);   Image1.Picture.Bitmap := bmp; end; In your uses clause, put Windows before Classes unit. ---------------------------------------------------------------------- Basile B. · 2015-06-14 01:36 var is even not necessary since TBitmap is a reference type (it's already a pointer). It's even better to remove it because with var the type of the parameter must be formally the same as the parameter type: sub class not allowed. Without var you can pass some TBitmap descendant. ---------------------------------------------------------------------- typo · 2015-06-14 01:50 You could use Ratio: double instead of TW and TH. ---------------------------------------------------------------------- Cliff48 · 2015-06-14 02:03 Thank you both for your very helpful answers, especially as to why I am having the problems. @typo.  I am using dw, dh as I am scaling to keep the same aspect ratio and will be used as icons on stringgrid.  Like most people I seemed to have collected icons, glyphs, images, etc from all over the net, and just stored them where I was going to be using them at the time.  I figured now was a good time to try to organise stuff as I am making a a more serious attempt to learn and use FPC/Lazarus capabilities in a more organised way.  So look forward to  more questions on basic stuff like this while I learn:) Thanks again