[英]How to download an image from Json and store it in gallery?
I need to parse an image from some Json and STORE it on phone gallery . 我需要解析一些Json的图像并将其存储在手机库中。 I have no idea how to save pictures on SD card so I need a code for this thanks .
我不知道如何将图片保存在SD卡上,因此我需要一个代码以表示感谢。
Try this.. realy help you 试试这个..真的可以帮助您
public class ImageDownloadTask extends AsyncTask { 公共类ImageDownloadTask扩展了AsyncTask {
CustomProgressBar progressDialog;
Bitmap bitmap;
Drawable drawable;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
progressDialog = CustomProgressBar.show(UpdateActivity.this,
"Loading...", true, true);
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
URL url;
InputStream in;
BufferedInputStream buffIn;
try {
url = new URL(imageUrl);
in = url.openStream();
buffIn = new BufferedInputStream(in);
bitmap = BitmapFactory.decodeStream(buffIn);
drawable = new BitmapDrawable(bitmap);
} catch (Exception e) {
// TODO: handle exception
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (bitmap != null)
imageViewPhoto.setBackgroundDrawable(drawable);
else
imageViewPhoto
.setBackgroundResource(R.drawable.img_default_photo);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.