Italian B4J - blob in B4XView

ivanomonti

Expert
Licensed User
Longtime User
Come da immagine ho un blob che arriva da db, ho un pane dove recupero attraverso codice, il nuovo B4XView ha la possibilità di inserire un immagine attraverso SetBitmap che accetta Javafx.scene.image.image, io gli passo un javafx.scene.image.image ma alla fine va in crash, l'errore è SEMPRE mio e lo so, ma avrei bisogno di un vostro sguardo dove sbaglio.

B4X:
If v Is B4XView And v.Tag = "icona" Then
                If lsTemp.Get(14) <> Null Then
                    Try
                        Log(lsTemp.Get(14))
                        v.SetBitmap(lsTemp.Get(14))
                    Catch
                        Log(LastException)
                    End Try
                End If
            End If


B4X:
Waiting for debugger to connect...
Program started.
No results found
javafx.scene.image.Image@509917c6
Errore nella linea: 532
java.lang.ClassCastException: class anywheresoftware.b4j.objects.PaneWrapper$ConcretePaneWrapper$NonResizePane cannot be cast to class javafx.scene.image.ImageView (anywheresoftware.b4j.objects.PaneWrapper$ConcretePaneWrapper$NonResizePane is in unnamed module of loader 'app'; javafx.scene.image.ImageView is in module javafx.graphics of loader 'app')
    at anywheresoftware.b4j.objects.ImageViewWrapper.SetImage(ImageViewWrapper.java:99)
    at anywheresoftware.b4a.objects.B4XViewWrapper.SetBitmap(B4XViewWrapper.java:543)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:676)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:240)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at jdk.internal.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:64)
    at b4j.example.classorganized._edititem(classorganized.java:211)
    at b4j.example.classorganized._buttonitem_mouseclicked(classorganized.java:612)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at jdk.internal.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:93)
    at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:1)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics/javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3564)
    at javafx.graphics/javafx.scene.Scene$ClickGenerator.access$8200(Scene.java:3492)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3860)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.access$1200(Scene.java:3579)
    at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1849)
    at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2588)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:397)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:434)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:390)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:433)
    at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
    at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)



Cattura.JPG
 

Star-Dust

Expert
Licensed User
Longtime User
LsTemp.Get(14) cosa sarebbe?

Come la hai salvato l'immagine? Non l'hai prima passata in Byte poi in stribnga Base 64 e infine salvato il BLOB?
Oppure hai preso la variabile immagine e passata come parametro al DB?
 

LucaMs

Expert
Licensed User
Longtime User
LsTemp.Get(14) cosa sarebbe?
https://www.b4x.com/android/forum/t...ema-modulare-tipo-plug-ins.117119/post-732551

In quel post (vattela a pija' 😄)
E che ne so, io che non ho sviluppato quel codice e tu stesso, tra un po' di tempo, a cosa corrisponderanno i valori della map nelle posizioni 2-3-4-5-6 che vedo scritte là
Se invece avessi preparato delle costanti:
Public Const PLUG_ARG_NAME As Int = 1
Public Const PLUG_ARG_FILE As Int = 2
Public Const PLUG_ARG_DIR As Int = 3
etc.
poi avresti scritto:
m.GetValueAt(PLUG_ARG_NAME)
m.GetValueAt(PLUG_ARG_FILE)
m.GetValueAt(PLUG_ARG_DIR)
etc.

In questo modo il codice risulta più leggibile (anche a te stesso tra un anno) e non devi ricordarti a memoria se nella posizione 2 hai il la dir o il file o il nome o...
 

ivanomonti

Expert
Licensed User
Longtime User
LsTemp.Get(14) cosa sarebbe?

Come la hai salvato l'immagine? Non l'hai prima passata in Byte poi in stribnga Base 64 e infine salvato il BLOB?
Oppure hai preso la variabile immagine e passata come parametro al DB?
contiene l'immagine blob presa dal db (campo blog) che uso tranquillamente ma ad esempio in imageview.setimage(lstemp.get(14)) viene pubblicata in B4XView va in crash

Cattura.JPG
 

Star-Dust

Expert
Licensed User
Longtime User
Fammi vedere il codice per trasferire l'immagine nel campo blob del DB.
penso che l'errore sta proprio li.
 

ivanomonti

Expert
Licensed User
Longtime User
in realtà no, perchè si registra serenamente e lo riprendo serenamente

In Class_Globals Private ImageIco As B4XBitmap

B4X:
Dim ICO As Image
ICO = ImageIco ' immagine tampone
Dim out As OutputStream
out.InitializeToBytesArray(0)
ICO.WriteToStream(out)
Dim Buffer() As Byte
Buffer = out.ToBytesArray
out.Close
sqlite.InitializeSQLite(File.DirApp,"data.sqlite", False)
sqlite.ExecNonQuery(query)
sqlite.ExecNonQuery2("UPDATE item SET icon = ? WHERE id = '" & id & "' AND userid=?", Array As Object(Buffer,Main.global.idlogin))
 

Star-Dust

Expert
Licensed User
Longtime User
in realtà no, perchè si registra serenamente e lo riprendo serenamente

In Class_Globals Private ImageIco As B4XBitmap

B4X:
Dim ICO As Image
ICO = ImageIco ' immagine tampone
Dim out As OutputStream
out.InitializeToBytesArray(0)
ICO.WriteToStream(out)
Dim Buffer() As Byte
Buffer = out.ToBytesArray
out.Close
sqlite.InitializeSQLite(File.DirApp,"data.sqlite", False)
sqlite.ExecNonQuery(query)
sqlite.ExecNonQuery2("UPDATE item SET icon = ? WHERE id = '" & id & "' AND userid=?", Array As Object(Buffer,Main.global.idlogin))
È sbagliato non si fa così.
L'array va convertito in stringa a base64 e viceversa alla lettura da Stringa a byte e poi da byte con inputStream in immagine

Fra l'altro che a setBitmap e vi passare come parametro un Omaggio non un array dui dati, ammesso che il db l'array di dati.. il che non è sicuro.

Ma il Db non accetta gli array come parametri ne li restituisce. Tu passi l'array di parametri alla sub ma un parametro non può essere a sua volta un array
 
Last edited:

ivanomonti

Expert
Licensed User
Longtime User
@Star-Dust mi spieghi allora perchè nel db arriva tutto in modo regolare e restituisce in modo regolare,,, non per far polemica ma per capire, anche perchè il codice utilizzato l'ho preso da erel in qualche suo esempio ma non ricordo dove :-(
 

Star-Dust

Expert
Licensed User
Longtime User
@Star-Dust mi spieghi allora perchè nel db arriva tutto in modo regolare e restituisce in modo regolare,,, non per far polemica ma per capire, anche perchè il codice utilizzato l'ho preso da erel in qualche suo esempio ma non ricordo dove :-(
Tanto sarebbe inutile oggi non mi va di far polemica 😂😂😂

Ma suppongo che hai posto la domanda per avere una risposta e soprattutto se hai posto la domanda vuol dire che non funziona quello che hai scritto....

Quindi se vuoi prova il mio consiglio altrimenti tenta ancora con il tuo metodo
 

Star-Dust

Expert
Licensed User
Longtime User
Indizio: Image e ImageView non sono la stessa cosa!
Soprattutto un array di byte non è un Bitmap. Lo sevi convertire
 

ivanomonti

Expert
Licensed User
Longtime User
@LucaMs, lo so ma quel codice che ho postato da risultati con la trasformazione da db a imageview

B4X:
Sub imageblobget(value As Object) As Image
    Try
        Dim Buffer() As Byte
        Buffer = value
        Dim InputStream1 As InputStream
        InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
        Dim Bitmap1 As Image
        Bitmap1.Initialize2(InputStream1)
        InputStream1.Close
        Return Bitmap1
    Catch
        Log(LastException)
    End Try
End Sub

Chiuedo un consiglio perche non mi è chiara la cosa in zucca, dovrebbe essere molto più semplice ma in realtà la trovo un poco bordellain, al momento gira tutto alla perfezione ma avendo visto che in .SetBitmap in B4XView che in ImageView funziona perfettamente, qui mi mi fa crash, a questo punto ho fatto un codice per una cosa e un codice per l'altra, ma trovo la cosa una CAGATA che vorrei sistemare.

B4X:
Dim imgw As ImageView
                imgw.Initialize("")
                imgw.SetImage(imvalue.Get(14))
                imgw.PrefHeight = 24
                imgw.PrefWidth = 24
                SetGraphic(bt, imgw)

qui invece devo aggiungere imageview su un pannello cosa che vorrei fare nel pannello senza imageview

B4X:
If v Is B4XView And v.Tag = "icona" Then
                Dim pn As Pane = v
                If lsTemp.Get(14) <> Null Then
                    Try
                        Log(lsTemp.Get(14))
                        Dim imgw As ImageView
                        imgw.Initialize("")
                        imgw.SetImage(lsTemp.Get(14))
                        imgw.PrefHeight = 128
                        imgw.PrefWidth = 128
                        pn.AddNode(imgw,0,0,128,128)
                        '------------------------------------------
                    Catch
                        Log(LastException)
                    End Try
                End If
            End If

Ora che @Star-Dust ha sollevato il "NO NON VA BENE" voglio capire
 

LucaMs

Expert
Licensed User
Longtime User
Ho fatto una libreria per trasferire le immagini su db es posso dire anche che dipende dalla versione di Android
Penso che lui voglia lavorare sulle B4XView, non so la tua libreria.
Cmq, nel suo caso, lavorare con XUI e le B4XView servirà solo da allenamento (o da rinco...to), perché è impossibile che il sw che sta sviluppando possa poi girare ad esempio su un tablet Android (sarebbe fattibile, ovviamente, ma non credo che abbia realizzato tutto in "puro XUI").
 
Top