Je charge des images à partir d'URL de différentes tailles. Il semble que les plus petits viennent à travers, et une exception nullPointerException (affichée dans le Log.d ci-dessous) vient à travers pour les plus grands. Comment puis-je redimensionner ces images?Android 2.2 SDK - image bitmap redimensionner nullPointerException
BitmapDrawable drawable = null;
Bitmap bitmap = null;
try {
bitmap = loadBitmapFromWeb(url);
System.out.println("url " + url);
} catch (IOException e) {
}
int width = 150;
int height = 150;
try {
drawable = resizeImage(bitmap, height, width);
} catch (Exception e) {
Log.d("exception image", e.toString());
drawable = getDrawableFromResource(R.drawable.default_backup);
}
C'est ce que je l'utilise pour charger à partir d'une URL:
public static Bitmap loadBitmapFromWeb(String url) throws IOException {
InputStream is = (InputStream) new URL(url).getContent();
Bitmap bitmap = BitmapFactory.decodeStream(is);
return bitmap;
}
C'est ce que j'utiliser pour redimensionner, où l'erreur apparaît:
public static BitmapDrawable resizeImage(Bitmap bitmap, int w, int h) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int newWidth = w;
int newHeight = h;
float scaleWidth = ((float) newWidth)/width;
float scaleHeight = ((float) newHeight)/height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height,
matrix, true);
return new BitmapDrawable(resizedBitmap);
}
pouvez-vous être un peu plus précis? Où votre NPE est-il lancé? Numéro de ligne? Quelle ligne de code? – WarrenFaith