我环顾四周,但没有找到解决问题的可靠方法。我的应用程序运行但是当我使用位图围绕活动进行naviagate时,我收到错误," Throwing OutofMemoryError"无法分配8294412字节分配和690632个空闲字节"。我在下面有我的代码片段,用于两个单独的活动。我已经尝试过回收位图,但这也没有成功。
public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.dialogprofile, null);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
Uri myUri = Uri.parse(worldpopulationlist.get(position).getFilename1().toString());
File f = new File(worldpopulationlist.get(position).getFilename1().toString());
Bitmap myImg = BitmapFactory.decodeFile(myUri.getPath());
Matrix matrix = new Matrix();
Bitmap circleBitmap = Bitmap.createBitmap(myImg.getWidth(), myImg.getHeight(), Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader (myImg, TileMode.CLAMP, TileMode.CLAMP);
Paint paint = new Paint();
paint.setShader(shader);
Canvas c = new Canvas(circleBitmap);
c.drawCircle(myImg.getWidth()/2, myImg.getHeight()/2, myImg.getWidth()/2, paint);
int finalHeight, finalWidth;
holder.success.setImageBitmap(circleBitmap);
circleBitmap.recycle();
int width=800;
int height=700;
finalHeight = holder.event.getMeasuredHeight();
finalWidth = holder.event.getMeasuredWidth();
filenamee = worldpopulationlist.get(position).getFilename().toString();
Uri myUr = Uri.parse(worldpopulationlist.get(position).getFilename().toString());
File f1 = new File(worldpopulationlist.get(position).getFilename().toString());
Bitmap myImg1 = BitmapFactory.decodeFile(myUr.getPath());
myImg1=Bitmap.createScaledBitmap(myImg1, width, height, true);
Matrix matrix1 = new Matrix();
holder.event.setImageBitmap(myImg1);
}
});
return View;
}
public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.list_row, null);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
Uri myUri = Uri.parse(worldpopulationlist.get(position).getFilename().toString());
File f = new File(worldpopulationlist.get(position).getFilename().toString());
Bitmap myImg = BitmapFactory.decodeFile(myUri.getPath());
Matrix matrix = new Matrix();
Bitmap rotated = Bitmap.createBitmap(myImg, 0, 0, myImg.getWidth(), myImg.getHeight(),
matrix, true);
holder.flag.setImageBitmap(rotated);
}
});
return View;
}