MotionViews-Android icon indicating copy to clipboard operation
MotionViews-Android copied to clipboard

Save final bitmap

Open dockusan opened this issue 8 years ago • 19 comments

Thank you for great article! But Can you add save button for merge all layer to one bitmap? (with white background)

dockusan avatar Dec 15 '16 03:12 dockusan

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.

hitesh-dhamshaniya avatar Dec 26 '16 11:12 hitesh-dhamshaniya

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.

dockusan avatar Dec 27 '16 02:12 dockusan

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.

hitesh-dhamshaniya avatar Dec 27 '16 05:12 hitesh-dhamshaniya

You can do that. But Image resolution is low, it equals your screen size. You can't export high resolution with this way.

dockusan avatar Dec 27 '16 05:12 dockusan

That's is true, Can you please share code snippets for save high-resolution image.

hitesh-dhamshaniya avatar Dec 27 '16 05:12 hitesh-dhamshaniya

Sorry. I've not write code for export image yet. I will send you when I finished

dockusan avatar Dec 28 '16 03:12 dockusan

The way @dockusan describe it is generally correct, I will write export code and share it later

AndriyBas avatar Jan 05 '17 16:01 AndriyBas

Saving the image in high-res would be awesome :-)

Also, thanks for the project!

rodrigobressan avatar Feb 15 '17 09:02 rodrigobressan

@AndriyBas export high resolution code ?

dingweijie avatar May 10 '17 02:05 dingweijie

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

Skizzotrick avatar May 11 '17 23:05 Skizzotrick

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

mohanishn1234 avatar Jun 06 '17 10:06 mohanishn1234

Hi @AndriyBas is there any progress with high-resolution image export code?

TomasPilar avatar Jun 27 '17 20:06 TomasPilar

@AndriyBas dear any update about code?

chnouman avatar Jul 11 '17 09:07 chnouman

I just found method getThumbnailImage() in MotionView class. This method returns final bitmap with MotionView size.

dockusan avatar Sep 07 '17 02:09 dockusan

@dockusan is that image in good quality or just the screen shot of MotionView size?

chnouman avatar Sep 07 '17 08:09 chnouman

@chnouman Just screenshot, but with screen size 1080x1920, it is good.

dockusan avatar Sep 07 '17 08:09 dockusan

ok @dockusan thanks budy

chnouman avatar Sep 15 '17 14:09 chnouman

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?

mianaliasjad avatar Mar 07 '20 17:03 mianaliasjad

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.

DineshNeupane avatar Jul 14 '21 06:07 DineshNeupane