0

First, please realize why my question should not be considered as duplicate. I have performed some search, and I still have no answer.

So, I need to rotate large jpeg image. Most important, no downscale allowed. For example, 20 Mpix image should stay 20 Mpix, rotated (90 degree for example). No downscaling, no any quality loss allowed. From obvious reasons, I can't uncompress it to bitmap and perform Matrix rotation, this will result out of memory exception crash.

So, I'm looking for some way (or maybe some library?) to perform image rotation as I need. Do you have any ideas? I can find some apps that able to perform very large images rotation without any problems, so I'm sure it's possible.

Please point me right direction? Anybody? I guess Android api does not contain any api to do that (or I can't find it).

[edit] My app is small, so I don't want any large lib like OpenCV.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
user1209216
  • 7,404
  • 12
  • 60
  • 123
  • The fact that some apps are rotating large images, how you can say there is no quality loss on doing this or that they are not using compression internally? BTW you could try to read the bytes and save them in a different position – MatPag Jan 19 '18 at 07:55
  • Well, maybe I need to be more specific. They may use compression internally, but result is not worse than original, for example 90% jpeg quality with the same resolution (rotated). But how to perform rotation on so large image? Standard way is not possible to use, because it tries to allocate to much memory. – user1209216 Jan 19 '18 at 07:58
  • You could try with something similar https://stackoverflow.com/a/16685272/2910520. Obviously you will need a buffer to read N bytes at a time. – MatPag Jan 19 '18 at 07:59
  • Isn't it the same what is done when I try to use standard api? It will still need very large amount of memory. I will need to allocate `width*height` twice, it's too much – user1209216 Jan 19 '18 at 08:02
  • If you read and write on "disk" (and having only the buffer in memory) you shouldn't have problems. By the way reading and saving so many bytes could be very I/O intensive for a device. I think you still need compression for this. – MatPag Jan 19 '18 at 08:06
  • I guess there must be more smart way to do that, for example, partial processing (buffered) instead of loading entire bitmap to array. But it could be complicated, isn't there any lib (possibly using ndk) to do most complicated job? I have always thought it's rather common problem, so it should be solved somehow? – user1209216 Jan 19 '18 at 08:09
  • You can try using OpenCV. Either the JNI Wrapper or a native implementaiton. https://docs.opencv.org/3.4.0/da/d6e/tutorial_py_geometric_transformations.html – Christopher Jan 19 '18 at 08:16
  • `"for example, partial processing (buffered) instead of [...]"` see `android.graphics.BitmapRegionDecoder` – pskink Jan 19 '18 at 08:18
  • @Christopher - 30 Mb apk size to perform simple image rotation.. – user1209216 Jan 19 '18 at 08:33
  • Please update your question that apk size is an issue for you. – Christopher Jan 19 '18 at 08:36
  • then use `android.graphics.BitmapRegionDecoder` – pskink Jan 19 '18 at 08:41
  • Thanks for suggestion, however it's not still straightforward. Any samples are welcome – user1209216 Jan 19 '18 at 08:52
  • 1
    so what is not clear? basically you need to divide your huge image into sever small `Bitmap`s that can be loaded, rotated and written back to the output image – pskink Jan 19 '18 at 08:56
  • Yes you are right – user1209216 Jan 19 '18 at 08:57

0 Answers0