2015-12-25 54 views
0

我想繪製類似這樣的東西,但它不顯示位圖2.只顯示位圖1(較大的一個)。在ImageView的在較大的位圖上繪製一個小的位圖

imageView1 = (ImageView) findViewById(R.id.imageView1); 
imageView1.setImageBitmap(drawUsingBitmap()); 

Example

//bitmap1 and bitmap2 already initialized 
Bitmap resultBitmap = Bitmap.createBitmap(cubemap.getWidth(), cubemap.getHeight(), cubemap.getConfig()); 
Canvas canvas = new Canvas(resultBitmap); 
canvas.drawBitmap(bitmap1, new Matrix(), null); 
canvas.drawBitmap(bitmap2, (bitmap1.getWidth() - bitmap2.getWidth())/3, (bitmap1.getHeight()) , new Paint()); 
return resultBitmap;  
+0

你的代碼輸出是什麼? –

+0

它只顯示** bitmap1 **(放大圖像)。 –

回答

0

組圖像使用位圖

public Bitmap drawUsingBitmap() { 
     bitmapLarge = BitmapFactory.decodeResource(getResources(), R.drawable.bitmap_large); 
     bitmapSmall = BitmapFactory.decodeResource(getResources(), R.drawable.bitmap_small); 
     Bitmap resultBitmap = Bitmap.createBitmap(bitmapLarge.getWidth(), bitmapSmall.getHeight() + bitmapLarge.getHeight(), Config.ARGB_8888); 
     Canvas canvas = new Canvas(resultBitmap); 
     // using bitmap 
     Paint paint = new Paint(); 
     paint.setColor(Color.BLACK); 
     canvas.drawBitmap(bitmapSmall, bitmapSmall.getWidth()/2, 0, paint); 
     canvas.drawBitmap(bitmapLarge, 0, bitmapSmall.getHeight() - 10, paint); 
     return resultBitmap; 
    } 

使用的drawRect

public Bitmap draWUsingRect() { 
     // using rectangle 
     int widthSmall = 120; 
     int heightSmall = 80; 
     int widthLarge = 400; 
     int heightLarge = 300; 
     Bitmap resultBitmap = Bitmap.createBitmap(widthLarge + 20, heightSmall + heightLarge + 20, Config.ARGB_8888); 
     Canvas canvas = new Canvas(resultBitmap); 
     Paint paint = new Paint(); 
     paint.setColor(Color.BLACK); 
     paint.setStyle(Style.STROKE); 
     paint.setStrokeWidth(5); 
     canvas.drawRect(new Rect(widthSmall/2, 0, widthSmall, heightSmall), paint); 
     canvas.drawRect(new Rect(0, heightSmall, widthLarge, heightSmall + heightLarge), paint); 
     return resultBitmap; 
    } 

我希望這對你有幫助。

+0

對不起,延遲迴復。只需檢查代碼,它就像魅力一樣。 謝謝,先生! –

+0

@Danish Ahmad不用客氣 –