This question already has answers here:
Android take photo and resize it before saving on sd card

(6 个回答)


4年前关闭。




捕获图像并在 Activity 中显示后,由于图像尺寸较大,它不会插入到数据库中。我需要知道如何压缩和减少图像大小和像素。
         try {
              //  Bitmap bitmap;
                BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();

                bitmap = BitmapFactory.decodeFile(f.getAbsolutePath(),
                        bitmapOptions);

                imageView.setImageBitmap(bitmap);

                String path = android.os.Environment
                        .getExternalStorageDirectory()
                        + File.separator
                        + "Phoenix" + File.separator + "default";
                f.delete();
                OutputStream outFile = null;
                File file = new File(path, String.valueOf(System.currentTimeMillis()) + ".jpg");
                try {
                    outFile = new FileOutputStream(file);
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 85, outFile);
                    outFile.flush();
                    outFile.close();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();

最佳答案

答案就在你的问题中,

在您的代码位图压缩范围是 85

   bitmap.compress(Bitmap.CompressFormat.JPEG, 85, outFile);

您需要将其更改为 25
   bitmap.compress(Bitmap.CompressFormat.JPEG, 25, outFile);

10-07 19:26
查看更多