问题
I have checked out many discussions on stackoverflow & other forums about programatically taking a screenshot of a surfaceview in android like the one below.
Taking screen shot of a SurfaceView in android
But, we'r facing a unique problem as it looks. We are drawing a line on a canvas of a surfaceview using the api canvas.drawline(). But when we use the example code provided in the numerous to take a screenshot of the surfaceview then the line is missing on the screen capture. The line drawn on the canvas is required as a part of the screen capture.
Basically, we are enabling the cache, building the cache & get the cache of the view like in the below link.
www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&ved=0CD0QFjAC&url=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F12724237%2Ftaking-screen-shot-of-a-surfaceview-in-android&ei=Xy0SUv3oOpDNrQfDmIHoAQ&usg=AFQjCNFNQA8PinYhqSA9z-Nt44kqzTtT-A&sig2=Kcvzw5j3wKXliC0EzzLd9Q&bvm=bv.50768961,d.bmk&cad=rja
Is it not correct. Can anyone kindly suggest? Thanks in advance.
回答1:
try to set drawingCacheEnabled(false) - this method works for me:
/**
* returns the given view as a bitmap
* @param view
* @param viewWidth
* @param viewHeight
* @return
*/
public static Bitmap getBitmapFromView(View view) {
Log.debug(LOG_SOURCE, "getBitmapFromView: "+view.getWidth()+" x "+view.getHeight());
if (view.getWidth() == 0 || view.getHeight() == 0)
return null;
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.setDrawingCacheEnabled(false);
view.measure(view.getWidth(), view.getHeight());
view.layout(0, 0, view.getWidth(), view.getHeight());
view.draw(canvas);
canvas = null;
return bitmap;
}
来源:https://stackoverflow.com/questions/18316861/surfaceview-screenshot-with-line-ellipse-drawn-over-it