How to compress image size in Android Studio | compressed Image | Java

Опубликовано: 01 Октябрь 2024
на канале: Foysal Official
659
8

#java

android compress image size before sending to server , How to compress an image file in Android , How to reduce an Image file size before uploading to a server , Compress Image in android , How to Compress Image or Resize Image for Android Apps , How to compress and reduce size(resolution) of image file from your Android App? - Android 13 API 33 , Reduce Image Size for Upload | Android Tutorial 2023 , Compressing Images in Android 2023 , How to compress image or resize image for Android apps , How do I compress image in android studio(JAVA)

Uri imageUri = data.getData();
Bitmap selectedImage = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
Bitmap compressedImage = compressImage(selectedImage);

private Bitmap compressImage(Bitmap image) {
int originalWidth = image.getWidth();
int originalHeight = image.getHeight();
int targetWidth = originalWidth / 5;
int targetHeight = originalHeight / 5;
Bitmap resizedImage = Bitmap.createScaledBitmap(image, targetWidth, targetHeight, false);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
resizedImage.compress(Bitmap.CompressFormat.JPEG, 80, outputStream);
byte[] imageBytes = outputStream.toByteArray();
return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
}

#Ict_Foysal
#Foysal_Tech
#Android_Studio
#Mohammed_Foysal
#Android_Studio_Bangla
#Android_App_development
#Mohammed_Foysal_Official