android Bitmap

jain110 2012-05-02 03:45:27
Android 中Bitmap对象如何使用decodeStream生成缩略图?
在网上看了好多都是用decodeFile这种方式生成的。 谁可以告知一下?
...全文
81 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
j_f0001 2012-05-02
  • 打赏
  • 举报
回复

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;

}
jain110 2012-05-02
  • 打赏
  • 举报
回复
BitmapFactory.Options options = new BitmapFactory.Options();
//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的方式来生成缩略图
danielinbiti 2012-05-02
  • 打赏
  • 举报
回复
decodeFile没有从网络解码图片的能力

80,354

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧