Surfaceview 屏幕截图,上面绘制了线条/椭圆 [英] Surfaceview screenshot with line/ellipse drawn over it

查看:70
本文介绍了Surfaceview 屏幕截图,上面绘制了线条/椭圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查阅了很多关于 stackoverflow & 的讨论.其他有关以编程方式在 android 中截取表面视图的屏幕截图的其他论坛,如下所示.

I have checked out many discussions on stackoverflow & other forums about programatically taking a screenshot of a surfaceview in android like the one below.

在android中截取SurfaceView的屏幕截图

但是,从表面上看,我们面临着一个独特的问题.我们正在使用 api canvas.drawline() 在表面视图的画布上画一条线.但是当我们使用大量提供的示例代码截取表面视图的屏幕截图时,屏幕截图中缺少该行.画布上绘制的线条需要作为屏幕截图的一部分.

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-屏幕截图对的一-surfaceview功能于机器人&安培; EI = Xy0SUv3oOpDNrQfDmIHoAQ&安培; USG = AFQjCNFNQA8PinYhqSA9z-Nt44kqzTtT-A和SIG2 = Kcvzw5j3wKXliC0EzzLd9Q&安培; BVM = bv.50768961,d.bmk&安培; CAD=rja

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.

推荐答案

尝试设置drawingCacheEnabled(false) -这种方法对我有用:

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;
}

这篇关于Surfaceview 屏幕截图,上面绘制了线条/椭圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆