2015-07-28 102 views
0

我正在處理圖像合併應用程序我正在使用此代碼。在android中合併兩個位圖

Bitmap.Config config = bm1.getConfig(); 

if (config == null) { 
config = Bitmap.Config.ARGB_8888; 
} 

newBitmap = Bitmap.createBitmap(w, h, config); 

Canvas newCanvas = new Canvas(newBitmap); 

newCanvas.drawBitmap(bm1, 0, 0, null); 

Paint paint = new Paint(); 

paint.setAlpha(128); 

newCanvas.drawBitmap(bm2, 0, 0, paint); 

的合併,但它給我造成像 result 我已經像 image 1image 2

我需要這個結果result_required 這可能嗎?如何 ?我嘗試與阿爾法,但它實現完整的形象。 我嘗試使用alpha,但它適用於完整圖像。

+0

請籤答案在這裏: http://stackoverflow.com/questions/11740362/merge-two-bitmaps-in -android – MarkySmarky

+0

@MarkySmarky謝謝你爲這個鏈接,但這是正常marge圖像看問題的最後一個圖像,我想在縮小圖像點減少阿爾法。 –

回答

0

後,我的朋友找到做這樣 的方式我使用這個功能

private Bitmap ProcessingBitmap() { 
    Bitmap bm1 = null; 
    Bitmap bm2 = null; 
    Bitmap newBitmap = null; 
    try { 
     bm1 = myBitmap; 
     bm2 = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.bc01), bm1.getWidth(), bm1.getHeight(), true); 
     int w; 
     if (bm1.getWidth() >= bm2.getWidth()) { 
      w = bm1.getWidth(); 
     } else { 
      w = bm2.getWidth(); 
     } 
     int h; 
     if (bm1.getHeight() >= bm2.getHeight()) { 
      h = bm1.getHeight(); 
     } else { 
      h = bm2.getHeight(); 
     } 
     Bitmap.Config config = bm1.getConfig(); 
     if (config == null) { 
      config = Bitmap.Config.ARGB_8888; 
     } 
     newBitmap = Bitmap.createBitmap(w, h, config); 
     Canvas newCanvas = new Canvas(newBitmap); 

     //define half/half area 
     Rect rect1Half = new Rect(0, 0, ((bm1.getWidth() * 100)/100), 
       bm1.getHeight()); 
     Rect rect2Half = new Rect(((bm2.getWidth() * value)/100) + 1, 
       0, bm2.getWidth(), bm2.getHeight()); 

     newCanvas.drawBitmap(bm1, rect1Half, rect1Half, null); 
     Paint paint = new Paint(); 

     paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)); 
     // paint.setAlpha(valueAlpha); 
     paint.setMaskFilter(new BlurMaskFilter(50, BlurMaskFilter.Blur.NORMAL)); 


     newCanvas.drawBitmap(bm2, rect2Half, rect2Half, paint); 

    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    image.setImageBitmap(newBitmap); 
    return newBitmap; 
} 

paint.setXfermode(新PorterDuffXfermode(PorterDuff.Mode.SRC)); paint.setMaskFilter(new BlurMaskFilter(50,BlurMaskFilter.Blur.NORMAL));

是與半徑模糊maskfilter主代碼50