Android Question Bitmap.InitializeMutable(width, height) Unknown member ?

MitchBu

Well-Known Member
Licensed User
Longtime User
I am trying to initialize a Mutable Bitmap so I can draw onto it with a canvas and then save to disk without drawing onto the activity, but I get
Unknown member: initializemutable

Here is what I did :
B4X:
bitmap2.InitializeMutable(800,600)

I read several times https://www.b4x.com/android/help/drawing.html#bitmapdrawable_initialize without finding any way to apply this :

Method_636.png
InitializeMutable (Width As Int, Height As Int)

Creates a new mutable bitmap with the specified dimensions. You can use a Canvas object to draw on this bitmap.
 

MitchBu

Well-Known Member
Licensed User
Longtime User
Precisely my question is how does such an object can be created. Apparently neither bitmap which is read only nor bitmapDrawable seem to be OK.

This is the code I tried and which triggers the exception :

B4X:
Private bitmap2 As BitmapDrawable
bitmap2.InitializeMutable(800,600)

It is my hope that Erel, or somebody else, will post the exact code to use.

I found two related questions but none gives more information than what I already have :(

https://www.b4x.com/android/forum/threads/bitmap-initializemutable-does-not-work.54795/
and https://www.b4x.com/android/forum/threads/initializemutable.27618/
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
If I declare as bitmap, it compiles, but afterward I get this :

** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 39 (Main)
java.lang.IllegalArgumentException: method anywheresoftware.b4a.objects.drawable.CanvasWrapper.Initialize argument 1 has type android.view.View, got android.graphics.Bitmap
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:753)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:343)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at b4a.canvas.main.afterFirstLayout(main.java:102)
at b4a.canvas.main.access$000(main.java:17)
at b4a.canvas.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6134)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

** Activity (main) Resume **
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
It works ! :D

B4X:
   Private bitmap2 As Bitmap
    bitmap2.InitializeMutable(800,600)
    cvs.Initialize2(bitmap2)
    cvs.DrawColor(Colors.Green)
    Dim Out As OutputStream
    Out = File.OpenOutput(File.DirRootExternal, "reTest.png", False)
    cvs.Bitmap.WriteToStream(Out, 100, "PNG")
    Out.Close

Thank you so much for the friendly hands :)
 
Upvote 0
Top