Android 相机预览会损坏 G2 上的图像输出吗?

发布于 2024-11-28 09:21:32 字数 611 浏览 0 评论 0原文

我使用 Android 的 CameraSurfaceView 在拍照之前向用户显示预览图像。这在屏幕上看起来很好,但当我拍照时,生成的 jpg 已损坏(水平线)。

作为起点,我使用了 Mark Murphy 的相机/图片示例,其中G2 上也出现同样的问题。

相机参数:

预览尺寸:800x480

图片格式:JPEG

根据 getSupportedPreviewSizes()getSupportedPictureFormats() 均支持

这两个参数 Nexus One,其屏幕尺寸相同,使用相同的参数可以正常工作。

将预览尺寸设置为 640x480 时,G2 可以正常工作

我的问题:之前是否有人遇到过此问题(尽管使用支持的设置,但图像已损坏)?发生的频率如何?你是如何解决这个问题的?

I'm using Android's Camera and SurfaceView to show a the preview image to the user before taking a picture. This appears fine on the screen but when I take the picture the resulting jpg is corrupted (horizontal lines).

As a starting point I used Mark Murphy's Camera/Picture example which exhibits the same issue on the G2.

The camera paramaters:

preview size: 800x480

picture format: JPEG

Both parameters are supported according to the getSupportedPreviewSizes() and getSupportedPictureFormats()

The Nexus One, which has the same size screen, works correctly with the same parameters.

The G2 works correctly when setting the preview size to 640x480

My question: Has anyone else run into this issue before (corrupted image despite using supported settings)? How frequent is it? How did you work around it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏末染殇 2024-12-05 09:21:33

到目前为止,我遇到了同样的问题,现在我设法使用

setPictureFormat(ImageFormat.JPEG);

相机参数设置来修复我的问题。

最近刚刚发现相机默认的图片输出是YUV。这就是为什么它在预览时显示完美,但一旦拍摄照片,您就会得到绿色、粉红色或损坏的图像输出。
这些是相机可能支持的 ImageFormat 值。

JPEG = 256;
NV16 = 16;
NV21 = 17;
RAW10 = 37;
RAW_SENSOR = 32;
RGB_565 = 4;
UNKNOWN = 0;
YUV_420_888 = 35;
YUY2 = 20;
YV12 = 842094169;

因此,除了支持的大小之外,在某些情况下我们可能还需要检查 PictureFormat。

https://i.sstatic.net/PlHFH.png

这些只是使用 ImageFormat 拍摄的示例图像YUV,从而将其保存为 JPEG 压缩。

但在任何情况下,如果您不想更改 ImageFormat 并因此将设置保留为 YUV 格式,您可能需要在此解决方法中保存图像:

Camera.Parameters parameters = camera.getParameters();
Camera.Size size = parameters.getPreviewSize();
YuvImage image = new YuvImage(data, parameters.getPreviewFormat(),
                    size.width, size.height, null);
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "YuvImage.jpg");
FileOutptStream filecon = new FileOutputStream(file);
image.compressToJpeg(new Rect(0, 0, image.getWidth(), image.getHeight()), 90,
                    filecon);

So far I had the same issue and now I manage to fix mine using

setPictureFormat(ImageFormat.JPEG);

Camera parameter settings.

Just recently found out that the camera default picture output was YUV. That's is why it shows perfectly on preview but once the picture is taken you would get a green or pink or corrupted image output.
These are the ImageFormat values which camera might support.

JPEG = 256;
NV16 = 16;
NV21 = 17;
RAW10 = 37;
RAW_SENSOR = 32;
RGB_565 = 4;
UNKNOWN = 0;
YUV_420_888 = 35;
YUY2 = 20;
YV12 = 842094169;

So other than the supported size, on some cases we might need to check the PictureFormat as well.

https://i.sstatic.net/PlHFH.png

These are just sample images taken using ImageFormat YUV and thus saving it as JPEG compression.

But in any case that you don't want to change the ImageFormat and thus keep the settings in YUV format you may need to save the image in this workaround:

Camera.Parameters parameters = camera.getParameters();
Camera.Size size = parameters.getPreviewSize();
YuvImage image = new YuvImage(data, parameters.getPreviewFormat(),
                    size.width, size.height, null);
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "YuvImage.jpg");
FileOutptStream filecon = new FileOutputStream(file);
image.compressToJpeg(new Rect(0, 0, image.getWidth(), image.getHeight()), 90,
                    filecon);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文