1

我使用以下代码下载位图并调整其大小:

private void downloadImage(String urlImg, ImageView v) {
    Bitmap bitmap = null, resized= null;
    try {
        URL urlImage = new URL("http://.../" + urlImg);
        HttpURLConnection connexion = (HttpURLConnection) urlImage
                .openConnection();
        InputStream inputStream = connexion.getInputStream();
        bitmap = BitmapFactory.decodeStream(inputStream);
        resized = Bitmap.createScaledBitmap(bitmap, 100, 100, false);
        v.setImageBitmap(resized);

        connexion.disconnect();
        inputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

在我的 onCreate() 函数中,我在使用以前的函数的地方动态创建 ImageViews

   ImageView view = new ImageView(this);
   downloadImage(list.getOneAnnonce(i).getPhoto(), view);
   trMain.addView(view);

如果我不尝试调整位图大小,则没有错误,但如果我尝试调整大小 -> 强制关闭

4

0 回答 0