MotionViews-Android
MotionViews-Android copied to clipboard
Save final bitmap
Thank you for great article! But Can you add save button for merge all layer to one bitmap? (with white background)
What great work was done !! Thank you for sharing. Can you please suggest way save final image as a png or any image format, how can I achieve this functionality.
Way to export final bitmap:
- Get size layer parent view.
- Create a bitmap with size parent view (or bigger with a scale ratio) => This is a paper to paint and draw
- We have layer coordinate in parent view, now create new layer size(with new scale ratio) and draw layer object on above canvas.
I have implement below things to save Bitmap in storage, It's work for me
`public void saveFile(MotionView layout, String path) {
layout.setDrawingCacheEnabled(true);
layout.buildDrawingCache();
Bitmap cache = layout.getDrawingCache();
try {
FileOutputStream fileOutputStream = new FileOutputStream(path + "/temp.jpg");
cache.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
} finally {
layout.destroyDrawingCache();
}
}
Let me know if there is any glitches.
You can do that. But Image resolution is low, it equals your screen size. You can't export high resolution with this way.
That's is true, Can you please share code snippets for save high-resolution image.
Sorry. I've not write code for export image yet. I will send you when I finished
The way @dockusan describe it is generally correct, I will write export code and share it later
Saving the image in high-res would be awesome :-)
Also, thanks for the project!
@AndriyBas export high resolution code ?
Hello,
I don't know how efficient the next method is. I have just tried the motionviews today but i can see that some people are looking for a way to get a bitmap from the motionview. Here is a simple solution that worked for me. Ofc, i am going to work on it more but for those who need a solution asap i will just leave it here.
public Bitmap getBitmapFromMV(MotionView motionView)
{
int size_x = motionView.getWidth();
int size_y = motionView.getHeight();
Bitmap.Config conf = Bitmap.Config.ARGB_8888;
Bitmap bmp = Bitmap.createBitmap(size_x, size_y, conf);
Canvas final_cnv = new Canvas(bmp);
List<MotionEntity> mentities = motionView.getEntities();
for(int i = 0; i < mentities.size(); i++)
{
mentities.get(i).draw(final_cnv, new Paint());
}
return bmp;
}
we get the bitmap from frame layout. See the answer on stackoverflow. Credit goes to GhoRiser https://stackoverflow.com/questions/21725916/convert-frame-layout-into-image-and-save-it
public Bitmap viewToBitmap(View view) { Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); view.draw(canvas); return bitmap; }
Hi @AndriyBas is there any progress with high-resolution image export code?
@AndriyBas dear any update about code?
I just found method getThumbnailImage()
in MotionView class. This method returns final bitmap with MotionView size.
@dockusan is that image in good quality or just the screen shot of MotionView size?
@chnouman Just screenshot, but with screen size 1080x1920, it is good.
ok @dockusan thanks budy
Guys i am adding text and emoji over imageView using this library but I don't know how to save that image again in its original quality. I know we can save View but it would be just a screenshot. I want to preserve the quality of my source image after adding text and emoji on it. can anyone help in this matter?
Layer class has getScale and getRotation method. You can grab these two parameters and final position of the sticker and use them with your original bitmap while drawing for the export.