0

我试图从 url 有效地加载位图,但不知何故最终我得到了空的 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);
}
4

0 回答 0