使用TCameraComponent

Vla*_*pin 3 delphi firemonkey delphi-10-seattle

我正在尝试TCameraComponent使用以下代码调整捕获的图像的大小:

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;
Run Code Online (Sandbox Code Playgroud)

但是,每次关闭相机并再次重新打开相机时,调整大小的图像会捕获实际的缩放部分TImage.为什么会出现这种情况?我究竟做错了什么?

目标是调整大小img.Bitmap以适应300x160像素.

Rem*_*eau 5

第二个参数DrawBitmap()应该img.Bitmap是绘制的原始大小,而不是您尝试调整大小的大小.

Canvas.DrawBitmap(img.Bitmap, TRectF.Create(0, 0, img.Bitmap.Width, img.Bitmap.Height), TRectF.Create(0, 0, 300, 160), 1.0);
Run Code Online (Sandbox Code Playgroud)

在柏林和以后,TBitmap有一个BoundsF属性,你可以使用.

Canvas.DrawBitmap(img.Bitmap, img.Bitmap.BoundsF, TRectF.Create(0, 0, 300, 160), 1.0);
Run Code Online (Sandbox Code Playgroud)