Android pinch zoom large image, memory efficient without losing detail

后端 未结 2 1317
夕颜
夕颜 2021-02-08 08:58

My app has to display a number of high resolution images (about 1900*2200 px), support pinch zoom. To avoid Out of memory error I plan to decode image to show full screen by usi

2条回答
  •  面向向阳花
    2021-02-08 09:18

    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 = "";
    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.

提交回复
热议问题