以截屏SurfaceView的机器人 [英] Taking screen shot of a SurfaceView in android

查看:163
本文介绍了以截屏SurfaceView的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的方法来拍摄屏幕快照这是一个SurfaceView特定视图的。

I am using following method to taking screen shot of a particular view which is a SurfaceView.

public void takeScreenShot(View surface_view){

    // create bitmap screen capture
    Bitmap bitmap;
    View v1 = surface_view;
    v1.setDrawingCacheEnabled(true);
    bitmap = Bitmap.createBitmap(v1.getDrawingCache());
    v1.setDrawingCacheEnabled(false);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 0, bos);
    byte[] imageData = bos.toByteArray();

}

问题是它给我的整个活动画面。但我需要截屏的特殊观点。我尝试过其他方法,但那些给我一个黑色的屏幕,屏幕截图,有的帖子说,它需要root权限的设备。 任何一个可以帮我请。我需要这个解决方案。帮助我....

the problem is its giving me the whole activity screen image. But I need to take screen shot of the particular view. I tried other ways but those give me a black screen as screen shot, some posts says that it requires rooted device. Can any one help me please. I'm in need of this solution. Help me....

推荐答案

面视图是一个视图,但是项目像位图或其他物体表面来看没有任何看法。所以,当你捕捉表面来看它会捕捉到表面上的每一件事情。你必须使用另一种观点类似图像视图或其他高于表面视图,然后捕获这些视图。

Surface view is a view but item on surface view like bitmap or other object are not any view. So while you capture surface view it will capture every thing on the surface. You have to use other view like image view or other above the surface view and then capture those view.

首先得要带那么做的图片认为,这

First get the view whose picture want to take then do this

            Bitmap bitmap;
            View rv = **your view**
            rv.setDrawingCacheEnabled(true);
            bitmap = Bitmap.createBitmap(rv.getDrawingCache());
            rv.setDrawingCacheEnabled(false);

            // Write File to internal Storage

            String FILENAME = "captured.png";
            FileOutputStream fos = null;

            try {

                fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);

            } catch (FileNotFoundException e1) {

                e1.printStackTrace();
                Log.v("","FileNotFoundException: "+e1.getMessage());

            }

            try {
                bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
                fos.flush();
                fos.close();

            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 

这篇关于以截屏SurfaceView的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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