2

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. 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

Community
  • 1
  • 1
mrYogi
  • 992
  • 2
  • 9
  • 29

2 Answers2

0

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); 
Kosh
  • 6,140
  • 3
  • 36
  • 67
  • thanks for quick reply,but is there any way to capture screenshot with camera running in background? – mrYogi Feb 09 '13 at 13:00
  • ah just remembered something. just pass your saving method on protected void onPause() { super.onPause(); save(); } now when your app is in the background it will keep executing the saving method! – Kosh Feb 09 '13 at 13:21
  • you got me wrong,by "in background" i mean cameraview in background and transparent view on top of that,taking screenshot in such condition. – mrYogi Feb 11 '13 at 08:56
  • owh in this case i guess you to need to FrameLayout to accomplish this. just overlay the two layouts together , and if you have separate layouts then just in your mainlayout . add framelayout consist of and in you can resize the width and height of it to put it in anywhere in your mainlayout. or just simply put the height and width as fill_parent it will overlay the mainlayout and you still can see the mainlayout. if you can't see it , then add in the framelayout , android:alpha="0.4" and it will be transparent. hope that give u an idea. – Kosh Feb 12 '13 at 09:14
  • i run camera in previous activity and transparent webview in transparent activity in second activity.. all goes well but i get only one view at a time either cameraframe or webview ,is there any way to capture screenshot as it shon on device screen(transparent webview and cameraview beneath it). – mrYogi Feb 13 '13 at 09:31
0

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!

Kosh
  • 6,140
  • 3
  • 36
  • 67