Camera picture to Bitmap results in messed up image

后端 未结 7 1989
谎友^
谎友^ 2020-12-29 10:00

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

7条回答
  •  清酒与你
    2020-12-29 10:15

    Did you try to put null at your Options? Try that:

    @Override
    public void onPictureTaken(final byte[] data, Camera camera) {
        Bitmap bm = BitmapFactory.decodeByteArray(data, 0, data.length, null);
        try {
            FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath()+"/image.jpg");
            bm.compress(Bitmap.CompressFormat.JPEG, 95, out);
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    

提交回复
热议问题