我想从 URL 获取位图,我的代码是:
public Bitmap getBitmapFromUrl(String src) {
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
//testBitMap = myBitmap;
Log.d("myLogs", "return Bitmap");
return myBitmap;
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
return null;
}
}
但是,当我将 url 与西里尔字母放在一起时无法获得位图时,http://cl228041.tmweb.ru/sites/default/files/бмв_0.jpg
我尝试:
URLEncoder.encode(yourString, HTTP.UTF-8);
但它不起作用。