Android Question Bitmap to KeyValueStore

Sergey_New

Well-Known Member
Licensed User
Longtime User
I used kvs this:
B4X:
Starter.kvs.PutBitmap(id,bmp)
Now I need to additionally save another string parameter in kvs.
How can I do it?
 

teddybear

Well-Known Member
Licensed User
What do you mean? save another string parameter with same id in kvs?
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
I need to pass and receive three parameters from kvs at once.
Define a type with your thee parameters, fill the type with your thee parameters, write the thee parameters as type to and retrieve the three parameters in the type at once from the kvs😉.
Be awere that you can only have one time use the same type name definition for all B4XPages in B4XPage environment were the defined type name can access in all B4XPages separate from B4XPage where the type is defined.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
Define a type with your thee parameters
B4X:
'    Type myTipe(id As String, bmp As Bitmap, s As String)

    Dim t As myTipe
    t.Initialize
    t.id="a"
    t.bmp=LoadBitmap(File.DirAssets, "arrow.png")
    t.s="x"
    Starter.kvs.Initialize(Starter.myFolder, "kvs.dat")
    Starter.kvs.Put("i", t)
There is an error on the last line of code. How to add myTipe correctly?
Error occurred on line: 18 (KeyValueStore)
java.lang.RuntimeException: java.lang.RuntimeException: Cannot serialize object: android.graphics.Bitmap@5965602
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:285)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.WriteObject(B4XSerializator.java:121)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertObjectToBytes(B4XSerializator.java:79)
at sv.bystrovzorov.keyvaluestore._put(keyvaluestore.java:93)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:265)
at sv.bystrovzorov.function._setminiatures(function.java:7654)
at sv.bystrovzorov.mainmenu$ResumableSub_Activity_Create.resume(mainmenu.java:518)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1748)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7884)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.RuntimeException: Cannot serialize object: android.graphics.Bitmap@5965602
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:275)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeMap(B4XSerializator.java:256)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:283)
... 30 more
 
Last edited:
Upvote 0

teddybear

Well-Known Member
Licensed User
B4X:
'    Type myTipe(id As String, bmp As Bitmap, s As String)

    Dim t As myTipe
    t.Initialize
    t.id="a"
    t.bmp=LoadBitmap(File.DirAssets, "arrow.png")
    t.s="x"
    Starter.kvs.Initialize(Starter.myFolder, "kvs.dat")
    Starter.kvs.Put("i", t)
There is an error on the last line of code. How to add myTipe correctly?
Error occurred on line: 18 (KeyValueStore)
java.lang.RuntimeException: java.lang.RuntimeException: Cannot serialize object: android.graphics.Bitmap@5965602
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:285)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.WriteObject(B4XSerializator.java:121)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertObjectToBytes(B4XSerializator.java:79)
at sv.bystrovzorov.keyvaluestore._put(keyvaluestore.java:93)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:265)
at sv.bystrovzorov.function._setminiatures(function.java:7654)
at sv.bystrovzorov.mainmenu$ResumableSub_Activity_Create.resume(mainmenu.java:518)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1748)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7884)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.RuntimeException: Cannot serialize object: android.graphics.Bitmap@5965602
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:275)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeMap(B4XSerializator.java:256)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:283)
... 30 more
The object by kvs put can only be or contain primitive type. bitmap is non-primitive type, you only use putbitmap method.
if you want to use type to put, you need to convert bitmap to an array of byte.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
teddybear, MicroDrie thanks!
Unfortunately too many transformations will take a significant amount of time when filling kvs with more than 200 images.
I will try other methods.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Welli a new speed requirement, perhaps it works to store the image in blob and the two otter parameters in a sqlite database, and store the database in the kvs to prevent conversion.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
Welli a new speed requirement, perhaps it works to store the image in blob and the two otter parameters in a sqlite database, and store the database in the kvs to prevent conversion.
Thank you, I'll keep that in mind.
 
Upvote 0
Top