Skip to content Skip to sidebar Skip to footer

Image Over Other Image Android

How can i set image (semi-trasparent) over other image ? I need to create new bitmap and then save it. Thanks all.

Solution 1:

Bitmapbitmap1=null; // define itBitmapbitmap2=null; // define itBitmapresultBitmap= Bitmap.createBitmap(bitmap1.getWidth(), bitmap1.getHeight(), Bitmap.Config.ARGB_8888);

    Canvasc=newCanvas(resultBitmap);

    c.drawBitmap(bitmap1, 0, 0, null);

    Paintp=newPaint();
    p.setAlpha(127);

    c.drawBitmap(bitmap2, 0, 0, p);

    // Your final bitmap is resultBitmap

Solution 2:

All you need to do is to take the two bitmaps and set their bounds. Then you need to draw them both on the canvas. If you want to set the image as semi-trasparent, you need to set the alpha of the picture.

This is an example:

Bitmapbitmap=null;
    try {

        bitmap = Bitmap.createBitmap(500, 500, Config.ARGB_8888);
        Canvasc=newCanvas(bitmap);
        Resourcesres= getResources();


        Bitmapbitmap1= BitmapFactory.decodeResource(res, R.drawable.test1); //blueBitmapbitmap2= BitmapFactory.decodeResource(res, R.drawable.test2); //greenDrawabledrawable1=newBitmapDrawable(bitmap1);
        Drawabledrawable2=newBitmapDrawable(bitmap2);


        drawable1.setBounds(100, 100, 400, 400);
        drawable2.setBounds(150, 150, 350, 350);
        drawable1.draw(c);
        drawable2.draw(c);


    } catch (Exception e) {
    }
    return bitmap;

}

Solution 3:

Create a canvas object from the bottom layer canvas. Then draw the semi-transparent Bitmap to that canvas. The original Bitmap object will now have the semi-transparent bitmap written on top of it.

Post a Comment for "Image Over Other Image Android"