ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 PasteFromClipboard() doesn't work as I would expect
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Homer

USA
70 Posts

Posted - Dec 16 2021 :  17:47:17  Show Profile  Reply
If I open Windows File Explorer and copy a valid image file by right clicking the name and selecting "Copy", PasteFromClipboard always returns False. However, in Paint, if I "select all" and copy an image file, it will save as long as I add an appropriate file extension. I've included code snippets, but if you'd like to see the entire procedure if you wish.

I haven't found a demo that shows code for pasting so if someone can please suggest a course of action it would be very much appreciated.

Before I execute the code below, I make sure the file extension matches the ones allowed in my code. I also enable the "paste" menu, and therefore Ctrl-V, with:

mnuPaste1.Enabled := ImageEnView1.Proc.CanPasteFromClipboard();



This is just a code segment of what I'm having trouble with:

if ImageEnView1.Proc.PasteFromClipboard() then
  begin
    Application.ProcessMessages;
    if (Extn = '.JPG') or (Extn = '.JPEG') then
      ImageEnView1.IO.SaveToFileJpeg(gsDocManPath + NewFileName);
    if (Extn = '.PNG') then
      ImageEnView1.IO.SaveToFilePNG(gsDocManPath + NewFileName);
    if (Extn = '.BMP') then
      ImageEnView1.IO.SaveToFileBMP(gsDocManPath + NewFileName);
    if (Extn = '.TIF') or (Extn = '.TIFF')then
      ImageEnView1.IO.SaveToFileTIFF(gsDocManPath + NewFileName);
    if (Extn = '.PDF') then
      ImageEnView1.IO.SaveToFilePDF(gsDocManPath + NewFileName);
    Application.ProcessMessages;

  ...
 
    {save filename and path in the database.}

  end;

xequte

38176 Posts

Posted - Dec 17 2021 :  01:48:07  Show Profile  Reply
Hi

If you copy from Windows Explorer, a filename is added to the clipboard. This can only be pasted as a file to TImageEnFolderMView:

https://www.imageen.com/help/TImageEnFolderMView.CanPasteFilesFromClipboard.html


If you copy from MS Paint, a bitmap is added to the clipboard, which can be pasted to TImageEnView, using ImageEnView1.Proc.PasteFromClipboard();

It is not possible to paste a filename directly into a paint program or ImageEnView, but you could easily right a method to do this:

1. Use PasteFilesFromClipboard to get the list of files on the clipboard:

https://www.imageen.com/help/PasteFilesFromClipboard.html

2. If there's an image file in the list, load it into your TImageEnView.



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Homer

USA
70 Posts

Posted - Dec 17 2021 :  02:42:33  Show Profile  Reply
Thanks, Nigel. That looks like a very handy function. Since my app is for document management, the end user could try to paste a Word document, or a copy of an incoming email in addition to the image files ImageEn handles. I'll do some testing. Thank you very much for the tip.
Go to Top of Page

Homer

USA
70 Posts

Posted - Dec 17 2021 :  03:15:17  Show Profile  Reply
I've had a chance to experiment a bit. I copied a .BMP file from Windows explorer and pasted it into Open Office Writer. The picture appeared, not the file name. The same was true for a .JPG, .TIF, and .PNG. I'm sure I'm missing something from your earlier reply, but I would like my app to behave the was pasting does in Open Office Writer does (and other word processors I've used). I'm sure that's the way my users would want to paste documents they've saved to their HD.
Go to Top of Page

xequte

38176 Posts

Posted - Dec 17 2021 :  04:27:54  Show Profile  Reply
Hi

It wouldn't surprise me if some applications do a similar thing to what I suggested above (using the filename to load the content).

There are many examples on the web of iterating the content of the clipboard if you want to see what formats are there, e.g.

http://delphiexamples.com/clipboard/viewclipboard.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Homer

USA
70 Posts

Posted - Dec 18 2021 :  16:56:24  Show Profile  Reply
Sometimes I have to overcome my own stupidity. I was making this much harder than it needed to be. As you suggested, I used the clipboard object to find the fully resolved file name. Then simply copied it into my "document" folder, changing the name in the process. I have a function that creates unique names with some human understandable info in the name. Then it was a simple matter to display the "new" file using ImageEn. Sometimes my light bulb is very dim. Nigel, thanks for pointing me in the correct direction.

If it were only graphic files, it could have been done in a half-dozen lines of code. Mine was a little more complicated because I had to accept Word and other kinds of documents. Even so, It was much easier than I was trying to make it. Thanks again.
Go to Top of Page

xequte

38176 Posts

Posted - Dec 18 2021 :  19:38:19  Show Profile  Reply
Hi

Nice work finding a good solution to this.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: