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

Firemonkey Android中TakePhotoFromCameraAction拍照分辨率过低如何解决?

Android Firemonkey 拍照保存低分辨率问题解决

问题根源

你当前使用的TakePhotoFromCameraAction1DidFinishTaking事件传入的Image参数,是系统返回的压缩缩略图,并非相机拍摄的原始高分辨率照片——所以哪怕相机设了最大分辨率,拿到的Bitmap尺寸还是很小,后续保存的画质自然差。

解决步骤

要获取原始高分辨率照片,得通过Action的OriginalFilePath属性获取原始照片的存储路径,再对原始文件进行操作:

  • 先把TTakePhotoFromCameraAction的ImageFormat属性设为TImageFormat.Unknown(保留原始拍摄格式),或根据需求设置对应格式;
  • 在OnDidFinishTaking事件中,读取OriginalFilePath指向的原始文件,再复制或转存到目标路径;
  • 如果需要调整JPG质量,再读取原始文件为Bitmap后设置参数保存。

修改后的代码示例

procedure TMainForm.TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap);
var
  OriginalPath, TargetPath: string;
  JpgQuality: TBitmapCodecSaveParams;
  OriginalBitmap: TBitmap;
begin
  // 获取相机拍摄的原始照片路径
  OriginalPath := TakePhotoFromCameraAction1.OriginalFilePath;
  if OriginalPath = '' then Exit;

  TargetPath := TPath.Combine(TPath.GetSharedPicturesPath, 'test.jpg');

  // 方案1:直接复制原始文件(最快,完全保留原始画质)
  // TFile.Copy(OriginalPath, TargetPath, True);

  // 方案2:读取原始文件并调整JPG质量后保存
  OriginalBitmap := TBitmap.Create;
  try
    OriginalBitmap.LoadFromFile(OriginalPath);
    JpgQuality.Quality := 100;
    OriginalBitmap.SaveToFile(TargetPath, @JpgQuality);
  finally
    OriginalBitmap.Free;
  end;
end;

额外注意

  • 确保App拥有存储读写权限,Android 10及以上版本需处理Scoped Storage,或在Manifest中添加android:requestLegacyExternalStorage="true"以兼容旧存储逻辑;
  • 若无需转格式,直接复制原始文件的效率最高,也能完整保留相机拍摄的原始分辨率与画质。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 21:57:09