从网址撷取影像,并保持其原始大小 [英] Fetch image from Url and keep its original size

查看:117
本文介绍了从网址撷取影像,并保持其原始大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从这个code座网址提取图片:

I fetch image from URL with this code block:

BitmapFactory.Options bmOptions;
bmOptions = new BitmapFactory.Options();
//from web
try {
    Log.i(TAG,""+g.getPath());
    InputStream is = new URL(g.getPath()).openStream();
    BitmapFactory.decodeStream(is, null, bmOptions);
    is.close();
    BitmapFactory.Options o2 = new BitmapFactory.Options();
    o2.inSampleSize = 2;
    o2.inMutable = true;
    is = new URL(g.getPath()).openStream();
    bitmap = BitmapFactory.decodeStream(is, null, o2);
    is.close();
} catch (Exception ex) {
    ex.printStackTrace();
}

下载成功,但图像的大小不是原大小。这是较低的分辨率。我怎样才能在其原大小图片从网址是什么?

Download is successful but the image's size is not the orginal size. It is lower resolution. How can I get the image in its orginal size from Url?

推荐答案

删除此行

    o2.inSampleSize = 2;

您也可以使用
                  位= BitmapFactory.de codeStream(是,空,bmOptions);

You can also use bitmap = BitmapFactory.decodeStream(is, null, bmOptions );

没有必要创造新的BitmapOptions

No need to create new BitmapOptions

这篇关于从网址撷取影像,并保持其原始大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆