Link to home
Start Free TrialLog in
Avatar of ItsMe
ItsMe

asked on

Resize TImage

Hi,
how do I convert an resized Image to an Image, which normal size is the resized size ?
e.g. my image is 32x32 I resize it to 32x64 (by stretching it) . Now I need to convert the
image so that 32x64 is the normal size (When I load the image with autosize=true and
stretched=false the image must has the size 32x64. I must do that without using the hdd.
Avatar of Madshi
Madshi

I have not test it, but try this:

procedure StretchImage(oldImg,newImg: TImage);
begin
  newImg.width:=32; newImg.height:=64;
  newImg.picture.bitmap.width:=32; newImg.picture.bitmap.height:=64;
  newImg.picture.bitmap.canvas.StretchDraw(Rect(0,0,32,64),oldImg);
end;

Regards... Madshi.
Avatar of ItsMe

ASKER

Ok, I think that'll work. I'm asking the user for the new bitmap height and width. Now the original
bitmap should be changed to the new size. I'm only using 1 Image component. And I can't use
stretch because it doesn't work with my program (I'm using OnMouseMove, CanvasMoveTo etc.)
and when I stretch it "normal" my rectangle end position doesn't match with mouse position. Perhaps
you could send me a source code ? (StretchDraw wants a TGraphic not an image ???). You can
compare my program with Borland's "Graphex" example program but my program must be able to change
the image size.

Regards
ItsMe
Ok, another try:

procedure StretchImage(var img: TImage; newWidth,newHeight: integer);
var bmp : TBitmap;
begin
  bmp:=TBitmap.Create;
  try
    bmp.width:=newWidth; bmp.height:=newHeight;
    bmp.canvas.StretchDraw(Rect(0,0,32,64),img.picture.graphic);
    img.picture.SetBounds(img.left,img.top,newWidth,newHeight);
    img.picture.bitmap.Assign(bmp);
  finally bmp.free end;
end;

Regards... Madshi.
Avatar of ItsMe

ASKER

Dear Madshi, now my program works. Thank you. Please send a comment as answer, so that I can
accept it.
ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

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