I have an application that places Stickers on an image for editing purposes. I want to convert this view, which is in a RelativeLayout, to an image, and save it to the device.
I use a library that converts Layouts to images, however, the application or hangs, or shrinks the image by removing the stickers, without saving. Follow the code. I'm a beginner on Android and I do not know if I'm doing things the right way.
if (item.getItemId() == R.id.main_save_croqui) {
Layout_to_Image layout_to_image;
RelativeLayout relativeLayout;
Bitmap bitmap;
relativeLayout=(RelativeLayout)findViewById(R.id.activity_main);
layout_to_image=new Layout_to_Image(MainActivity.this,relativeLayout);
bitmap=layout_to_image.convert_layout();
try {
Date now = new Date();
String nomeImagem = Environment.getExternalStorageState().toString()+"/"+now+".jpg";
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitmapdata = stream.toByteArray();
File img = new File(nomeImagem, "croqui.jpg");
FileOutputStream outputStream = new FileOutputStream(img, false);
outputStream.write(bitmapdata, 0, bitmapdata.length);
outputStream.flush();
outputStream.close();
} catch (Throwable e){
e.printStackTrace();
}