2011-12-09 3 views
0

자산 폴더에서 이미지 하나를 열고 크기를 조정하고 이미지를 다시 저장하려고합니다. 이 코드를 사용합니다 :비트 맵을 파일로 저장

private void resizeImage(float ratio) { 
    AssetManager assetManager = getAssets(); 
    InputStream stream = null; 
    try { 
     stream = assetManager.open("bear.png"); 
    } catch (IOException e) { 
     return; 
    } 
    Bitmap bitmapOrg = BitmapFactory.decodeStream(stream); 

    int width = bitmapOrg.getWidth(); 
    int height = bitmapOrg.getHeight(); 

    float scaleWidth = ((float) width)/ratio; 
    float scaleHeight = ((float) height)/ratio; 

    Matrix aMatrix = new Matrix(); 
    aMatrix.setSkew(scaleWidth, scaleHeight); 

    bitmapOrg = Bitmap.createBitmap(bitmapOrg, 0, 0, bitmapOrg.getWidth(), 
      bitmapOrg.getHeight(), aMatrix, false); 

} 

그러나 응용 프로그램을 시작할 때 충돌이 발생합니다. 이것은 스택 추적입니다 :

12-09 02:36:33.750: ERROR/AndroidRuntime(1939):  at android.graphics.Bitmap.nativeCreate(Native Method) 
12-09 02:36:33.750: ERROR/AndroidRuntime(1939):  at android.graphics.Bitmap.createBitmap(Bitmap.java:477) 
12-09 02:36:33.750: ERROR/AndroidRuntime(1939):  at android.graphics.Bitmap.createBitmap(Bitmap.java:444) 

누군가 크래시를 알 수 있습니까?

+0

마지막 줄을 다음과 같이 바꾸면 어떻게됩니까? 최종 비트 맵 newBitmap = Bitmap.createBitmap (bitmapOrg, 0, 0, bitmapOrg.getWidth(), bitmapOrg.getHeight(), aMatrix, false); – dbryson

+0

여전히 동일한 스택 추적이 있습니다. –

답변

2

자산 폴더가 APK 내에 있으며 파일 시스템의 실제 폴더가 아닙니다. 아무 것도 저장할 수 있다고 생각하지 않습니다.

관련 문제