HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStream is = connection.getInputStream();使用HttpURLConnection产生的流只能使用一次
如果你想连续调用这个流 必须重新初始化
例如Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is, null, options);
Boolean scaleByHeight = Math.abs(options.outHeight - TARGET_HEIGHT) >= Math.abs(options.outWidth - TARGET_WIDTH);
if(options.outHeight * options.outWidth * 2 >= 200*200*2){
double sampleSize = scaleByHeight
? options.outHeight / TARGET_HEIGHT
: options.outWidth / TARGET_WIDTH;
options.inSampleSize =
(int)Math.pow(2d, Math.floor(
Math.log(sampleSize)/Math.log(2d)));
}
// Do the actual decoding
options.inJustDecodeBounds = false;
is.close();
is = getHTTPConnectionInputStream(sUrl);
Bitmap img = BitmapFactory.decodeStream(is, null, options);
is.close();
分享到:
相关推荐
因此,改用先通过BitmapFactory.decodeStream方法,创建出一个bitmap,再将其设为ImageView的source,decodeStream最大的秘密在于其直接调用JNI>>nativeDecodeAsset()来完成decode,无需再使用java层的createBitmap...
Android系统中图片一般用Bitmap对象表示,它支持png,jpg等常见格式。通常情况下图片的体积都比较大,单个应用允许使用的内存又是... BitmapFactory.decodeStream :从输入流加载。 BitmapFactory.decodeResource :从
b=(Button)this.findViewById(R.id.b);//图片浏览按钮 et=(EditText)this.findViewById(R.id.et);... bitmap = BitmapFactory.decodeStream(is);//将InputStream变成Bitmap is.close();//关闭InputStream
Bitmap map=BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options); android.provider.MediaStore.Images.Media.insertImage(getContentResolver(), map, null, null); ...
这是博文《BitmapFactory.decodeResource VS BitmapFactory.decodeStream》中的时序图,发现上传后,看不清楚,所以上传在这里。
bm = BitmapFactory.decodeStream(is); /* 关闭InputStream */ is.close(); /* 让ImageView显示图像 */ imtp.setImageBitmap(bm);//显示下载图片 Sample8_12_Activity.this.setWallpaper(bm);//将...
使用setImageResource或BitmapFactory.decodeResource来设置一张大图,因为这些函数在完成decode后,最终都是通过java层的createBitmap来完成的,需要消耗更多内存。解决方案:改用先通过BitmapFactory.decodeStream...
用于类似图库,缓存,所困、... bitmap = BitmapFactory.decodeStream(new FileInputStream(imagePath), null, options); } catch (FileNotFoundException e) { e.printStackTrace(); } return bitmap; } }
如何从网络中获取一张图片,并显示出来?? 首先应想到若要从网络资源中获取图片,就需要通过流操作,于是就想到如何创建流...第四步:利用BitmapFactory.decodeStream()方法直接将图片流解码为bitmap 第五步:送去显示
Bitmap bm = BitmapFactory.decodeStream(getResources() .openRawResource(R.drawable.dog)); // 获得图片的宽高 int width = bm.getWidth(); int height = bm.getHeight(); // 设置想要的大小 int newWidth = 320;...
因此,改用先通过 BitmapFactory.decodeStream 方法,创建出一个 bitmap,再将其设为 ImageView 的 source,decodeStream 最大的秘密在于其直接调用 JNI>>nativeDecodeAsset() 来完成 decode,无需再使用 Java
代码如下: private void loadImage() { mImageView = (ImageView) findViewById(R.id.... mImageView.setImageBitmap(BitmapFactory.decodeStream(url.openStream())); } catch (Exception e) { } } 您可能感兴趣的文
Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri)); ImageView imageView = (ImageView) findViewById(R.id.imgview_src); /* 将Bitmap设定到ImageView */ imageView.setImageBitmap(bitmap...
BitMapFactory 提供了四类方法: decodeFile,decodeResource,decodeStream 和 decodeByteArray 分别用于从文件系统,资源,输入流以及字节数组中加载出一个 Bitmap 对象。 高效加载 Bitmap 很简单,即采用 BitMapFactory...
import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.media.AudioManager; import android.media.MediaPlayer; import android.media....