3

I'm currently dealing with really big images (7-10mb) that cannot be resized or compressed for multiple reasons.

Now, the idea is to show them in a custom ImageView that enables the user to do the double-tap zoom, pinch to zoom, etc.

I used this library for the job: https://github.com/MikeOrtiz/TouchImageView

I've tried also other libraries but every other library is still really slow. Can someone give me some pointers/suggestion to make it faster (even writing my own C++ implentation)?

I'm a bit lost with all this "Matrix", "flig", "scale" thing and I have no idea of what I should touch to make it faster. If you know also other faster libraries (or how to use the custom Android implementation, that works really fast) it would be great.

Filnik
  • 352
  • 1
  • 12
  • 33
  • How large are they pixel-wise? Can you upload them to GLES textures? – fadden Aug 24 '15 at 17:05
  • sorry, what is GLES textures? Btw, they are 3680x3288, 6.4MB and cannot be resized or scaled. – Filnik Aug 25 '15 at 09:28
  • On most devices, OpenGL-ES textures can be up to 4096x4096, though some low-end devices might be limited to 2048x2048. GLES can handle the scaling (and rotation, and whatever else you might want to do). Your images might be 6.4MB on disk, but they're 46MB in memory (assuming 32 bits per pixel), because they must be uncompressed before displayed; manipulating that much data in software is not going to be fast, so it's best to let the GPU do it. – fadden Aug 25 '15 at 15:18
  • and how can I do to make the GPU to handle it? – Filnik Aug 25 '15 at 15:26
  • You would need to learn a bit of OpenGL-ES, which comes with a bit of a learning curve. You can find some examples in Grafika (https://github.com/google/grafika), e.g. "texture from camera" shows scaling and rotation of live Camera input. You would need to upload your image to a texture with `glTexImage2D()` and then display it, rather than receiving data from the Camera. You can see an example of that in `TextureUploadActivity#runTextureTest()` (which is an off-screen benchmark); between the two examples I think you have all the pieces you need. – fadden Aug 25 '15 at 15:50

6 Answers6

5

Try a library called openCV or use it in matlab and then port the code into c/c++ for the image enhancement

  • it's not only enhancement, since it's not a "one-shot" zoom.. it's the whole zooming feature connected to gestures, etc. – Filnik Aug 27 '15 at 14:28
3

Have you tried using the DeepZoom feature of the Ion library?

https://github.com/koush/ion

https://www.youtube.com/watch?v=yIMltNEAKZY

If you don't want to to use opengl, or the above library does not work, you can also try playing with the http://developer.android.com/reference/android/graphics/BitmapRegionDecoder.html class. That is, keep track of "where" the user is (the viewport & zoom level) and decode that region off the main thread, pushing it into a canvas each time the user changes the input.

Ashton Engberg
  • 5,949
  • 2
  • 19
  • 14
2

You could try manually implementing "mipmaps" -- different sizes of the same image, and then just use the most appropriately sized image for displaying.... thus when zoomed out, you'll be manipulating a relatively small image (but will still get the full detail of the large one when zoomed in).

Buddy
  • 10,874
  • 5
  • 41
  • 58
  • but it would still be slow with full zoom images, am I right? It's slow moving on the image too, not only the zoom :( – Filnik Aug 25 '15 at 09:26
  • True. I guess you could split the image into smaller tiles and just display those (doing the math to line them up)... – Buddy Aug 25 '15 at 14:02
2

Try a library called PhotoView. When used together with picasso, i was able to achieve Onlick functionality enabling the user to click a smaller image and have it pop up the full image on a custom view complete with zoom functionality..It's really easy to implement

Bmbariah
  • 687
  • 2
  • 10
  • 22
  • thanks but it's too slow this one too. I keep getting: " Skipped 82 frames! The application may be doing too much work on its main thread." Any other idea? :( – Filnik Aug 25 '15 at 09:36
2

One way of solving it is by using a WebView, which has support for panning, pinch-zooming etc. I think that image quality may be an issue though.

android-local-image-in-webview

android-add-image-to-webview-from-a-drawable

etc. You can also generate and load the html dynamically

Community
  • 1
  • 1
reden
  • 968
  • 7
  • 14
  • actually it seems a good idea. Although I can't undersand why on the browser it's just super fast and on the webview it still lags a bit (a lot better than the other solutions though). Any idea? – Filnik Aug 28 '15 at 15:17
  • Sorry, no, can't say why it's slower. – reden Aug 28 '15 at 15:59
0

In TouchImageView.java class DoubleTapZoom set a lower or higher value for ZOOM_TIME

private class DoubleTapZoom implements Runnable {
 ......
 private static final float ZOOM_TIME = 500 //(lower - faster)
 ......
Neo7g
  • 26
  • 2