New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save a Bitmap as a Byte array or image File #6
Comments
If you wish to have the bitmap on the heap (Java world) you are limited to the size of the heap. However, if it's ok with you to have the content on the JNI world (C/C++), you can pass the data using one of the next techniques :
In case you wish to encode the bitmap to a file, sadly this is something that Android also has on the native code, which I didn't do the needed research. I really wish I could do the decoding&encoding on the JNI world, and have the Java world only as something to view the content. If you research this and find the answers, please let me know. BTW, about the quality loss of encoding images to files, JPEG is considered lossy format, which will always lose quality (even if you don't notice it). |
You're right. I increased the size of the heap, and some devices throws an OutOfMemoryException. I've little experience with native development, so I don't know how get a byte array on JNI world. BitmapRegionDecoder helped me, and the only choice was to compress the image in JPEG. I appreciate the help you gave me, so far I top my target off. |
You could save on memory using the next tip too: |
Hi guys . I need to save 2 bitmaps into just one Image file and show them in the file , please if any onw know how i can do it help me . more description here : http://stackoverflow.com/questions/39028509/android-save-2-bitmap-into-just-one-image-file?noredirect=1#comment65421469_39028509 |
@ali1995reza First, you should create a new thread. |
But i never got solution . I have a big view over than 10000×10000 pixels and i want to save it to an Image file . I must create bitmap from part of this and then save dat ! Because of this size i never cant create a bitmap for entire of view . Hoe i can do it ? |
OK, I answered there. Please avoid writing in existing threads. |
Your algorithm helps me a lot saving memory in my app, Thank you; I used your algorithm like this:
Now, the next step is save this bitmap without lose quality. I'll try this:
The algorithm works fine, but this is too slow when the bitmap is compressing in PNG or WEBP. JPEG with 100 quality it's faster, anyway, the bitmap will lost quality. I'll try this too
This solution have problems with big bitmaps, i.e. 5312 x 2988. When the buffer is allocating the bytes throws an OutOfMemoryException. And I can't resize the picture; I must rotate the picture without resize or lost quality.
So, Is there a form to get a byte array from your native library? Or Could you help me how I can save the bitmap as a File, avoiding memory exceptions?
I'll be very grateful if you can solve my problem
The text was updated successfully, but these errors were encountered: