缩略图正常,但 HTC 设备上的图像内容错误

发布于 2025-01-04 05:32:14 字数 1372 浏览 1 评论 0原文

我有一台 Galaxy Note 设备,我编写了一个从相机中获取 uimage 的应用程序。 我已将布局设置为横向,并且可以使用我的设备抓取图像。问题是当我在别人的设备上运行相同的程序时。 程序在另一台设备上运行相同,但保存图片时图片内容错误。您会看到稍微对角的条纹,而不是图像内容。 我认为这是以错误的间距或分辨率保存图像的结果。 由于某种原因,其他设备上“被窃听”的图片的缩略图是正确的。 我试图找出我的设备和另一台设备之间的差异,但除了一个分辨率为 1280x800 而另一个设备的分辨率为 800x480 之外,我没有发现任何差异。在这两种情况下,测量和布局功能都具有 90 度方向和正确的横向分辨率。在这两种情况下,图像格式都是JPEG(通过查询mCamera.getParameters().getPictureFormat())。 我很困惑,我不知道该怎么办,因为一切看起来都一样,除了一个设备吐出正确的 JPEG 字节数组,而另一个设备给我正确的数据,但方向错误。或者看起来是这样。

编辑:我发现即使我将原始数据直接保存到 JPEG 文件中也会出现问题,因此不涉及显示或解码。我可以在图库浏览器中看到 JPEG 文件有伪影,不知何故是错误的。 我将相机数据保存到(JPEG)文件的代码如下:

private File onJPGPreviewFrame(byte[] data, String Name) {
    FileOutputStream outStream = null;
    File f = null;
    try {
        if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { 
            File externalRoot = Environment.getExternalStorageDirectory(); 
            File tempDir = new File(externalRoot, Name); 
            tempDir.createNewFile();
            outStream = new FileOutputStream(tempDir);  
            outStream.write(data);
            outStream.close();
            f = tempDir;
        }

        Log.d(TAG, "onPreviewFrame - wrote bytes: " + data.length);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
    }
    return f;
}

I have a Galaxy Note device and I wrote an application that grabs uimages from the camera.
I have set the layout to landscape and I am able to grab images with my device. The problem is when I run the same program on someone else's device.
The program runs the same on the other device, but when saving a picture the content of the picture is wrong. You see slightly diagonal strpies instead of the image content.
I think it's the result of the image being saved with the wrong pitch or resolution.
The thumbnail of the "bugged" picture on the other device is for some kind of a reason corret.
I have tried to find the difference between my device and the other device, but apart from one having a resolution of 1280x800 and the other of 800x480, I didn't find any difference. In both cases the Measur and Layout functions have a 90 degrees orientation and the correct landscape resolution. In both cases the image format is JPEG(by inquiring mCamera.getParameters().getPictureFormat()).
I am stumped, I am don't know what to do, because everything seems the same except that one device spits the correct JPEG byte array, and the other gives me the correct data but with the wrong orientation. Or so it seems.

EDIT: I found that there is an issue even when I save the raw data straight into a JPEG file, so no display or decode is involved. I can see in the Gallery browser that the JPEG file has artifacts, is wrong somehow.
My code for saving the camera data into a (JPEG) file is as following:

private File onJPGPreviewFrame(byte[] data, String Name) {
    FileOutputStream outStream = null;
    File f = null;
    try {
        if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { 
            File externalRoot = Environment.getExternalStorageDirectory(); 
            File tempDir = new File(externalRoot, Name); 
            tempDir.createNewFile();
            outStream = new FileOutputStream(tempDir);  
            outStream.write(data);
            outStream.close();
            f = tempDir;
        }

        Log.d(TAG, "onPreviewFrame - wrote bytes: " + data.length);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
    }
    return f;
}

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

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

发布评论

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

评论(1

残月升风 2025-01-11 05:32:14

设备屏幕分辨率的宽高比与设备相机分辨率的宽高比不同。如果您选择预览的宽高比与相机的宽高比相同,则 jpeg 字节数组数据将不会被“窃听”。
这样做的问题是预览会失真,因为它与屏幕的宽高比不匹配。
这是我用来找到最佳纵横比的一些代码:

private Size getOptimalPreviewSize(List<Size> sizes, int width, int height) 
{            
    Size optimalSize = null;                                 

    double targetRatio = (double) width / height;
    int Max = 0;

    for (Size size : sizes) 
    { 
        double ratio = (double) size.width / size.height;
        int m = size.width * size.height;
        if (m>Max && (ratio == targetRatio)) 
        {
            Max = m;
            optimalSize = size; 
        }                
    } 

    if (optimalSize == null) 
    { 
        // TODO : Backup in case we don't get a size. 
    } 

    return optimalSize; 
}

The device screen resolution has a different aspect ratio than the device's camera resolution. If you choose the preview to have the same aspect ratio as the camera's aspect ratio, then the jpeg byte array data will not be "bugged".
The problem with this is that the preview is going to be distorted because it doesn't match the screen's aspet ratio.
Here is some code I used to find the optimal aspect ratio:

private Size getOptimalPreviewSize(List<Size> sizes, int width, int height) 
{            
    Size optimalSize = null;                                 

    double targetRatio = (double) width / height;
    int Max = 0;

    for (Size size : sizes) 
    { 
        double ratio = (double) size.width / size.height;
        int m = size.width * size.height;
        if (m>Max && (ratio == targetRatio)) 
        {
            Max = m;
            optimalSize = size; 
        }                
    } 

    if (optimalSize == null) 
    { 
        // TODO : Backup in case we don't get a size. 
    } 

    return optimalSize; 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文