【问题标题】:do we need two bitmaps for 2 different ImageViews我们是否需要两个位图用于 2 个不同的 ImageView
【发布时间】: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 个图像视图设置不同的位图。

标签: android imageview


【解决方案1】:

虽然问题不是很清楚,但通过阅读 cmets,我了解到您可能希望为两个 ImageView 设置不同的位图。如果是这种情况,您可以这样做:

firstBitmap = BitmapFactory.decodeFile(filePath, o2);

secondBitmap = BitmapFactory.decodeFile(someOtherPath, o2);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-22
    • 2012-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多