Skip to content Skip to sidebar Skip to footer

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().t

Solution 1:

in order to put two images together you may like to follow this code its working 100% to overlay two images together

 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

        view.setDrawingCacheEnabled(false); 

Solution 2:

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

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!


Post a Comment for "Taking Screenshot Camera View+layout View Android Augmented Reality"