这是我为从 url 获取图像到位图而编写的方法,每当我使用 Handler
public void setimage(final ImageView imageview, final String urll,final int postion)
{
new Thread(new Runnable()
{
@Override
public void run()
{
URL url = null;
try {
url = new URL(urll);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
final Bitmap myBitmap = BitmapFactory.decodeStream(input);
handler.post(new Runnable()
{
@Override
public void run() {
imageview.setImageBitmap(Bitmap.createScaledBitmap(myBitmap, 160, 140, true));
}
});
web.get(postion).setImage(myBitmap);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}).start();
}
每当我向下滚动以在 logcat
java.lang.OutOfMemoryError android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
请告诉我哪里做错了
最佳答案
您可以使用
请求使用更多android:largeHeap="true"
在 list 中。
引用:How to solve java.lang.OutOfMemoryError trouble in Android
关于java - 在android中将图像url转换为位图时如何解决java.lang.OutOfMemoryError异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28494921/