我正在使用 UrlImageViewHelper 库,它工作正常。它将图像缓存在内部存储中,这对我很不利,因为我有很多图像,如果我想缓存它们,那就太可怕了。如何保存这些下载的文件并将它们存储在 SD 卡而不是内部存储中?
问问题
379 次
2 回答
1
请通过浏览器检查您的网址是否有效。如果图像尺寸很大,请使用仍显示您的 URL 的占位符图像,而不是加载可用的图像,如下所示:
UrlImageViewHelper.setUrlDrawable(imageView, "http://example.com/image.png", R.drawable.placeholder);
于 2014-06-04T05:06:06.677 回答
0
使用这个类
public class DemoHelper {
private static final String TAG = DemoMainActivity.TAG;
public static class RemoteImageTask extends AsyncTask<Void, Void, Bitmap> {
ImageView _image;
String _imageSource;
TaskCallback _callback;
public RemoteImageTask(ImageView image, String imageSource) {
this(image, imageSource, null);
}
public RemoteImageTask(ImageView image, String imageSource, TaskCallback callback) {
_image = image;
_imageSource = imageSource;
_callback = callback;
}
protected Bitmap doInBackground(Void... params) {
URL url;
Bitmap bmp = null;
try {
url = new URL(_imageSource);
bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (Exception ignored) {
Log.e(TAG, "Exception", ignored);
}
return bmp;
}
protected void onPostExecute(Bitmap bmp) {
_image.setImageBitmap(bmp);
if (_callback != null)
_callback.onTaskFinished(bmp);
}
}
public interface TaskCallback {
public void onTaskFinished(final Bitmap bmp);
}
}
于 2014-06-04T04:58:23.780 回答