Android 中Bitmap对象如何使用decodeStream生成缩略图?
在网上看了好多都是用decodeFile这种方式生成的。 谁可以告知一下?
在网上看了好多都是用decodeFile这种方式生成的。 谁可以告知一下?
解决方案 »
- 应用怎样拥有/data/local/tmp目录的写权限
- 求大神帮忙解决android中的编程问题
- android的朋友看过来,100分求如何实现在代码程序中创建网站的快捷方式(需要网站图标,另外本人创建了一个群(181357702),欢迎交流
- Android学习困惑
- android gps 移植问题
- 关于listview的问题
- android 3.0 SDK
- TableLayout如何保证宽高比?
- android things中文显示乱码
- activity中使用aar中的监听,onActivityResult接收不了数据?急急急~
- android中 组件 和 线程 的关系 !!!
- 图片上传方案
//options.inSampleSize = 3;
options.outHeight = 200;
options.inJustDecodeBounds = true;
//options.
if (position < 0) { position = position + mImageDirs.size(); }
// 获取这个图片的宽和高
Bitmap bm = BitmapFactory.decodeFile(this.mImageDirs
.get(position % mImageDirs.size()), options); //此时返回bm为空
options.inJustDecodeBounds = false;
int be = options.outHeight / 20;
if(be%10 !=0)
be+=10;
be=be/10;
if (be <= 0)
be = 1;
options.inSampleSize = be;
bm = BitmapFactory.decodeFile(this.mImageDirs.get(position
% mImageDirs.size()), options);这里使用decodeFile生成的缩略图,我希望用decodeStream的方式来生成缩略图
public static Bitmap getBitmapByUrl(HttpGet httpGet,String strurl, int displayWidth,
int displayHeight) throws IOException, URISyntaxException {
URL url = new URL(strurl);
getHttpClient();
httpGet.setURI(new URI(strurl));
HttpResponse response = httpClient.execute(httpGet);
InputStream ins=null;
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
ins=response.getEntity().getContent();
}
else
return null;
//url.openConnection().setDefaultUseCaches(true);
Options options = new Options();
options.inJustDecodeBounds = true; Bitmap bitmap = BitmapFactory.decodeStream(ins, null, options);
int srcWidth = options.outWidth;
ins.close();
ins = null;
options.inJustDecodeBounds = false;
Log.d("Tag", "with:" + options.outWidth);
// int be = (int) (((double) options.outWidth) / ((double)
// displayWidth));
int be = 0;
be = (int) Math.round(((((double) srcWidth) / ((double) displayWidth)))); options = new Options();
options.inSampleSize = be;
//ins = url.openStream();
response = httpClient.execute(httpGet);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
ins=response.getEntity().getContent();
} bitmap = BitmapFactory.decodeStream(ins, null, options);
ins.close();
return bitmap;
}