I am trying to implement one code where user will add image and the size of image should be less then 3MB if the size is greater then it will resize automatically. I know this question is repeated asking but my code is not working properly.
Below is my code
Uri selectedImage = data.getData();
String[] filePath = {MediaStore.Images.Media.DATA};
Cursor c = getContentResolver().query(selectedImage, filePath, null, null, null);
c.moveToFirst();
int columnIndex = c.getColumnIndex(filePath[0]);
String picturePath = c.getString(columnIndex);
c.close();
bitmap2 = (BitmapFactory.decodeFile(picturePath));
Log.e("path of image 4", picturePath + "");
String str = String.valueOf(bitmap2.getRowBytes() * bitmap2.getHeight());
Log.e("lengh of bitmap.......", str);
// Log.e("lengh of bitmap", String.valueOf(bitmap2.getAllocationByteCount()));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap2.compress(Bitmap.CompressFormat.JPEG, 100, bos);
byte[] bitmapdata = bos.toByteArray();
Bitmap resized = Bitmap.createScaledBitmap(bitmap2, 200, 300, true);
imageView2.setImageBitmap(resized);
setImage("image2");