0

我正在为我的应用程序从图库中请求图像。我发现下载文件夹中的图像未显示在我的应用程序中。从 LogCat 我发现图像已由 Activity 获取:

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 中显示的图像的最大高度和宽度?

4

1 回答 1

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);

资源

于 2013-11-14T11:20:45.270 回答