拍摄屏幕快照相机视图+布局视图android增强现实 [英] taking screenshot camera view+layout view android augmented reality

查看:109
本文介绍了拍摄屏幕快照相机视图+布局视图android增强现实的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从帧缓冲区中获取屏幕捕获,它对我的​​布局视图非常有效 我从此处使用了以下代码:

I tried taking screencapture from frame buffer and it works well for my layout views I used the following code from here:

String mPath = Environment.getExternalStorageDirectory().toString() + "/" + ACCUWX.IMAGE_APPEND;   

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

OutputStream fout = null;
imageFile = new File(mPath);

try {
    fout = new FileOutputStream(imageFile);
    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
    fout.flush();
    fout.close();

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

但是我想用相机视图捕获布局视图,因为我也在布局视图或透明网页的背景中使用cameraview. 一种解决方法是分别拍摄相机图像和布局视图,并将它们彼此放置并保存新的位图.

But I want to capture layout view with camera view, since I am using cameraview in background of layout views or transparent webpage as well. One turnaround is to take camera image and layout view separately and put them on each other and save new bitmap.

有人可以建议我对此采取任何适当的解决方案吗? 预先感谢

Can anyone suggest me any proper solution to this? Thanks in advance

推荐答案

我无法将代码发布为注释,所以在这里 您可以在onActivtity上传递该特定方法,还是在您发送其意图或自定义摄像头后传递它,然后可以控制单击相机按钮时添加一个方法来捕获视图即可.这是我保存视图的方法.

i couldn't post the code as comment so here you go will you can pass that specific method on your onActivtity or just pass it after u send the intent , or of its custom camera then you can control that when you click on the camera button just add a method to capture the view. this is my method for saving the view.

void Save() {
    if (null != view.getDrawable()) {
        view.setDrawingCacheEnabled(true);
        view.buildDrawingCache();
        save = view.getDrawingCache();
        final File myDir = new File(folder);
        myDir.mkdirs();
        final Random generator = new Random();
        int n = 10000;
        n = generator.nextInt(n);
        final String fname = "StyleMe-" + n + ".png";
        final File file = new File(myDir, fname);
        if (file.exists())
            file.delete();
        try {
            final FileOutputStream out = new FileOutputStream(file);
            save.compress(Bitmap.CompressFormat.PNG, 100, out);
            out.flush();
            out.close();
            sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                    Uri.parse("file://"
                            + Environment.getExternalStorageDirectory())));
            Toast.makeText(getApplication(), "Image Saved",
                    Toast.LENGTH_SHORT).show();
        } catch (final Exception e) {
            Toast.makeText(getApplication(),
                    "Something Went Wrong check if you have Enough Memory",
                    Toast.LENGTH_LONG).show();
        }
    } else {
        final Toast tst = Toast.makeText(getApplication(),
                "Please Select An Image First", Toast.LENGTH_LONG);
        tst.setGravity(Gravity.CENTER, 0, 0);
        tst.show();
    }
    view.setDrawingCacheEnabled(false);
}

为了让您连续保存视图,然后只需添加loop即可.当您单击相机按钮时,循环开始!在这里,在我的保存方法中,不必担心重叠名称:).它将随机生成每个图像的名称!

in order for you to save the view continually then just add loop . when you click the camera button that loop starts !! and here in my saving method , don't worry about overlaying names :). randomly it will generate the names for each image!

这篇关于拍摄屏幕快照相机视图+布局视图android增强现实的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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