我们需要两个位图用于2个不同的ImageViews

时间:2014-04-04 13:35:33

标签: android imageview

我需要知道是否需要设置两个位图来显示两个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);


   }

1 个答案:

答案 0 :(得分:0)

虽然问题不是很清楚,但是从阅读评论我明白你可能想要为两个ImageView设置不同的位图。如果是这种情况,请按以下步骤操作:

firstBitmap = BitmapFactory.decodeFile(filePath, o2);

secondBitmap = BitmapFactory.decodeFile(someOtherPath, o2);