fabian7593 / MagicalCamera

A library to take picture easy, transform your data in different format and save photos in your device
Apache License 2.0
338 stars 90 forks source link

OutOfMemoryError #16

Closed timbaev closed 7 years ago

timbaev commented 7 years ago

Then I take a photo, I get this error:

FATAL EXCEPTION: main Process: com.timal.bookreminder, PID: 9243 java.lang.OutOfMemoryError: Failed to allocate a 48000012 byte allocation with 16777216 free bytes and 27MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:843) at android.graphics.Bitmap.createBitmap(Bitmap.java:820) at android.graphics.Bitmap.createBitmap(Bitmap.java:751) at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:627) at com.frosquivel.magicalcamera.Utilities.PictureUtils.resizePhoto(PictureUtils.java:49) at com.frosquivel.magicalcamera.Functionallities.ActionPicture.onTakePhotoResult(ActionPicture.java:221) at com.frosquivel.magicalcamera.Functionallities.ActionPicture.resultPhoto(ActionPicture.java:240) at com.frosquivel.magicalcamera.MagicalCamera.resultPhoto(MagicalCamera.java:163) at com.timal.bookreminder.TwoFragment.onActivityResult(TwoFragment.java:183) at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:164) at android.app.Activity.dispatchActivityResult(Activity.java:6508) at android.app.ActivityThread.deliverResults(ActivityThread.java:3702) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3749) at android.app.ActivityThread.access$1400(ActivityThread.java:153) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1400) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5441) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)

It is only on Android 6.0, on Android 4.4 work perfectly.

fabian7593 commented 7 years ago

hello @timbaev, this is not for the android version is for the device camera.

Why? This is because the bitmap have a limit in the array and if the bitmap is very large, this exception is catch, (please review this https://developer.android.com/training/displaying-bitmaps/index.html).

This is too because the camera of your device is very good and your lvl of quality photo is high, if you have lvl 30 in magical camera maybe work in all devices withouth this exception;).

And the solution: write in your manifest

 <application
        android:hardwareAccelerated="false"
        android:largeHeap="true">

Use, the example of magical camera, download the project and execute, see the manifest of the app, and other process, execute the example and test in any devices.

My recomendation is, dont use the best quality of photography, because the weight is very high, and is difficult for send to Web Services or save in DB... Or if you need all the quality photo, add the large heap, but this increment the ram memory of your device...

Please tell if this work for you, thanks