0

I am working on image Merge application I am use this code.

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

for Merge but it give me result like result i have image image 1 and image 2

i need this result result_required is it possible ? and how ? i am try with alpha but it give effect full image. i am try using alpha but it apply to full image.

Community
  • 1
  • 1
Sagar Devani
  • 242
  • 1
  • 3
  • 10
  • please checkout the answer over here: http://stackoverflow.com/questions/11740362/merge-two-bitmaps-in-android – MarkySmarky Jul 28 '15 at 12:11
  • @MarkySmarky thankyou for this link but this is for normal marge the image see the last image of question i want reduse the alpha at the point of marge image. – Sagar Devani Jul 28 '15 at 12:23

2 Answers2

0

You can use the following:

https://developer.android.com/reference/android/graphics/PorterDuff.Mode.html

Details and results of different modes can be found here:

http://ssp.impulsetrain.com/porterduff.html

Just pick the needed algo and use it on your bitmaps.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
MarkySmarky
  • 1,609
  • 14
  • 17
0

after two day my friend find the way to do like this i am using this function

  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(new PorterDuffXfermode(PorterDuff.Mode.SRC)); paint.setMaskFilter(new BlurMaskFilter(50, BlurMaskFilter.Blur.NORMAL));

is main code for that blur maskfilter with radius 50.

Sagar Devani
  • 242
  • 1
  • 3
  • 10