【问题标题】:Working with TCameraComponent使用 TCameraComponent
【发布时间】:2017-08-28 13:26:33
【问题描述】:

我正在尝试使用以下代码调整捕获的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 像素。

【问题讨论】:

    标签: delphi firemonkey delphi-10-seattle


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-10
      • 1970-01-01
      • 1970-01-01
      • 2016-03-23
      • 2015-09-08
      • 2020-12-19
      • 2017-11-20
      相关资源
      最近更新 更多