2012-02-27 2 views
1

아래 인용 된 방법을 사용하여 비트 맵의 ​​모서리를 반올림합니다. OutOfMemory 예외 때문에 언젠가 완벽하게 작동합니다. 예외가 종종 발생합니다안드로이드의 비트 맵 작업 중 메모리가 부족합니다.

Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), 
     bitmap.getHeight(), Config.ARGB_8888); 

여기에 특별한 코드가 누락 되었습니까? 도와주세요. 당신이 roundBitmap()를 호출 한 후 원래 비트 맵이 필요하지 않은 경우

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; 
} 
+1

때때로 메모리의 부족이 실제로 문제의 원인이 아니라 다른 것이있을 때 '메모리 부족'이라는 오류 메시지가 나타납니다. 스택 추적 및/또는 errormessage를 지정할 수 있습니까? –

+1

또 다른 비슷한 스레드에 게시 된 내 대답은 당신을 도울 수 있습니다 : http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object/ 18544069 # 18544069 – Bruce

답변

1

당신은 비트 맵에 사용되는 메모리를 해제 bitmap.recycle()를 호출해야합니다.

-4
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), 
    bitmap.getHeight(), new BitmapFactory.Options().inSampleSize=4); 

위의 코드를 시도해보십시오.

+0

작동하지 않습니다. 컴파일 시간 오류가 표시됩니다. –

관련 문제