[英]how to change image file name in android studio?
我正在從URL下載圖像並顯示在imageview上,但問題是,如果圖像名稱以數字開頭,則無法顯示。
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);
}
}
由於提供的代碼不清楚,因此可能會對您有所幫助。 使用Picasso或Universal Image Loader在ImageView上加載圖像或將位圖保存到sdCard,然后加載它,請參見https://stackoverflow.com/a/34629526/5057663
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.