Reputation: 792
I am trying to resize a captured TCameraComponent
image using the following code:
procedure TForm1.GetImage;
begin
imagec.SampleBufferToBitmap(img.Bitmap, True);
with resizedimg.Bitmap do // Resize the image to another bitmap
begin
SetSize(300, 160);
if Canvas.BeginScene then
try
Canvas.DrawBitmap(img.Bitmap, TRectF.Create(0, 0, 300, 160), TRectF.Create(0, 0, 300, 160), 1.0);
finally
Canvas.EndScene;
end;
end;
end;
But, each time I turn the camera off and re-open it again, the resized image captures a zoomed part of the actual TImage
. Why does this behavior happen? What am I doing wrong?
The goal is to resize img.Bitmap
to fit within 300x160 pixels.
Upvotes: 3
Views: 1046
Reputation: 595349
The 2nd parameter of DrawBitmap()
should be the original size of the img.Bitmap
that is being drawn, not the size that you are trying to resize to.
Canvas.DrawBitmap(img.Bitmap, TRectF.Create(0, 0, img.Bitmap.Width, img.Bitmap.Height), TRectF.Create(0, 0, 300, 160), 1.0);
In Berlin and later, TBitmap
has a BoundsF
property you can use instead.
Canvas.DrawBitmap(img.Bitmap, img.Bitmap.BoundsF, TRectF.Create(0, 0, 300, 160), 1.0);
Upvotes: 5