将大于2048x2048的图像加载到Android上的ImageView中
我需要将高分辨率远程图像加载到imageview,但不使用任何外部库或框架。图像类似于2150x1500像素,下面是我的加载代码:将大于2048x2048的图像加载到Android上的ImageView中,android,opengl-es,imageview,Android,Opengl Es,Imageview,我需要将高分辨率远程图像加载到imageview,但不使用任何外部库或框架。图像类似于2150x1500像素,下面是我的加载代码: URL imageUrl = new URL(url); HttpURLConnection connection; if (url.startsWith("https://")) { connection = (HttpURLC
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);
下面是解码文件功能:
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
我总是得到纹理大小太大的例外。有没有办法加载这些图像?或者有没有一种方法可以调整图像大小,而不是2到4倍,而是按宽度调整大小以适应2048像素?我尝试过,但内存不足,出现异常,应用程序崩溃(当我使用2048高度和宽度时)。你能给我图像url吗?我正尝试将其与viewpager结合使用(用户应在从internet下载的n个图像之间滚动)。它在genymotion simulator中工作,但在设备(Nexus 7)上不工作。以下是查看寻呼机适配器中的iStatiateItem方法:
class DownloadImage extends AsyncTask<String, Void, Bitmap>
{
ImageView bmImage;
public DownloadImage(ImageView bmImage) {
this.bmImage = bmImage;
}
@Override
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
@Override
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(Bitmap.createScaledBitmap(result, 120, 120, false));
}
}
new DownloadImage((ImageView) findViewById(R.id.imageView1))
.execute("https://.........");