1
我需要将高分辨率的远程图像加载到imageview,但不使用任何外部库或框架。图片就像是2150x1500像素,这里是我的加载代码:将大于2048x2048的图像加载到Android上的ImageView上
URL imageUrl = new URL(url);
HttpURLConnection connection;
if (url.startsWith("https://")) {
connection = (HttpURLConnection) imageUrl.openConnection();
} else {
connection = (HttpURLConnection) imageUrl.openConnection();
}
connection.setConnectTimeout(30000);
connection.setReadTimeout(30000);
connection.setInstanceFollowRedirects(true);
InputStream is = connection.getInputStream();
OutputStream os = new FileOutputStream(f);
CacheUtils.CopyStream(is, os);
os.close();
image = decodeFile(f);
img.setImageBitmap(image);
这里是decodeFile功能:
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
,我总是得到纹理尺寸过大的异常。有什么方法可以加载这些图片吗?或者有没有办法调整图像大小不是2或4倍,而是调整大小以适应宽度2048像素?
我试过了,但我离开的内存异常和应用程序崩溃(当我使用2048高度和宽度)。 – 2014-09-02 10:20:22
你可以给我的图片网址吗? – 2014-09-02 10:33:07
http://youngsday.com/wp-content/uploads/2014/04/new-york.jpg – 2014-09-02 10:42:52