Copy picture to clipboard

  1. 7 months ago

    Bryan D

    9 Mar 2017 Pre-Release Testers, Xojo Pro

    I am using CHartDirector, and I have the following code.

      Dim c as new Clipboard
        c.Picture=pic
      c.close

    The picture is on the clipboard in Windows, but if the user selects paste, any text on the clipboard is pasted. The user must select past special, then paste as device independent bitmap to get the picture. Is there a way to put the picture on the clipboard so that it is the default item pasted?

  2. Jeff T

    9 Mar 2017 Midlands of England, Europe

    You might deliberately try setting the text property to "" or nil

  3. Emile S

    9 Mar 2017 Europe (France, Strasbourg)

    Try to Paste in Windows Paint ?

    IMHO: the application where you want to Paste the Clipboard contents accept text, but not Image…

    BTW: are-you sure that pic is a Picture ? ;)

  4. Bryan D

    9 Mar 2017 Pre-Release Testers, Xojo Pro

    It pastes straight away in paint. In Microsoft Word or PowerPoint I have to select "Paste Special", "Device Independent Bitmap" or "Bitmap" to make it work. Without paste special, it tries to paste text.

  5. Emile S

    9 Mar 2017 Europe (France, Strasbourg)

    Bryan:

    this is how the Clipboard always worked: it paste the data accepted by the Target Application ;)

  6. Bryan D

    9 Mar 2017 Pre-Release Testers, Xojo Pro

    When I copy a picture from other applications I do not need to paste special in the target application.

  7. Emile S

    9 Mar 2017 Europe (France, Strasbourg)

    Only if the target application allow that.

    Last time I checked, I was able to paste either text (styled or not) and image into Word. ;)
    20 years ago or so…

  8. The clipboard can carry several things. I would follow Jeff's suggestion and set Clipboard.text to nil or "".

    Dim c as new Clipboard
        c.Picture=pic
        c.Text = ""
      c.close

    My guess is that if the Clipboard has both text and picture info, pasting it to Paint (for example) will past the picture info (because that is what it expects); but pasting it to Word or Powerpoint (that accept text as well as pictures - and many other things) will require to be very specific about what you want to paste (i.e. using PasteSpecial) or modifying the DefaultPaste option.

  9. 2 months ago

    Peter T

    Aug 11 Pre-Release Testers, Xojo Pro Oakland, CA USA

    I've just tried this, and it does NOT work. I am running a 2017r1 64-bit Windows application, and cannot get it to paste into MS Excel, even after setting the clipboard text to and empty string. In the pat, I had used the Monkeybread WindowsClipboardMBS object to get around this, but that also stopped working as of 2017r1.

    Has anyone found a solution to this?

  10. Eugene D

    Aug 11 Pre-Release Testers, Xojo Pro Canada scispec.ca

    @Peter T Has anyone found a solution to this?

    Hi Peter,

    Yes, I have had the same problem and there is something that is not working when copy-and-pasting pictures into Excel from Xojo.

    I have a simple workaround from my Excel 2016 Book, and it saves a picture from Xojo and then commands are used to load the picture from Excel. Its not copy-and-paste, its more like save-and-load. Here is the code from the book:

    Dim excel as new ExcelApplication
    excel.Workbooks.Add
    excel.visible = true
      
    Dim TheSaveFolder as String
    Dim f as FolderItem
    Dim aPict as new Picture(400, 300, 32)
    aPict.Graphics.DrawLine(1,1,100,100)
    f = SpecialFolder.Pictures.Child("Temp_Image.bmp")
    aPict.save(f, Picture.SaveAsWindowsBMP)
    excel.range("A1").Select_
    TheSaveFolder = f.AbsolutePath
    excel.ActiveSheet.Pictures.Insert(TheSaveFolder).select_
      
    MsgBox "Excel will now quit"
    excel.ActiveWorkbook.close false
    excel.Quit
      
    excel = nil
    
    Exception err as OLEException
        MsgBox err.message
  11. Joost R

    Aug 12 Pre-Release Testers, Xojo Pro The Netherlands

    There is a Feedback 48686 from @Bryan D and the status is FIXED AND VERIFIIED.
    I did some testing on Win10, xojo 2017R2b14 and it still did not work as expected. Downloaded the sample + graphics Bryan included in his FB and even this did not work.
    I looks like the xojo picture object is not accepted by the Windows clipboard, since the xojo clipboard object contains the data, according to the debugger.

  12. Joost R

    Aug 12 Pre-Release Testers, Xojo Pro The Netherlands
    Edited 2 months ago by Joost R

    As a work around I was thinking about saving the picture to a file and find a way to get the file copied into the clipboard.
    Saving is no problem, getting the file into clipboard by code is. Getting the binary stream is not the issue but put it in the clipboard in a way it's recognized as a pic ?

  13. Peter T

    Aug 14 Pre-Release Testers, Xojo Pro Oakland, CA USA

    Thanks, @Eugene D. Unfortunately, the users of our application may be pasting into any one of several target apps, not all of which can be addressed by Office Automation.

    @Joost R - This has been a long-standing problem which we worked around for years by using @ChristianSchmitz 's WindowsClipboardMBS object. For whatever reason, this stopped working as of 2017r1 or 1.1. I think Christian believes it may have to do with a change in Xojo drawing on Windows.

    "Paste Special" does work, though our users are not happy to have to take this extra step as the result of an "improvement" to our application. When we use the Xojo clipboard object, Excel always pastes the text, even if it's an empty string. Now, when we use the MBS object, Excel reports that it is unable to paste the picture data. So, there is apparently something in the Windows clipboard which tells the target to prefer the picture over the text, but the picture data put on the clipboard by the MBS code is currently somehow wrong.

    I'll sign on to the feedback case you linked to, Joost.

  14. Joost R

    Aug 15 Pre-Release Testers, Xojo Pro The Netherlands

    As of today FB 48686 says:
    "Reported fixed against Xojo2017r2."
    2017R2 release is scheduled for today. I will repeat my test on this issue tomorrow.

  15. Emile S

    Aug 15 Europe (France, Strasbourg)
    Edited 2 months ago by Emile S

    Robin stand up earlier today !
    Note to self: you do not now Robin’s usual stand up time, Emile, so why do you say “earlier today“ ?

    ;-)

  16. Peter T

    Aug 15 Pre-Release Testers, Xojo Pro Oakland, CA USA

    @Joost R 2017R2 release is scheduled for today. I will repeat my test on this issue tomorrow.

    I just tested it, and for me it STILL does not work. How about you, Joost?

  17. Joost R

    Aug 15 Pre-Release Testers, Xojo Pro The Netherlands

    yes ... eh .... NO ! it's still NOT WORKING. I really don't understand why and how FB 48686 has been closed as being fixed. Just not tested in the context of the problem. And why do you have to raise a new feedback ? Just say sorry and reopen this one, it's clear enough and reproducing this issue is just 4 short lines of code and Windows up and running. (Guess the last one was not tested)

    Have you started a new one Peter ? What number ?

    There is a big chance that the solution to the problem is much more difficult than the problem looks like. According to me, the Windows clipboard doesn't take the content of a xojo picture object as a picture.
    Hopefully the team will give extra attention to this one for the next release.

  18. Peter T

    Aug 15 Pre-Release Testers, Xojo Pro Oakland, CA USA

    @Joost R - I agree, but was sick today, so have nit created a new case. Feel free if you want to; otherwise, I can tomorrow, I hope.

    Interestingly, it did work for me ONCE when I first tested, but I couldn't get it to do it again. It does work when pasting into some target apps that don't handle text (like Paint), but not Excel or Word. I think that these apps prefer text on the clipboard, even if it's an empty string. But, past behavior of WindowsClipbardMBS suggests that there is some way to get these target apps to ignore the text.

    Is there a way to actually set the clipboard's text to NIL rather than an empty string?

  19. Christian S

    Aug 16 Pre-Release Testers, Xojo Pro Germany

    Well, you can put several items on the clipboard. But if you copy only a picture, you should not include text.
    And of course the clipboard should be cleared before.

    I can look again why my Class doesn't work any more.

  20. Peter T

    Aug 16 Pre-Release Testers, Xojo Pro Oakland, CA USA

    @ChristianSchmitz And of course the clipboard should be cleared before.

    The problem with that is that as far as I can tell, there is no way to do it.

    Unlike WindowsClipboardMBS, the Xojo Clipboard object has no "clear()" method. It appears that even setting the Clipboard.text property to an empty string is seen as a valid string by various target applications, and they prefer the text over the picture.

    If you could look into why your class stopped working, it would be much appreciated.

  21. Newer ›

or Sign Up to reply!