简体   繁体   English

拍摄屏幕快照相机视图+布局视图android增强现实

[英]taking screenshot camera view+layout view android augmented reality

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

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. 但是我想用相机视图捕获布局视图,因为我也在布局视图或透明网页的背景中使用cameraview。 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 提前致谢

in order to put two images together you may like to follow this code its working 100% to overlay two images together 为了将两个图像放在一起,您可能希望遵循此代码以其100%的效果将两个图像叠加在一起

 Bitmap border = BitmapFactory.decodeResource(getResources(), R.drawable.vignette2);
int width = bmp.getWidth();
int height = bmp.getHeight();
change = Bitmap.createScaledBitmap(change, width, height, false); // change is Bitmap
Canvas canvas = new Canvas(change);
Bitmap scaledBorder = Bitmap.createScaledBitmap(border,width,height, false);
canvas.drawBitmap(scaledBorder, 0, 0,null);
//canvas.drawBitmap(k, 0, 0, null);
view.setImageBitmap(change); // view is the imageView

now part to save the view , the easy way is to 现在是保存视图的一部分,简单的方法是

view.setDrawingCacheEnabled(true);
        view.buildDrawingCache();
        save = view.getDrawingCache(); // save is a Bitmap

and then : 接着 :

                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();

this will save you the view of the imageview , or if its Layout then just set your layout and give it a name and then replace it with view and please do not forget after u check whether the saving succeed or not to set 这将为您保存imageview的视图,或者如果它的Layout只是设置您的布局并给它命名,然后用view替换它,请在您检查保存是否成功设置后不要忘记

        view.setDrawingCacheEnabled(false); 

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. 我无法将代码发布为注释,因此您可以在onActivtity上传递该特定方法,或者在您发送意图或自定义摄像头后传递它,然后可以在单击“摄像头”按钮时进行控制只需添加一种方法即可捕获视图。 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);
}

in order for you to save the view continually then just add loop . 为了让您连续保存视图,只需添加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! 它将随机生成每个图像的名称!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android中的增强现实,可在Camera View上定位地图叠加层 - Augmented reality in Android for Positioning Map Overlays on Camera View 增强现实,摄像机视图上的经度和纬度投影 - Augmented reality, projection of longitude and latitude on camera view 如何在Android中使用增强现实识别在相机视图中显示的对象的位置 - How to identify the location of the object shown in Camera view using Augmented Reality in Android Android相机功能:增强现实 - Android camera feature: Augmented reality 具有摄像头输入和基本点的Android增强现实 - Android Augmented Reality with camera input and a cardinal point Android:截取视图的截图,保存图像并检索它 - Android: Taking screenshot of a View, Saving the image and retrieving it Android:为ScrollView中的所有视图获取ScreenShot - Android: Taking a ScreenShot for all view in ScrollView 此 android 应用程序屏幕截图中使用了哪个布局或视图 - which layout or view is used in this android application screenshot Android,增强现实:在相机上添加带有相框的花朵图像 - Android, Augmented Reality: Adding a flower image with Picture frame on camera 帮助Android增强现实 - Help with android augmented reality
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM