J'utilise la méthode citée ci-dessous pour arrondir les coins de n'importe quel bitmap. Quelque temps cela fonctionne parfaitement, un certain temps non à cause de l'exception OutOfMemory. L'exception se produit souvent à la ligneMémoire insuffisante pendant le travail avec Bitmap dans android
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Ai-je oublié des codes spéciaux ici? Aidez-moi, s'il vous plaît.
public static Bitmap roundBitmap(Bitmap bitmap, int roundedRadius) {
if (bitmap == null)
return null;
if (roundedRadius == 0) {
return bitmap;
}
// Bitmap output = bitmap.copy(Config.ARGB_8888, true);
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xffffff00;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = roundedRadius;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
Parfois, l'erreur «out of memory» apparaît, lorsque le manque de mémoire n'est pas vraiment la cause du problème mais quelque chose d'autre. Pouvez-vous spécifier la trace de pile et/ou l'erreur? –
Ma réponse postée dans un autre fil similaire pourrait vous aider: http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object/ 18544069 # 18544069 – Bruce