Reputation:
I have a bitmap image of dimensions(width = 250, height = 200). I am stretching it with following code snippet, but the quality is deteriorated. Is there a way to retain the quality of bitmap image while stretching it?
with Bitmap do
begin
Width := 200;
Height := 150;
PixelFormat := pf1bit;
TransparentMode := tmAuto;
Canvas.CopyMode := cmSrcCopy;
Canvas.FillRect(Rect(0, 0, Width, Height));
Canvas.StretchDraw(Rect(0, 0, Width, Height), MyBitMap);
end;
Here, MyBitMap
is of type TBitMap
in which I have loaded the original bitmap image.
AND, Is this the right way of doing this?
Upvotes: 1
Views: 21675
Reputation: 91
it could be because you have PixelFormat := pf1bit;
put it at least pf8bit or better pf24bit for better result since you don't care about the filesize
Upvotes: 0
Reputation: 66
Here is a very nice procedure called SmoothResize(abmp:TBitmap; NuWidth,NuHeight:integer);. It is able to resize a TBitmap width great quality. Don't forget to add the two type declarations.
The StretchDraw method is very fast and is a part of canvas. The quality is as you described not much brilliant. If you want to use StretchDraw change PixelFormat to pf24bit and delete the FillRect-line.
hope this helps :)
Upvotes: 5