2011-08-08 3 views
1

BitmapFactory을 사용하여 파일에서 JPG를 디코딩 한 다음 의 imageBitmap을 설정했습니다. 때때로, 응용 프로그램은 내가 사용하려고했습니다 "java.lang.OutOfMemoryError: bitmap size exceeds VM budget"java.lang.OutOfMemoryError : 비트 맵 크기가 VM 예산을 초과합니다.

와 충돌 :

BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inSampleSize = 2; 
Bitmap bm = BitmapFactory.decodeFile(filepath, options); 

그것은하지만 더 이상, 잠시 동안 작동하는 것 같았다. 내가 무엇을 할 수 있을지?

+0

이미지 해상도는 무엇입니까? – MobileCushion

답변

1

이 응용 프로그램에 할당 할 수있는 메모리 양에 모자가있다, 그것은 32 MB의 주위 16메가바이트 수 있습니다. (개까지 안드로이드 버전) 비트 맵에 필요한 2 메가 픽셀, 메모리에 대한

는 2 * 4 = 8 M.

메모리 소비를 줄이기 위해, 당신은 이미지 해상도를 낮출 필요가있을 것이다. WVGA, 800 × 480은

Shash

+0

그래서 지금은 Camera.Parameters가 setJpegQuality (100)로 설정되어 있습니다. 나는 그것을 바꿀 필요가 있다고 생각하니? – LuxuryMode

+1

비틀기 이미지 해상도 – Shash316

+0

감사합니다. 어떻게해야합니까? – LuxuryMode

0

사용하는 이미지의 수를 줄이거 나 캐시하고 캐시하는 경우 필요한 최소 크기로 저장하십시오.

감사 스테판 안드로이드에서

+0

어떻게 그들을 특정 크기로 저장합니까? – LuxuryMode

+0

크기를 조정하는 방법은 다음과 같습니다. http://www.anddev.org/resize_and_rotate_image_-_example-t621.html – Snicolas

0

시작하는 그리고이 이미지 파일을 캐시 할 수있는 코드를 말한다. 캐시 이미지

protected static Map<String, Drawable> cacheThumbs = new HashMap<String, Drawable>(); 

은 // 코드

   if(thumbUri.length() == 0) 
        return; 
       Drawable d = cacheThumbs.get(thumbUri); 
       if(d == null) 
       { 
        String fileName = movie.getId()+"_"+thumbUri.substring(thumbUri.lastIndexOf('/')+1); 
        cacheFile = new File(application.getCacheDir(), fileName); 
        if(!cacheFile.exists()) 
        { 
         //Log.v(LOG_TAG,"Fetching "+thumbUri +" and caching in "+cacheFile.getAbsolutePath()); 
         InputStream bis = (InputStream) new URL(thumbUri).getContent(); 
         BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(cacheFile)); 
         int read = 0; 
         while((read = bis.read(buffer)) != -1) 
          bos.write(buffer, 0, read); 
         bis.close(); 
         bos.close();       
         Log.v(LOG_TAG,thumbUri + " fetched"); 
        }//if 
        Log.v(LOG_TAG,thumbUri + " in cache"); 
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(cacheFile), 9000); 
        d = Drawable.createFromStream(bis, "src name"); 
        bis.close(); 
        cacheThumbs.put(thumbUri, d); 

감사합니다, 스테판

0

나는이 토론에 다른보기를 추가하고 싶습니다. 나는 많은 스레드와 제안을 읽었으며 단일 이미지를 표시하는 WebView로 끝났습니다. 하나의 이미지만을위한 갤러리는 아닙니다.

웹 및 로컬 이미지에서로드하는 이미지에도 적용됩니다.이 옵션은 완벽하게 작동하며 옵션별로 확대/축소 가능합니다. 다음은 작은 예입니다.

WebView webView = (WebView) findViewById(R.id.your_webview); 

String html = "<html><head><title>A title</title></head><body bgcolor=\"#000000\"><img src=\"" + url + "\"></body></html>"; 

WebSettings webSettings = webView.getSettings(); 
webSettings.setBuiltInZoomControls(true); 
webSettings.setLoadWithOverviewMode(true); 
webSettings.setSupportZoom(true); 
webSettings.setUseWideViewPort(true); 

webView.setScrollbarFadingEnabled(true); 
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); 
webView.loadDataWithBaseURL("fake://fake.com", html, "text/html", "UTF-8", null); 
관련 문제