Hello i am new in android. Can anybody help me to maintain aspect ratio of image. In my application i select image from SDCARD and display it in imageview by passing intent to next activity. But most of the times when image is big or small then image is not display properly in my imageview.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inTempStorage = new byte[16 * 1024];
options.inJustDecodeBounds = true;
bitmap = BitmapFactory.decodeStream(getContentResolver()
.openInputStream(mImageCaptureUri));
ByteArrayOutputStream bs = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 50, bs);
Bitmap newbitmap = Bitmap.createScaledBitmap(bitmap, 120,
120, true);
newbitmap.compress(Bitmap.CompressFormat.PNG, 50, bs);
Intent photointent = new Intent(MethinkzActivity.this,
DisplayImage.class);
photointent.putExtra("photo", bs.toByteArray());
startActivity(photointent);
And at other activity i catch that by using following.
bitmap = BitmapFactory.decodeByteArray(getIntent()
.getByteArrayExtra("photo"), 0, getIntent()
.getByteArrayExtra("photo").length);
final double viewWidthToBitmapWidthRatio = (double) my_image
.getWidth() / (double) bitmap.getWidth();
my_image.getLayoutParams().height = (int) (bitmap.getHeight() * viewWidthToBitmapWidthRatio);
my_image.setImageBitmap(bitmap);
Please help me to find this.
you should have to use Scalling Property of ImageView for the ImageView use this property in your xml file use one the scale type for imageview