Android 如何确保我的位图为ARGB_8888格式且具有尽可能高的质量?

Android 如何确保我的位图为ARGB_8888格式且具有尽可能高的质量?,android,bitmap,android-camera,Android,Bitmap,Android Camera,我有一个相机应用程序,我的相机预览和拍摄的图像质量相当低。我已经阅读了一些关于位图的内容,它建议将捕获的图像配置为以ARGB_8888格式保存,但我所阅读的示例中没有一个与我的用例真正匹配。以下是拍照时执行的函数: @Override public void onPictureTaken(byte[] data, Camera camera) { File pictureFile = Util.getOutputMediaFile(this); if (p

我有一个相机应用程序,我的相机预览和拍摄的图像质量相当低。我已经阅读了一些关于位图的内容,它建议将捕获的图像配置为以ARGB_8888格式保存,但我所阅读的示例中没有一个与我的用例真正匹配。以下是拍照时执行的函数:

@Override
    public void onPictureTaken(byte[] data, Camera camera) {
        File pictureFile = Util.getOutputMediaFile(this);
        if (pictureFile == null) {
            Toast.makeText(this, "Couldn't create file", Toast.LENGTH_SHORT)
                    .show();
        } else {
            try {
                FileOutputStream fos = new FileOutputStream(pictureFile);
                fos.write(data);
                fos.close();
            } catch (FileNotFoundException e) {
                Toast.makeText(this, "File not found exception",
                        Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                Toast.makeText(this, "IO Exception", Toast.LENGTH_SHORT).show();
            }
            BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(),
                    pictureFile.getAbsolutePath());
            Bitmap bm1 = bitmapDrawable.getBitmap();
            Matrix matrix = new Matrix();
            int w = bm1.getWidth();
            int h = bm1.getHeight();
            matrix.setScale(-1, 1);
            matrix.preRotate(-90);
            Bitmap adjustedBitmap = Bitmap.createBitmap(bm1, 0, 0,
                    w, h, matrix, true);     //I'm tempted to put it here, but it always throws errors when I try and add Bitmap.Config.ARGB_8888 as an argument to createBitmap
            OutputStream outStream = null;
            // sampleimage4 is the name given to the image saved. You can give
            // any name
            File file = new File(pictureFile.getAbsolutePath());
            try {
                outStream = new FileOutputStream(file);
                // saving as a JPEG image
                adjustedBitmap.compress(Bitmap.CompressFormat.JPEG, 100,
                        outStream);
                outStream.flush();
                outStream.close();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Intent intent = new Intent(this, ImagePreview.class);
            if (getIntent().getExtras() != null) {
                if (bundle != null)
                    intent.putExtra("bundle", bundle);
            }
            intent.putExtra("filePath", pictureFile.getAbsolutePath());
            intent.putExtra("load", load);
            intent.putExtra("height", preview.getHeight());
            intent.putExtra("width", preview.getWidth());

            startActivity(intent);
            camera.startPreview();
        }
    }

希望你能看到我的愿望是使用ARBB88。但我不知道如何实现这一点

如果您主要关心的是质量,请使用PNG而不是JPEG压缩它。或者把它留在你的车里。你确定你的RGB格式是罪魁祸首吗?你看到图像中有什么东西表明量化不好吗?它是一个相当小的位图,640x480,比屏幕小得多。使用JPEG或PNG压缩时会发生这种情况。我原以为argb_8888可以节省更多像素,但这只是一个理论。任何能在位图中获得更多像素的东西都是好的。PNG是无损RGBA 8888。JPEG是有损的,因此您可能会丢失一些细节,但在高质量设置下,肉眼不应注意到它。从YUV到RGB的颜色空间转换可能会丢失一些保真度,但在抓拍照片时,这并不是很明显的事情。我可以做些什么使位图保存的像素数超过640 x 480?配置相机以捕获更大的图像。