Qad*_*ain 6 android bitmap bitmapimage imageview android-imageview
我有一个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" />
Run Code Online (Sandbox Code Playgroud)
我从相机捕获图像,将该图像转换为位图.
Bitmap thumbnail;
thumbnail = MediaStore.Images.Media.getBitmap(getActivity()
.getContentResolver(), imageUri);
Run Code Online (Sandbox Code Playgroud)
当我在上面的imageview中显示它之前得到这个位图的分辨率,比如
Log.i("ImageWidth = " + thumbnail.getWidth(), "ImageHeight = "
+ thumbnail.getHeight());
Run Code Online (Sandbox Code Playgroud)
它归还了我 ImageWidth = 2592 ImageHeight = 1936
在此之后我在上面的imageview中显示了这个位图,imgCaptured.setImageBitmap(thumbnail); 然后我将我的imageview的大小视为
Log.i("ImageView Width = " + imgCaptured.getWidth(),
"ImageView Height = " + imgCaptured.getHeight());
Run Code Online (Sandbox Code Playgroud)
这让我回头 ImageView Width = 480 ImageView Height = 720
现在我的问题是
在我的imageview中显示后,如何获得该位图的大小.我知道这可以通过使用它来完成
image.buildDrawingCache();
Bitmap bmap = image.getDrawingCache();
Run Code Online (Sandbox Code Playgroud)
但这会创建一个大小等于imageview的新位图.
我还想知道,在imageview中显示后,图像会自动调整大小.如果是,那么有没有办法在imageview中显示图像而不调整图像大小.
编辑
实际上我已经拍摄了2592x1936的图像.我在imageView中显示了这个图像,对此图像做了一些其他操作.现在我想以相同的2592x1936分辨率保存此图像.可能吗?
提前致谢.
在ImageView中显示位图后,ImageView将创建一个BitmapDrawable对象,以在ImageView的Canvas中绘制它.所以,你可以调用ImageView.getDrawable()方法来获取BitmapDrawable的参考,并获得通过调用Drawable.getBounds的边界(矩形RECT)方法.通过边界,您可以计算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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14461 次 |
| 最近记录: |