Android : Capture Screen image in android on canvas not working

on Wednesday, December 10, 2014


I want to capture image of hole screen.I my application i have a view where user can draw some lines and rectangle on it and after that on a button click event i want to capture hole screen including drawing content but when i try then image is captured but it contain only xml design and not what i draw on canvas. I have a class class DrawingSurface extends SurfaceView implements SurfaceHolder.Callback in which i have code for drawing.


inside my fragment i have added this view to my frame layout-



mLayout = (RelativeLayout) view.findViewById(R.id.center_view);


drawingSurface = new DrawingSurface(mContext,conner1,conner2,conner3,conner4,myJob,mLayout); frame = (FrameLayout) view.findViewById(R.id.surface); frame.addView(drawingSurface);


and code for capture screen is -



private static OnClickListener SaveListener = new OnClickListener() {
@Override
public void onClick(View v) {
///// DrawingSurface dc = new DrawingSurface(mContext);
// dc.createFile();
mLayout.getRootView();
mLayout.setDrawingCacheEnabled(true);
mLayout.buildDrawingCache(true);
mLayout.post(new Runnable() {

@Override
public void run() {
Bitmap bitmap = mLayout.getDrawingCache();
Bitmap myBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), (int)(bitmap.getHeight()/1.0));
mLayout.setDrawingCacheEnabled(false);
try {
saveImage(myBitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
};


and below is screen shot that is captured by code - enter image description here


and only xml view is captured and not what i have draw on it.How to do that.


Thanks in advance.


0 comments:

Post a Comment