delphi - 使用 TCameraComponent

标签 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;

但是,每次我关闭相机并重新打开它时,调整大小的图像都会捕获实际 TImage 的缩放部分。为什么会发生这种行为?我做错了什么?

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

最佳答案

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);

在柏林及更高版本中,TBitmap 有一个 BoundsF 属性,您可以使用它来代替。

Canvas.DrawBitmap(img.Bitmap, img.Bitmap.BoundsF, TRectF.Create(0, 0, 300, 160), 1.0);

关于delphi - 使用 TCameraComponent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43188703/

相关文章:

delphi - Soap Delphi 客户端因 1MB 调用超时而结束

delphi - Firebird 停用触发器

delphi - 更改应用程序中的字体

Delphi XE2、Delphi 10 西雅图、应用程序句柄、Dll、操作错误

delphi - 我可以使用比我学校使用的更新版本的 Delphi 来完成我的类(class)吗?

delphi - 避免 Delphi 中的代码重复

performance - OR 语句是否比多个 IF 语句更快?

android - 使用 Firemonkey 在 android 中获取设备电子邮件地址

windows - 可以使用 Delphi 为 Chrome 创建扩展吗?

delphi - TShellTreeView 在哪里?