2014-04-04 67 views
0

我需要知道是否需要設置兩個位圖來顯示兩個ImageView中的圖像。我正在上傳圖庫中的圖片。我們是否需要兩個不同的ImageViews的位圖

代碼: -

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


    } 
+0

是什麼問題?你問是否可以將一個圖像資源分配給多個ImageView? –

+0

@fremmedehenvendelser不,我將不同的圖像資源分配給2個不同的圖像視圖。他們將使用2個不同的按鈕上傳。 – user3492898

+0

您正在爲兩個不同的imageView設置相同的位圖。 – Lunchbox

回答

0

雖然這個問題不是很清楚,從閱讀我明白,你可能會想不同的位圖設置爲兩個ImageViews的意見。如果是這樣,這裏是你如何做到這一點:

firstBitmap = BitmapFactory.decodeFile(filePath, o2); 

secondBitmap = BitmapFactory.decodeFile(someOtherPath, o2); 
相關問題