How to get the size of a bitmap after it is displayed in ImageView

I have an image

<ImageView android:id="@+id/imgCaptured" android:layout_width="fill_parent" android:layout_height="fill_parent" android:adjustViewBounds="true" android:scaleType="fitXY" android:src="@drawable/captured_image" /> 

I capture a camera image by converting this image to a bitmap.

 Bitmap thumbnail; thumbnail = MediaStore.Images.Media.getBitmap(getActivity() .getContentResolver(), imageUri); 

when I get the resolution of this bitmap before displaying it in my image above, for example

 Log.i("ImageWidth = " + thumbnail.getWidth(), "ImageHeight = " + thumbnail.getHeight()); 

his return to me ImageWidth = 2592 ImageHeight = 1936

after that I displayed this bitmap in my image above as imgCaptured.setImageBitmap(thumbnail); then I put the size of my image as

 Log.i("ImageView Width = " + imgCaptured.getWidth(), "ImageView Height = " + imgCaptured.getHeight()); 

this returned me ImageView Width = 480 ImageView Height = 720

now my question is what

  • How can I get the size of this bitmap after displaying it in my image view. I know that this can be done using this

     image.buildDrawingCache(); Bitmap bmap = image.getDrawingCache(); 

    but this will create a new raster size equal to the size of the image.

  • I also want to know that whether the image changed automatically after it was displayed in the image view. if so, is there a way to show the image in image view without resizing the image.

Edit

In fact, I captured a 2592x1936 image. I displayed this image in my View image, did some other operations on this image. Now I want to save this image with the same resolution 2592x1936. is it possible?

Thanks in advance.

+4
source share
1 answer

After displaying the bitmap in the ImageView, ImageView will create a BitmapDrawable to draw it in the ImageView Canvas. So you can call the ImageView.getDrawable () method to get a reference to BitmapDrawable, and get Bounds by calling Drawable.getBounds (Rect rect). through the borders you can calculate the width and height of the bitmap drawn in the ImageView

 Drawable drawable = ImageView.getDrawable(); //you should call after the bitmap drawn Rect bounds = drawable.getBounds(); int width = bounds.width(); int height = bounds.height(); int bitmapWidth = drawable.getIntrinsicWidth(); //this is the bitmap width int bitmapHeight = drawable.getIntrinsicHeight(); //this is the bitmap height 
+6
source

All Articles