Android pinch zoom large image, memory efficient without losing detail

时间秒杀一切 提交于 2019-12-03 06:07:12

Sorry to answer an old question, but I've just completed an image view that shows an image from assets or external storage with subsampling, and loads higher resolution tiles from the image as you pinch to zoom in. As high resolution image data for areas of the screen is not loaded it should avoid out of memory exceptions.

https://github.com/davemorrissey/subsampling-scale-image-view

I know the question was asked a long time ago but this answer might help other people struggling with this. I had exactly the same issue. You should consider using WebView and load your image with it, even if it is a local image. For instance to load an image in assets use the following:

// Get a WebView you have defined in your XML layout    
WebView webView = (WebView) findViewById(R.id.webView1);  
// Fetch the picture in your folders using HTML             
String htmlData = "<img src=\"my_image.png\">";
webView.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "utf-8", null);
// Activate zooming
webView.getSettings().setBuiltInZoomControls(true);

I admit that it is very strange to use WebView for such a task, it is the only solution I found. At least you will never get an OOM exception.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!