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?
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.