【发布时间】:2014-04-04 22:46:31
【问题描述】:
我需要知道是否需要设置两个位图来在两个 ImageView 中显示图像。我正在从图库上传图片。
代码:-
public void decodeFile(String filePath) {
// Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, o);
// The new size we want to scale to
final int REQUIRED_SIZE = 1024;
// Find the correct scale value. It should be the power of 2.
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1;
while (true) {
if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE)
break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
// Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
bitmap = BitmapFactory.decodeFile(filePath, o2);
//first image i have uploaded by using first button
imgView1.setImageBitmap(bitmap);
imgView2.setImageBitmap(bitmap);
}
【问题讨论】:
-
问题是什么?您是在问是否可以将一个图像资源分配给多个 ImageView?
-
@fremmedehenvendelser 不,我将不同的图像资源分配给 2 个不同的图像视图。它们将使用 2 个不同的按钮上传。
-
您将同一个位图设置为两个不同的图像视图。
-
@Lunchbox 好的,如何为 2 个图像视图设置不同的位图。