Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to resize a bitmap in firemonkey


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Jul 16, 2014 11:13 AM Last Post By: Dominique Willems
Philippe Watel

Posts: 13
Registered: 10/20/06
How to resize a bitmap in firemonkey  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 16, 2014 5:16 AM
Hello
that should be easy but it not
myBitmap:TBitmap;

myBitmap := TBitmap.CreateFromFile(FILENAME_1);
// let say the size is 64 X 64
// I increase to 250
myBitmap.SetSize(250,250);
// save to another file
myBitmap.Savetofile(FILENAME_2);
myBitmap.free;

the file is all black
Any thoughts
thank you
PW
Eli M

Posts: 1,346
Registered: 11/9/13
Re: How to resize a bitmap in firemonkey  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 16, 2014 6:16 AM   in response to: Philippe Watel in response to: Philippe Watel
SetSize sets the height and width of the bitmap but does not resize it's contents.

function ResizeBitmap(B: TBitmap;Width,Height: Integer): TBitmap;
begin
Result := TBitmap.Create(Width,Height);
Result.Clear(0);
if Result.Canvas.BeginScene then
try
Result.Canvas.DrawBitmap(B,RectF(0,0,B.Width,B.Height),RectF(0,0,Width,Height),1);
finally
Result.Canvas.EndScene;
end;
end;

procedure TForm2.Image1Click(Sender: TObject);
var
B: TBitmap;
begin
B := ResizeBitmap(Image1.Bitmap,250,250);
Image1.Bitmap.SetSize(250,250);
Image1.Bitmap.CopyFromBitmap(B);
B.Free;
end;

Philippe Watel

Posts: 13
Registered: 10/20/06
Re: How to resize a bitmap in firemonkey  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 16, 2014 8:26 AM   in response to: Eli M in response to: Eli M
thank you VERY MUCH That does it
Firemonkey is one non obvious thing after another

I took the liberty to modify it a bit so it is not a function

//==============================================================================
procedure ResizeBitmap(fB: TBitmap; const fWidth, fHeight: integer);
//==============================================================================
var
pTemp: TBitmap;
begin
pTemp := nil;
try
pTemp := TBitmap.Create(fWidth, fHeight);
pTemp.Clear(0);
if pTemp.Canvas.BeginScene then
try
pTemp.Canvas.DrawBitmap(fB, RectF(0, 0, fB.Width, fB.Height),
RectF(0, 0, fWidth, fHeight), 1);
fB.SetSize(fWidth, fHeight);
finally
pTemp.Canvas.EndScene;
end;
fB.CopyFromBitmap(pTemp);
finally
FreeAndNil(pTemp);
end;
end;

Edited by: Philippe Watel on Jul 16, 2014 6:53 PM
Dominique Willems

Posts: 591
Registered: 10/26/99
Re: How to resize a bitmap in firemonkey  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 16, 2014 11:13 AM   in response to: Philippe Watel in response to: Philippe Watel
Philippe Watel wrote:
Hello
that should be easy but it not
myBitmap:TBitmap;

myBitmap := TBitmap.CreateFromFile(FILENAME_1);

myBitmap := myBitmap.CreateThumbnail(250,250)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02