How to save a JPEG image on Android with a custom quality level

后端 未结 4 1290
滥情空心
滥情空心 2020-12-01 11:47

On Android, how do I save an image file as a JPEG at 30% quality?

In standard Java, I would use ImageIO to read the image as a BufferedImage

4条回答
  •  不思量自难忘°
    2020-12-01 12:02

    You can store your bitmap in the JPEG format by calling compress and setting the second parameter:

    
        Bitmap bm2 = createBitmap();
        OutputStream stream = new FileOutputStream("/sdcard/test.jpg");
        /* Write bitmap to file using JPEG and 80% quality hint for JPEG. */
        bm2.compress(CompressFormat.JPEG, 80, stream);
    

提交回复
热议问题