2

Current i m doing one image editing android app in which i need to take screenshot of one relative layout My code:

  public Bitmap takeScreenshot() {
            Bitmap bitTmp;
            View rootView = findViewById(R.id.rl_img_view);
            rootView.setDrawingCacheEnabled(true);
            bitTmp = rootView.getDrawingCache();
            return bitTmp;
        }

my problem is that when i take screenshot it send me bitmap which contain empty part of layout as black color. Is it possible to get that empty part transparent on output bitmap?

Output i get: http://postimg.org/image/5mxznc6jv

Output i want: http://postimg.org/image/50bre04kf

Rank Mayur
  • 116
  • 2
  • 14
  • try setting the background transparency to the layout before you take screenshot.. not sure but might work. http://stackoverflow.com/questions/23201134/transparent-argb-hex-value/28481374#28481374 – Shivaraj Patil Mar 03 '15 at 08:14

1 Answers1

1

Change the width of the bitmap you are gettting, or maybe add padding from left.

Use this :

Public Bitmap pad(Bitmap Src, int padding_x, int padding_y){
    Bitmap outputimage = Bitmap.createBitmap(Src.getWidth() + padding_x,Src.getHeight() + padding_y, Bitmap.Config.ARGB_8888);
Canvas can = new Canvas(outputimage);
can.drawARGB(FF,FF,FF,FF); //This represents White color
can.drawBitmap(Src, padding_x, padding_y, null);

return outputimage;
}

Refer to this question : Canvas Bitmap

Community
  • 1
  • 1