我试图从网址有效地加载位图,但不知何故最终我得到了空的imageview。如果从资源解码,一切都在工作。
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = decodeSampledBitmapFromStream(in, 200, 200);
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
public static Bitmap decodeSampledBitmapFromStream(InputStream in, int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(in, null, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeStream(in, null, options);
}