Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我正在从android应用程序保存的jpeg图像不完全清晰_Android_Image_Bitmap_Jpeg - Fatal编程技术网

我正在从android应用程序保存的jpeg图像不完全清晰

我正在从android应用程序保存的jpeg图像不完全清晰,android,image,bitmap,jpeg,Android,Image,Bitmap,Jpeg,我必须将android.media.Image保存为位图,并最终压缩为jpeg。保存的图像为半图像和半灰色。此外,图像也会旋转 # image=frame.acquireCameraImage() 位图位图=BitmapFactory.decodeByteArray(jpegData,0,jpegData.length,选项) 这是您的代码,请像这样更改它 位图位图=BitmapFactory.decodeByteArray(jpegData,100,jpegData.length,选项) 在您

我必须将android.media.Image保存为位图,并最终压缩为jpeg。保存的图像为半图像和半灰色。此外,图像也会旋转

# image=frame.acquireCameraImage()


位图位图=BitmapFactory.decodeByteArray(jpegData,0,jpegData.length,选项)

这是您的代码,请像这样更改它


位图位图=BitmapFactory.decodeByteArray(jpegData,100,jpegData.length,选项)

在您的代码中,您将质量设置为0,因此出现问题,请将其更改为100,使图像保持原样。
希望能有所帮助。

删除日志语句并添加适当的间距将使代码更易于他人阅读。但至少第三个arraycopy有一个错误的OffsetHanks,但结果是:10649/com.google.ar.core.examples.java.helloar E/HelloArActivity:Exception on the OpenGL线程java.lang.ArrayIndexOutOfBoundsException at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:626)
                    Log.i("Bitmap", "-60");
                    Image.Plane[] planes = image.getPlanes();
                    Log.i("Bitmap", "-6");
                    ByteBuffer buffer = planes[0].getBuffer();
                    ByteBuffer buffer1 = planes[1].getBuffer();
                    Log.i("Bitmap", "-15");
                    ByteBuffer buffer2 = planes[2].getBuffer();
                    Log.i("Bitmap", "-7");
                    int format = image.getFormat();
                    int width = image.getWidth();
                    int height = image.getHeight();
                    Log.i("Bitmap", "-20");
                    Rect cropRect = new Rect(0, 0, width, height);
                    Log.i("Bitmap", "-8");
                    byte[] arr = new byte[buffer.remaining()];
                    buffer.get(arr);
                    Log.i("Bitmap", "-9");
                    byte[] arr1 = new byte[buffer1.remaining()];
                    buffer1.get(arr1);
                    Log.i("Bitmap", "-10");
                    byte[] arr2 = new byte[buffer2.remaining()];
                    buffer2.get(arr2);
                    image.close();
                    Log.i("Bitmap", "-5");
                    byte[] c = new byte[arr.length + arr1.length + arr2.length];
                    Log.i("Bitmap", "-1");
                    System.arraycopy(arr, 0, c, 0, arr.length);
                    Log.i("Bitmap", "-2");
                    System.arraycopy(arr1, 0, c, arr.length, arr1.length);
                    Log.i("Bitmap", "-3");
                    System.arraycopy(arr2, 0, c, arr1.length, arr2.length);
                    Log.i("Bitmap", "0");
                    YuvImage yuvImage = new YuvImage(c,ImageFormat.NV21,width,height, null);
                    Log.i("Bitmap", "1");
                    ByteArrayOutputStream b = new ByteArrayOutputStream();
                    Log.i("Bitmap", "1");
                    yuvImage.compressToJpeg(cropRect, 90, b);
                    byte[] jpegData = b.toByteArray();
                    Log.i("Bitmap", "2");
                    BitmapFactory.Options options = new BitmapFactory.Options();
                    options.inPreferQualityOverSpeed=true;
                    // int scaleFactor;
                    //options.inSampleSize = scaleFactor;
                    Log.i("Bitmap", "3");
                    Bitmap bitmap = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length, options);
                    saveBitmap(bitmap);