skip to Main Content

I have a method for screenshot which takes the View from XML and convert to Bitmap object, and I have multiple PNG on layout View. Some PNG have transparent Area which appears as Black color in Bitmap (which i want to change to White) or want to get rid of Black transparent area.

private void takescreenshot(LinearLayout preview) throws IOException
{
    View z  = preview;   // get whole layout view
    z.setDrawingCacheEnabled(true);
    Bitmap bitmap = Bitmap.createBitmap(z.getDrawingCache());
    z.destroyDrawingCache();
}

2

Answers


  1. Chosen as BEST ANSWER

    finally i figure out the solution as well

    View z  = preview;   // get whole layout view
            z.setDrawingCacheEnabled(true);
            Bitmap bitmap = Bitmap.createBitmap(z.getDrawingCache());
            z.destroyDrawingCache();
    
    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(),ARGB_8888);
            newBitmap.eraseColor(Color.WHITE);
            Canvas canvas2 = new Canvas(newBitmap);
            canvas2.drawBitmap(bitmap,0F,0F,null);
    

  2. create a new blank bitmap
    create canvas object
    fill the canvas a background
    put old bitmap in your canvas.

    Bitmap newBitmap = Bitmap.create(bitmap.width,bitmap.height,ARGB_8888)
    Canvas canvas = new Canvas(newBitmap)
    canvas.drawColor(Color.white)
    canvas.drawBitmap(bitmap,0F,0F,null)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search