Android Question Bitmap.Initializemutable does not work

Discussion in 'Android Questions' started by grafsoft, Jun 10, 2015.

  1. grafsoft

    grafsoft Well-Known Member Licensed User

    Hi,

    my code works on most devices, but there is one where it does not work.

    This is my code

    Code:
    Bitmap1.Initialize(Main.outdir,Main.thepic)
       
    Log (wi) 
       
    Log (he) 
       Bitmap2.InitializeMutable(wi,he)
       
    Log ("Bitmap2.InitializeMutable(wi,he)")
       
    If Bitmap2.IsInitialized=False Then Log ("No success")
    This is my log

    4160

    2339

    Bitmap2.InitializeMutable(wi,he)

    No success

    java.lang.RuntimeException: Object should first be initialized (Bitmap).

    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:49)

    at Photo.Tagger.kamera._camera1_picturetaken(kamera.java:1023)

    at java.lang.reflect.Method.invokeNative(Native Method)

    at java.lang.reflect.Method.invoke(Method.java:515)

    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)

    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:863)

    at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:820)

    at Photo.Tagger.cameraexclass._camera_picturetaken(cameraexclass.java:113)

    at java.lang.reflect.Method.invokeNative(Native Method)

    at java.lang.reflect.Method.invoke(Method.java:515)

    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)

    at anywheresoftware.b4a.BA$2.run(BA.java:297)

    at android.os.Handler.handleCallback(Handler.java:808)

    at android.os.Handler.dispatchMessage(Handler.java:103)

    at android.os.Looper.loop(Looper.java:193)

    at android.app.ActivityThread.main(ActivityThread.java:5292)

    at java.lang.reflect.Method.invokeNative(Native Method)

    at java.lang.reflect.Method.invoke(Method.java:515)

    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)

    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)

    at dalvik.system.NativeStart.main(Native Method)


    Thank you

    Peter
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    What are the values of wi and hi? Maybe there isn't enough memory available?

    It is worth checking the unfiltered logs.
     
    grafsoft likes this.
  3. sorex

    sorex Expert Licensed User

    that would require almost 38Mb
     
    grafsoft and Erel like this.
  4. Erel

    Erel Administrator Staff Member Licensed User

    I missed the values in the logs. As @sorex wrote the bitmap size is too large.
     
  5. grafsoft

    grafsoft Well-Known Member Licensed User

    The values are 4160 and 2339.

    How can I calculate the memory I need for this?

    How can I find the free memory on a phone?

    Thank you

    Peter
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Approximately: Width * Height * 4 (bytes)

    The process memory limit changes between different devices. You can ask the OS to give you more memory by setting the LargeHeap attribute in the manifest editor.

    Why do you need such a large bitmap?
     
  7. grafsoft

    grafsoft Well-Known Member Licensed User

    To put a photo on it and then draw on it. This phone has a camera with a very high resolution.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    You will need to use a smaller bitmap. I guess that you are showing the full image on the activity so there is no reason to keep the full image size.
     
Loading...