Skip to content

2.3 Save content

Oscar Gilberto Medina Cruz edited this page May 6, 2017 · 5 revisions

Save current drawing

For save the current drawing you have 2 options for response:

// For returning a bitmap as response
DrawingCapture.BITMAP

// For returning a byte array as response
DrawingCapture.BYTES

This is used as paramether in DrawView method

mDrawView.createCapture(DrawingCapture.BITMAP)

This will return an Object array with the image (in bitmap or bytes format) in the position 0 and a image format (JPG, PNG) in the position 1. The format is automatically calculated, depending if you have a solid background or transparent one.

And you can do wathever you want with the response. In my case, I used in a custom dialog for save the bitmap in device.

SaveBitmapDialog saveBitmapDialog = SaveBitmapDialog.newInstance();
Object[] createCaptureResponse = mDrawView.createCapture(DrawingCapture.BITMAP);
saveBitmapDialog.setPreviewBitmap((Bitmap) createCaptureResponse[0]);
saveBitmapDialog.setPreviewFormat(String.valueOf(createCaptureResponse[1]));
saveBitmapDialog.setOnSaveBitmapListener(new SaveBitmapDialog.OnSaveBitmapListener() {
    @Override
    public void onSaveBitmapCompleted() {
        Snackbar.make(mFabActions, "Capture saved succesfully!", 2000).show();
    }

    @Override
    public void onSaveBitmapCanceled() {
        Snackbar.make(mFabActions, "Capture saved canceled.", 2000).show();
    }
});
saveBitmapDialog.show(getSupportFragmentManager(), "saveBitmap");

Save current drawing with DrawCameraView

If you are using DrawCameraView, you need to send it as an extra parameter to DrawView.

mDrawView.createCapture(DrawingCapture.BITMAP, mDrawCameraView.getCameraView());

Dialog example