【问题标题】:how to change image file name in android studio?如何在android studio中更改图像文件名?
【发布时间】:2018-11-20 18:45:55
【问题描述】:

我正在从 URL 下载图像并显示在图像视图上,但问题是如果图像名称以数字开头,则无法显示。

private class DownloadFilesTask extends AsyncTask<String, Void, Bitmap> {
    protected Bitmap doInBackground(String... urls) {

        try {

            URL url = new URL(urls[0]);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);
            return myBitmap;

        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    protected void onProgressUpdate(Integer... progress) {

    }

    protected void onPostExecute(Bitmap result) {
        //loading.dismiss();

        String image_name = result.toString();
        if( Character.isDigit(image_name.charAt(0))){

        }
        imageView.setImageBitmap(result);
        imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    }
}

【问题讨论】:

  • 先显示你的代码然后给你解决方案。
  • 只有你的代码才能告诉问题的实际解决方案
  • 我已经编辑了这个问题。代码已添加
  • 我想更改此代码块内的图像名称。 if( Character.isDigit(image_name.charAt(0))){ }
  • 它不应该依赖于图像名称。问题可能出在其他地方

标签: java android image bitmap


【解决方案1】:

由于提供的代码不清楚,所以这可能会对您有所帮助。 使用 PicassoUniversal Image Loader 在 ImageView 上加载 Image 或将位图保存到 sdCard 然后加载它 见https://stackoverflow.com/a/34629526/5057663

【讨论】:

  • 这可能应该是评论,而不是答案,因为它实际上不回答问题,但仍然有用
  • @VladyslavMatviienko 支持您的评论,您绝对正确。但他不能发表评论,因为他只有 15 次代表。他需要至少 50 次发表评论 :)
猜你喜欢
  • 1970-01-01
  • 2015-04-10
  • 2020-09-30
  • 2011-08-30
  • 2014-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多