How to get the size of bitmap after displaying it in ImageView(在 ImageView 中显示后如何获取位图的大小)
问题描述
I have a imageview
<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 image from camera, converted that image into bitmap.
Bitmap thumbnail;
thumbnail = MediaStore.Images.Media.getBitmap(getActivity()
.getContentResolver(), imageUri);
when i get the resolution of this bitmap before displaying it in my above imageview, like
Log.i("ImageWidth = " + thumbnail.getWidth(), "ImageHeight = "
+ thumbnail.getHeight());
its returning me ImageWidth = 2592 ImageHeight = 1936
after this i displayed this bitmap in my above imageview as imgCaptured.setImageBitmap(thumbnail);
then i go size of my imageview as
Log.i("ImageView Width = " + imgCaptured.getWidth(),
"ImageView Height = " + imgCaptured.getHeight());
this returned me ImageView Width = 480 ImageView Height = 720
now my question is that
How can i get the size of that bitmap after displaying it in my imageview. I know this can be done by using this
image.buildDrawingCache(); Bitmap bmap = image.getDrawingCache();
but this will create a new bitmap of size equal to that of imageview.
I also want to know that, Does image resized automatically after displaying it in the imageview. if yes then is there any way to display the image in imageview without resizing the image.
Edit
Actually i have captured an image of 2592x1936. I displayed this image in my imageView, did some other operations on this image . now i want to save this image with same 2592x1936 resolution. is it possible?
Thanks in advance.
After you display a Bitmap
in a ImageView
, The ImageView
will create a BitmapDrawable object to draw it in ImageView's Canvas. So you can invoke ImageView.getDrawable()
method to get the reference of the BitmapDrawable
, and get the Bounds by invoke Drawable.getBounds(Rect rect
) method. through the bounds, you can compute the width and height of the Bitmap drawn in 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's width
int bitmapHeight = drawable.getIntrinsicHeight(); //this is the bitmap's height
这篇关于在 ImageView 中显示后如何获取位图的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 ImageView 中显示后如何获取位图的大小
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01