查找可在ImageView中显示的图像的最大高度和宽度

时间:2013-11-14 11:10:38

标签: android imageview

我正在为我的应用程序请求图库中的图像。我发现下载文件夹中的图像没有显示在我的应用程序中。从LogCat我发现该图像已通过活动获取:

D/BadgerListActivity(1984): Uri is: content://media/external/images/media/3080 and the pathName: /storage/emulated/0/Download/2801.jpg
D/ImagePreviewActivity(1984): pathName: /storage/emulated/0/Download/2801.jpg
W/OpenGLRenderer(1984): Bitmap too large to be uploaded into a texture (1905x2481, max=2048x2048)

如何以编程方式查找可在ImageView中显示的图像的最大高度和宽度?

1 个答案:

答案 0 :(得分:2)

缩小图像并尝试

ImageView iv  = (ImageView)ImagePreviewActivity.findViewById(R.id.photo);
Bitmap bitmap  = new BitmapDrawable(context.getResources() , w.photo.getAbsolutePath()).getBitmap();
int size = (int) ( bitmap .getHeight() * (512.0 / bitmap .getWidth()) );
Bitmap scaled = Bitmap.createScaledBitmap(bitmap , 512, size, true);
iv.setImageBitmap(scaled);

Source