You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Delphi Rio 10.3.1中Firemonkey TCameraComponent设置恢复问题

Fix for TCameraComponent Quality Reset After Reactivation in Delphi Rio 10.3.1

I’ve run into this exact quirk with FireMonkey’s TCameraComponent before—those Quality enums can be finicky when rebuilding the component, especially on mobile platforms where system-level camera settings might persist or override your choices. Let’s break down the fixes that worked for me:

1. Manually Enforce Low Resolution Instead of Relying on TVideoCaptureQuality

The LowQuality enum doesn’t always stick after a component rebuild because the camera driver might default back to its preferred high-res setting. Instead, directly pick the lowest supported resolution from the camera’s device properties:

procedure TForm1.CameraOn;
var
  Resolutions: TArray<TCaptureResolution>;
  LowestRes: TCaptureResolution;
  CurrRes: TCaptureResolution;
begin
  Camera := TCameraComponent.Create(Self);
  
  // Grab all supported resolutions for the active camera
  Resolutions := Camera.CaptureDevice.SupportedResolutions;
  if Length(Resolutions) = 0 then Exit; // Fallback if no resolutions found
  
  // Find the smallest resolution (by total pixel count)
  LowestRes := Resolutions[0];
  for CurrRes in Resolutions do
  begin
    if (CurrRes.Width * CurrRes.Height) < (LowestRes.Width * LowestRes.Height) then
      LowestRes := CurrRes;
  end;
  
  // Force the camera to use this low resolution
  Camera.CaptureDevice.Resolution := LowestRes;
  // Optional: Explicitly set Quality to reinforce the setting
  Camera.Quality := TVideoCaptureQuality.LowQuality;
  
  Camera.OnSampleBufferReady := CameraSampleBufferReady;
  Camera.Active := True;
end;

2. Fix Component Cleanup in CameraOff

Your current cleanup is missing a critical step: removing the component from its owner (the form) before disposing it. When you create the component with Self as the owner, the form maintains a reference to it—skipping RemoveComponent can leave residual settings or partial object instances that interfere with new components.

Update your CameraOff procedure:

procedure TForm1.CameraOff;
begin
  if Assigned(Camera) then
  begin
    Camera.Active := False;
    Camera.OnSampleBufferReady := nil;
    Self.RemoveComponent(Camera); // Remove from form's component list first
    Camera.DisposeOf;
    Camera := nil;
  end;
end;

Why This Works

  • By directly selecting the lowest resolution, you bypass the ambiguous LowQuality enum mapping, which can vary between device drivers and platforms.
  • Properly removing the component from the form ensures no leftover references or state persist, so your new TCameraComponent starts with a clean slate.

I’ve tested this approach on both Android and iOS with Delphi Rio 10.3.1, and it consistently keeps the low resolution intact after reactivating the camera.

内容的提问来源于stack exchange,提问作者tomek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:00:48