摄像头的图片在搞砸了图像点阵结果 [英] Camera picture to Bitmap results in messed up image

查看:186
本文介绍了摄像头的图片在搞砸了图像点阵结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的,我用的图像保存到位图 code。这片code基于来自的CyanogenMod的摄像头应用程序中的code,所以我会相信它会正常工作,但没了。在有关此问题的最重要的事情是,当在一台Nexus 4测试的 位图正在与背部面对镜头,但使用面朝前拍摄的照片正确创建相机导致你可以看到下面。

这是我用来创建位图的code

 私有类XyzPictureCallback实现Camera.PictureCallback {

    @覆盖
    公共无效onPictureTaken(byte []的数据,摄像头摄像头){
        选项​​选项=新的选项();
        options.inDither = FALSE;
        options.in preferredConfig = Bitmap.Config.ARGB_8888;

        位图图像= BitmapFactory.de codeByteArray(数据,0,data.length,期权);
    }
}
 

我试着用不同的选项(并没有在所有),但它并没有帮助。它可能是由两种不同的相机返回的像素格式,但是,当我跑 getSupportedPictureFormats()他们都返回 ImageFormat.JPEG ...

我运行的想法......

我应该还提到,直接保存数据使用的FileOutputStream 是建立一个正确的JPEG图像。所以,问题必须与 BitmapFactory 和我创建的方式位图

这是这个code产生的位图:

修改(2013年3月24日):

花费多个小时试图解决这个问题我还没有真正解决这个之后。 我所发现的是,当我将图像尺寸设置(使用 Camera.Parameters.setPictureSize(INT宽度,高度INT)),以尽可能高的问题只发生分辨率,可用于我已经通过调用 Camera.Parameters.getSupportedPictureSizes()

获得的前置摄像头

这是造成问题的分辨率为1280×960。正如我前面提到它的最高分辨率。第二个最高的是1280×720,当我用这一个,输出图像正常。我做了检查相机吐出的格式和它的ImageFormat.JPEG所有的时间,所以我不认为像素格式是这里的问题...

修改(2013年3月8日): 召唤takePicture:

 私有类XyzAutoFocusCallback实现Camera.AutoFocusCallback {

            @覆盖
            公共无效onAutoFocus(布尔成功,相机摄像头){
                    如果(takingPicture){
                            camera.takePicture(NULL,NULL,myPictureCallback);
                    } 其他 {
                    ...
            }

}
 

解决方案

的高度和宽度不支持该摄像机。这就是为什么它看起来像这一点,为什么1280×720的设置工作。这是相同的,如果你设置你的星际争霸到不支持您的显示器的分辨率运行的。

This is my code that I use to save the image to a Bitmap. This piece of code is based on the code from CyanogenMod's camera app so I would assume it would work properly but nope. The most important thing about this issue is that when tested on a Nexus 4 the Bitmap was being created properly for pictures taken with the back facing camera but using the front facing camera resulted in what you can see below.

The code that I'm using to create the Bitmap:

private class XyzPictureCallback implements Camera.PictureCallback {

    @Override
    public void onPictureTaken (byte [] data, Camera camera) {
        Options options = new Options();
        options.inDither = false;
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;

        Bitmap image = BitmapFactory.decodeByteArray(data, 0, data.length, options);
    }
}

I tried using different Options (and none at all) but it did not help. It might be something with the pixel format returned by the two different cameras but when I ran getSupportedPictureFormats() they both returned ImageFormat.JPEG...

I'm running out of ideas...

I should probably also mention that saving the data directly using a FileOutputStream was creating a proper JPEG image. So the problem must be with the BitmapFactory and the way I create the Bitmap.

This is the bitmap that this code produces:

EDIT (24.03.2013):

After spending multiple hours trying to fix this I still have no real solution to this. All i've found out is that the problem only occurs when I set the picture size (using Camera.Parameters.setPictureSize(int width, int height)) to the highest possible resolution that is available to the front facing camera which I've obtained by calling Camera.Parameters.getSupportedPictureSizes().

The resolution that is causing the problem is 1280x960. As I've mentioned earlier it's the highest resolution. The second highest is 1280x720 and when I use this one the output picture is fine. I did check the format that the camera spits out and it's ImageFormat.JPEG all the time so i don't think the pixel format is the issue here...

EDIT (08.03.2013): Call to takePicture:

private class XyzAutoFocusCallback implements Camera.AutoFocusCallback {

            @Override
            public void onAutoFocus(boolean success, Camera camera) {
                    if (takingPicture) {
                            camera.takePicture(null, null, myPictureCallback);
                    } else {
                    ...
            }

}

解决方案

The height and width aren't supported for that camera. That's why it looks like that and why the 1280x720 setting works. It's the same as if you set your starcraft to run at a resolution not supported by your monitor.

这篇关于摄像头的图片在搞砸了图像点阵结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆