【问题标题】:How to download an image from Json and store it in gallery?如何从 Json 下载图像并将其存储在图库中?
【发布时间】:2014-07-20 22:00:36
【问题描述】:

我需要解析来自某个 Json 的图像并将其存储在手机图库中。我不知道如何在 SD 卡上保存图片,所以我需要一个代码 谢谢。

【问题讨论】:

  • 这是一个完全不清楚的问题。好吧,这实际上是一个问题吗?它与 MySQL Workbench 完全无关。更新您的问题文本以包含更多信息、您已经完成的工作以及您遇到的问题。编辑标签为您的问题提供一些上下文(编程语言、手机操作系统等)。否则问题将被关闭。
  • 是的,这是一个问题!

标签: android android-json android-json-rpc


【解决方案1】:

试试这个..真的对你有帮助

公共类 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);
    }
} 

【讨论】:

    猜你喜欢
    • 2021-06-24
    • 2018-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 1970-01-01
    • 2019-05-25
    相关资源
    最近更新 更多