B4J Question fx.Clipboard.SetImage(Root.Snapshot)

ivanomonti

Expert
Licensed User
Longtime User
I have a problem with the fx.Clipboard.SetImage(Root.Snapshot) function which makes a single image and then nothing more, I mean the first click works and the following ones don't, where am I wrong?

code:
Private Sub Button_clipboard_grapic_Click 'crea una copia del form in memoria da incollare dove si vuole
    fx.Clipboard.SetImage(Root.Snapshot)
End Sub
 

Cableguy

Expert
Licensed User
Longtime User
There is no difference between the code in the first post and in the second post...
Actually I think there is...
By re-Declaring the bmp each time the sub is called, the bmp object recretated and has no image attached (?) and by doing that, the resulting compiled Java code is different, so it works!(?)
 
Last edited:
Upvote 0

ivanomonti

Expert
Licensed User
Longtime User
There is no difference between the code in the first post and in the second post...
in reality with the second code I can get the images with each click, if I make the first image and then copy some text at that point the first code no longer copies the screen but the text remains, with the second code it recreates the screen without problems
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Very nice. I wanted to test the two methods and the following code:
B4X:
Private Sub Button1_Click

    #IF B4J
        fx.Clipboard.SetImage(Root.Snapshot)
        If fx.Clipboard.HasImage Then
            Log("yes")
            Log(GetType(fx.Clipboard.GetImage))
            B4XImageView1.Bitmap = fx.Clipboard.GetImage
    '        ImageView1.SetImage(fx.Clipboard.GetImage)
        Else
            Log("no")
        End If
    #End If

End Sub

it throws an exception, whether I use the B4XImageView or the ImageView:

java.lang.IllegalArgumentException: Upload requires 360000 elements, but only 0 elements remain in the buffer

java.lang.IllegalArgumentException: Upload requires 360000 elements, but only 0 elements remain in the buffer
at com.sun.prism.impl.BaseTexture.checkUpdateParams(BaseTexture.java:385)
at com.sun.prism.d3d.D3DTexture.update(D3DTexture.java:138)
at com.sun.prism.impl.BaseTexture.update(BaseTexture.java:321)
at com.sun.prism.impl.BaseResourceFactory.createTexture(BaseResourceFactory.java:247)
at com.sun.prism.impl.BaseResourceFactory.getCachedTexture(BaseResourceFactory.java:218)
at com.sun.prism.impl.BaseResourceFactory.getCachedTexture(BaseResourceFactory.java:152)
at com.sun.javafx.sg.prism.NGImageView.renderContent(NGImageView.java:121)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2053)
at com.sun.javafx.sg.prism.NGImageView.doRender(NGImageView.java:103)
at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1945)
at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:235)
at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:577)
at com.sun.javafx.sg.prism.NGNode.renderForClip(NGNode.java:2294)
at com.sun.javafx.sg.prism.NGNode.renderRectClip(NGNode.java:2188)
at com.sun.javafx.sg.prism.NGNode.renderClip(NGNode.java:2214)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2047)
at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1945)
at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:235)
at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:577)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2053)
at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1945)
at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:477)
at com.sun.javafx.tk.quantum.ViewPainter.paintImpl(ViewPainter.java:330)
at com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:91)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
at java.lang.Thread.run(Thread.java:748)

(log of GetType: javafx.scene.image.Image, the type ImageView1.SetImage requires)
 
Last edited:
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Very nice. I wanted to test the two methods and the following code:
B4X:
Private Sub Button1_Click

    #IF B4J
        fx.Clipboard.SetImage(Root.Snapshot)
        If fx.Clipboard.HasImage Then
            Log("yes")
            Log(GetType(fx.Clipboard.GetImage))
            B4XImageView1.Bitmap = fx.Clipboard.GetImage
    '        ImageView1.SetImage(fx.Clipboard.GetImage)
        Else
            Log("no")
        End If
    #End If

End Sub

it throws an exception, whether I use the B4XImageView or the ImageView:

java.lang.IllegalArgumentException: Upload requires 360000 elements, but only 0 elements remain in the buffer

java.lang.IllegalArgumentException: Upload requires 360000 elements, but only 0 elements remain in the buffer
at com.sun.prism.impl.BaseTexture.checkUpdateParams(BaseTexture.java:385)
at com.sun.prism.d3d.D3DTexture.update(D3DTexture.java:138)
at com.sun.prism.impl.BaseTexture.update(BaseTexture.java:321)
at com.sun.prism.impl.BaseResourceFactory.createTexture(BaseResourceFactory.java:247)
at com.sun.prism.impl.BaseResourceFactory.getCachedTexture(BaseResourceFactory.java:218)
at com.sun.prism.impl.BaseResourceFactory.getCachedTexture(BaseResourceFactory.java:152)
at com.sun.javafx.sg.prism.NGImageView.renderContent(NGImageView.java:121)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2053)
at com.sun.javafx.sg.prism.NGImageView.doRender(NGImageView.java:103)
at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1945)
at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:235)
at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:577)
at com.sun.javafx.sg.prism.NGNode.renderForClip(NGNode.java:2294)
at com.sun.javafx.sg.prism.NGNode.renderRectClip(NGNode.java:2188)
at com.sun.javafx.sg.prism.NGNode.renderClip(NGNode.java:2214)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2047)
at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1945)
at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:235)
at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:577)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2053)
at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1945)
at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:477)
at com.sun.javafx.tk.quantum.ViewPainter.paintImpl(ViewPainter.java:330)
at com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:91)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
at java.lang.Thread.run(Thread.java:748)

(log of GetType: javafx.scene.image.Image, the type ImageView1.SetImage requires)

I noticed that even though they were declared to be the same type.

1696342184811.png


Reading the GetType returns for:
fx.Clipboard.SetImage(Root.Snapshot): the type fx.Clipboard.GetImage: javafx.scene.image.Image
while for
Dim img As Image = Root.Snapshot the type img as Image: javafx.scene.image.WritableImage

B4X:
Dim img As Image = Root.Snapshot
    fx.Clipboard.SetImage(Root.Snapshot)
    If fx.Clipboard.HasImage Then
        Log("yes")
        Log($"Type fx.Clipboard.GetImage: ${GetType(fx.Clipboard.GetImage)}"$)
        Log($"Type img as Image: ${GetType(img)}"$)
        'Dont work Type fx.Clipboard.GetImage: javafx.scene.image.Image
        'ImageView1.SetImage(fx.Clipboard.GetImage)
        'Work  Type img as Image: javafx.scene.image.WritableImage
        ImageView1.SetImage(img)
       
    Else
        Log("no")
    End If

and the type javafx.scene.image.WritableImage loads without any problem

I read in the documentation:
Please note that javafx.scene.image.WritableImage is a modified version of Image and its primary objective is to generate an image from memory data .

therefore most likely (?) assigning a B4XBitmap ( Root.Snapshot ) to a variable of type Image is "converted" to javafx.scene.image.WritableImage, in the case of fx.Clipboard.SetImage(Root.Snapshot) it remains javafx.scene.image.Image
 
Upvote 0
Top