0

I want to open one image from my assets folder, resize it and resave the image. I use this code:

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);

}

But when I start application it crash. This is stack trace:

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)

Does someone know why crash?

2
  • Just a quick thought... what happens if you replace the last line with this: final Bitmap newBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, bitmapOrg.getWidth(), bitmapOrg.getHeight(), aMatrix, false); Commented Dec 9, 2011 at 1:54
  • There still the same stacktrace Commented Dec 9, 2011 at 8:03

1 Answer 1

2

The assets folder is located inside the APK, and thus is not a true folder in the File System. I don't think you can save anything there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.