A
A
AlexeyID2018-09-07 21:15:08
Android
AlexeyID, 2018-09-07 21:15:08

How to qualitatively compress an image?

Tell me how to compress the image better, now I have the following code and the following results:

//путь к изображению
                fullPictureObj.get(0).getPath();

                File decodeFile = new File(fullPictureObj.get(0).getPath());

                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inPreferredConfig = Bitmap.Config.ARGB_8888;
                Bitmap bitmapFull = BitmapFactory.decodeFile(fullPictureObj.get(0).getPath(), options);
                int imageHeight = options.outHeight;
                int imageWidth = options.outWidth;

                //Ориентация изображения
                Bitmap rotateBitmap = rotateBitmap(bitmapFull,
                        fullPictureObj.get(0).getRealOrientation());
                bitmapFull.recycle();

                int newWidth = 960;
                float k = (float) imageWidth/ (float) newWidth;
                float newHeightFloat = ((float) imageHeight/k);
                int newHeight = (int) newHeightFloat;


                
                /*
                int maxSize = 960;
                if(imageWidth > imageHeight){
                    newWidth = maxSize;
                    newHeight = (imageHeight * maxSize) / imageWidth;
                } else {
                    newHeight = maxSize;
                    newWidth = (imageWidth * maxSize) / imageHeight;
                }
                */


                Bitmap bitmapMini = Bitmap.createScaledBitmap(rotateBitmap, newWidth, newHeight, false);
               // rotateBitmap.recycle();

                //Сохраняю изображения для сравнения и теста
                MediaStore.Images.Media.insertImage(getContext().getContentResolver(),
                        bitmapMini, "test" , null);

Original: 4608 X 3456 4.78MB
Result: 960 X 720 60.6KB
With compression, the weight is not critical, but the result should not exceed a width of 1000px
Original: https://pp.userapi.com/c846018/v846018037/e0d60/r9... ( not quite original)
Result: https://pp.userapi.com/c846018/v846018037/e0d69/Hx...
How can I better reduce the width and height of the image? As can be seen from the example, the result, to put it mildly, is not very good.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Moskus, 2018-09-07
@Moskus

The result is "not very", because you have hellishly strong compression, which in this code is at the mercy of the system itself (and there - xs what coefficient it uses).
See this discussion: https://stackoverflow.com/questions/36487971/how-t...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question