Link to home
Start Free TrialLog in
Avatar of kzdown
kzdown

asked on

Thumbnails?


My program works with own custom documents and sometimes user creates templates from them.
also there is a background picture into documents. I want to make 'new from template' dialog form that shows thumbnails of my document;s background. SO my question is :
-how to create thumbnail from my background pictures (jpegs)?

thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of Cesario Lababidi
Cesario Lababidi
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mohammed Nasman
Hello

  Here's procedure called MakeThumb, just pass the two images as source and target and the thumbnail size

//=====
procedure MakeThumb(src,dst:TImage; size:integer);
var tr:TRect;
newwidth,newheight,orgwidth,orgheight:integer;
begin
 orgwidth:=src.width;
 orgheight:=src.height;
 if (orgheight/orgwidth > 1) then begin
   newheight:=size;
   newwidth:=round(orgwidth*(newheight/orgheight));
  end
 else begin
   newwidth:=size;
   newheight:=round(orgheight*(newwidth/orgwidth));
  end;
 dst.autosize:=false;
 dst.stretch:=false;
 dst.width:=size;
 dst.height:=size;
 dst.canvas.pen.color:=clwhite;
 dst.canvas.brush.color:=clwhite;
 if (newwidth < size)then begin
   tr.left:=(size-newwidth)div 2;
   tr.right:=tr.left+newwidth;
   tr.top:=0;tr.bottom:=size;
   dst.canvas.rectangle(0,0,tr.left,size);    // fill white
   dst.canvas.rectangle(tr.right,0,size,size);// fill white
  end;
 if newheight > size then begin
   tr.left:=0;tr.right:=size;
   tr.top:=(size-newheight)div 2;
   tr.bottom:=tr.top+newheight;
   dst.canvas.rectangle(0,0,size,tr.top);      // fill white
   dst.canvas.rectangle(0,tr.bottom,size,size);// fill white
  end;
 dst.canvas.stretchdraw(tr,src.picture.graphic);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  makethumb(image1,Image2,100);
end;

Best regards
Mohammed nasman