B4J Question jFX Clipoard

miga

Member
Licensed User
Longtime User
I'm working with jFX Clipboard and trying to paste an image from clipboard to imgeview. It works when am copying an image (jpg, png, etc), but Have a problem when I'm trying to copy/paste image from QTplayer or pdf file.
In these cases I cannot even save jpg, png, bmp file. The xnview can open it, but e.g.Photoshop cannot.
The files are somehow damage (its visible in xnview).
Then I tried this:

fx.Clipboard.SetImage(fx.Clipboard.GetImage)
...then paste to windows paint...

and realized that even this damage the images.

Am I doing something wrong?
Or is there other way how to use Clipboard (image) except of jFX?

Thanx
 

miga

Member
Licensed User
Longtime User
Attached is example:
- original - copied from pdf, pasted to photoshop, saved as jpg
- re-clipboard - copied from pdf, re-clipboarded over fx.Clipboard.SetImage(fx.Clipboard.GetImage), pasted to photoshop, saved as jpg

you can see different size, damaged colors
if I save this over:

out = File.OpenOutput("C:\temp", "tmp.jpg", False)
clipImage = fx.Clipboard.GetImage
clipImage.WriteToStream(out)


the result is jpg, that can be open in xnview but not in photoshop. I cannot even upload it here, because:

The contents of the uploaded image do not match the file's extension

So I uploaded zip file within the saved jpg (it seams it's not a jpg)
Filechecker said it's png, but even after renaming photoshop shows empty image.
 

Attachments

  • original.jpg
    449.7 KB · Views: 248
  • re-clipboard.jpg
    420.4 KB · Views: 259
  • saved.zip
    504.3 KB · Views: 249
Last edited:
Upvote 0

miga

Member
Licensed User
Longtime User
What is the purpose of this step?


You haven't closed the outputstream so the file is not complete.

There is no purpose and i don't want to use it in my code. I just wanted to know where is the problem.
So it's just "check" whether content of clipboard, that went thru my code, is correct.

And of course last line of saving code is:
out.Close

sorry i didn't copy this line before

But again, all this happend only if I copy the image from pdf, QT player.
The images from any image viewer or from web sides works well.

thank you
 
Upvote 0

miga

Member
Licensed User
Longtime User
Thanx for answere.
Could you just check attached test?

Clipboard.zip - is small app that paste Clipboard image to an imageview and save it as png file (C:\temp)
Showcase_htm, pdf, mov - contain same image (pdf and mov are made from htm file)

Try to copy paste same image from htm, pdf, qtplayer to application.

html works
pdf and mov doesn't

Any idea why?
 

Attachments

  • Clipboard.zip
    16.8 KB · Views: 244
  • Showcase_pdf.zip
    296.6 KB · Views: 239
  • Showcase_mov.zip
    46.2 KB · Views: 248
  • Showcase_htm.zip
    200.5 KB · Views: 255
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
Strange indeed. Copying from QT, PDF or from Photoshop copied only a white image. It looks like it copied only the alpha of the image, and not the RGB.

I wanted to try with AWTRobot, but no success either, but not sure I did it properly:

B4X:
    If aw.ClipboardImageHas Then
        Dim str As InputStream
        str.InitializeFromBytesArray(aw.ClipboardImageGetAsByteArray, 0, aw.ClipboardImageGetAsByteArray.Length)
        Dim im As Image
        im.Initialize2(str)
        imageview1.SetImage(im)            ' insert into imageview
        str.Close
At least what you can do is write the image as a temp file, and load the image with fx.loadimage from your temp file...
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
For info, this code also produces the same result:

B4X:
Sub Paste_Action
    Dim clipboard As JavaObject
     clipboard.InitializeStatic("javafx.scene.input.Clipboard")
    Dim content As JavaObject = clipboard.RunMethod("getSystemClipboard", Null)
    If content.RunMethod("hasImage", Null) Then
        imageview1.SetImage(content.RunMethod("getImage", Null))
    End If
End Sub
 
Upvote 0

miga

Member
Licensed User
Longtime User
But when i save it over WriteToStream, it makes unreadible file. Check it in my app. It saves tmp.png in C:\temp
 
Upvote 0

miga

Member
Licensed User
Longtime User
I could read the png file with no problem

I can read only png from html. But not pdf nor mov. These looks like they are not propper png files. Only xnview can open it.
Neighter photoshop nor windows 10 photo viewver cannot open it.

I've tried pngTojpg library to convert saved png file to jpg with same result.
https://www.b4x.com/android/forum/threads/save-canvas-in-jpg.42839/#post-286094
From html image it was correct. From pdf and mov it created white jpg.

Something wrong is in Clipboard PASTE metod in B4J. Because to PASTE same Clipboard into Photoshop, Paint, etc is ok.
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
In this case, I think you should post a ticket directly on the Java page:
http://bugreport.java.com/

Because as Erel mentionned, this seems to be a Java / os related problem
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…