안녕하세요 초보개발자입니다..
현재 이미지 사이즈 640x640 이구요.. 크기는 평균 260kb정도입니다..
viewpager로 작업하구있구요 페이지가 넘어갈때마다 이미지를 로딩하게 구현해놨습니다.
이미지 클래스보시죠..
package com.newtalktalk.utils;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.util.HashMap;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.v4.util.LruCache;
import android.util.Log;
import android.widget.ImageView;
public class DownLoadimage extends AsyncTask<String, Void, Bitmap> {
private String mtype="";
public static HashMap<String, Bitmap> mimgdata;
private SoftReference<ImageView> imgreference;
public DownLoadimage(ImageView img, String type) {
// TODO Auto-generated constructor stub
// imgview = img;
imgreference = new SoftReference<ImageView>(img);
mtype = type;
if(mimgdata == null){
mimgdata = new HashMap<String, Bitmap>();
}
}
public void closeLrucache(){
mimgdata.clear();
}
@Override
protected Bitmap doInBackground(String... urls) {
// TODO Auto-generated method stub
String dataurl = urls[0];
Bitmap imgbitmap = null;
try{
if(mimgdata.get(dataurl) == null){
Log.i("--", "NULL");
InputStream in = new URL(dataurl).openStream();
imgbitmap = BitmapFactory.decodeStream(in);
mimgdata.put(dataurl, imgbitmap);
in.close();
}else{
Log.d("--", "not NULL ");
imgbitmap = mimgdata.get(dataurl);
}
}catch (Exception e) {
// TODO: handle exception
Log.d("ErrorLog", "DownLoadimage : = " + e.toString());
}
return imgbitmap;
}
@Override
protected void onPostExecute(Bitmap result) {
// TODO Auto-generated method stub
if(result != null){
if(imgreference != null){
ImageView imgview = imgreference.get();
if(imgview != null){
imgview.setImageBitmap(result);
}
}
}
result = null;
}
}
이렇게 구현했는데요..
한번은 OOM이 나질않는데.. 여러번하게 되면 OOM이 나네요 ㅠㅠ
제가 구현한 저 코드가 잘못된건가요?
다른곳에서 메모리를 줄여야 하는건가요?ㅠㅠ 도와주세요 ㅜㅜ