2014-02-06 115 views
-1

這是我的活動,我正在接收位圖並製作多個位圖並在一個圖像視圖中顯示 我在圖像視圖中獲取多個圖像但未正確設置請幫助我?無法在一個圖像視圖中設置多個位圖

 private Bitmap Final_Murge_Bitmap() 
     { 
     Murge_Bitmap = null; 
     try { 

     Murge_Bitmap = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888); 
     Canvas c = new Canvas(Murge_Bitmap); 
     c.drawBitmap(Murge_Bitmap, 0, 0, null); 
     Drawable drawable1 = new BitmapDrawable(Bitmap_recieve); 
     Drawable drawable2 = new BitmapDrawable(Bitmap_recieve); 
     Drawable drawable3 = new BitmapDrawable(Bitmap_recieve); 
     Drawable drawable4 = new BitmapDrawable(Bitmap_recieve); 
     Drawable drawable5 = new BitmapDrawable(Bitmap_recieve); 
     Drawable drawable6 = new BitmapDrawable(Bitmap_recieve); 
     Drawable drawable7 = new BitmapDrawable(Bitmap_recieve); 
     Drawable drawable8 = new BitmapDrawable(Bitmap_recieve); 

     drawable1.setBounds(220, 220, 501, 501); 
     drawable2.setBounds(330, 330, 400, 400); 
     drawable3.setBounds(160, 150, 200, 200); 
     drawable4.setBounds(140, 120, 200, 200); 
     drawable5.setBounds(120, 100, 400, 400); 
     drawable6.setBounds(100, 80, 500, 500); 
     drawable7.setBounds(80, 70, 200, 200); 
     drawable8.setBounds(60, 60, 200, 200); 

     drawable1.draw(c); 
     drawable2.draw(c); 
     drawable3.draw(c); 
     drawable4.draw(c); 
     drawable5.draw(c); 
     drawable6.draw(c); 
     drawable7.draw(c); 
     drawable8.draw(c); 

    } catch (Exception e) 
    { 
    } 
    return Murge_Bitmap; 
    }} 
+0

你想達到什麼目的? – pskink

+0

我想設置像gridview –

+0

順序格式的位圖爲什麼不使用GridView? –

回答

1

你可以做類似如下:

public Bitmap drawMultipleBitmapsOnImageView(Bitmap b) { 
     Bitmap drawnBitmap = null; 

     try { 
      drawnBitmap = Bitmap.createBitmap(400, 400, Config.ARGB_8888); 

      Canvas canvas = new Canvas(drawnBitmap); 
        // JUST CHANGE TO DIFFERENT Bitmaps and coordinates . 
      canvas.drawBitmap(b, 100, 100, null); 
      canvas.drawBitmap(b, 200, 300, null); 
      canvas.drawBitmap(b, 100, 200, null); 
      canvas.drawBitmap(b, 300, 350, null); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return drawnBitmap; 
    } 

調用此方法如下所示:

ImageView myImageView = (ImageView) findViewById(R.id.myImageView); 
     Bitmap bitmap = ((BitmapDrawable) myImageView.getDrawable()) 
       .getBitmap(); 
     Bitmap b = drawMultipleBitmapsOnImageView(bitmap); 

     myImageView.setImageBitmap(b); 

,並請給我一些反饋。

希望有所幫助。

+0

感謝它的幫助.. –

+0

它不工作?或不是你想要的? –

+0

它的工作,我需要縮放圖像和保存,但有一些問題在縮放我需要縮放圖像的代碼和設置在另一個圖像上實際上我的照片編輯器應用程序可以請你給我完整的照片編輯器的源代碼 –

0

您可以繪製一切,就像它已經說過的一樣,或者您可以使用這些BitmapDrawable創建一個LayerDrawable。它更容易,消耗更少的內存,所以如果你能用這個來達到你想要的,那就去做吧。

private LayerDrawable createLayerDrawable() { 
     Drawable layers = new Drawable[4]; 
     layers[0] = murge_drawable; // converted from Murge_Bitmap 
     layers[1] = drawable1; 
     layers[2] = drawable2; 
     layers[3] = drawable3; 
     // ... 
     return new LayerDrawable(layers); 
} 

imageview.setImageDrawable(getLayerDrawable()); 
相關問題