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
 Paste a file from clipboard into ImageEn
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Homer

USA
70 Posts

Posted - Dec 15 2021 :  15:38:24  Show Profile  Reply
When pasting a file from the clipboard, I don't know how to determine how to save it. It could be PDF, JPG, PNG, TIF, BMP, or whatever. I know enough how to tell if the clipboard contains text rather than an image, but if it is an image, I don't know how to tell what kind. I'm using Delphi 2007.

When I say I need to know how to save it, I mean I need to determine if I should use:

ImageEnView1.IO.SaveToFileJpeg(NewFileName);
ImageEnView1.IO.SaveToFilePNG(NewFileName);
ImageEnView1.IO.SaveToFilePDF(NewFileName);

Or something else.

Homer

USA
70 Posts

Posted - Dec 15 2021 :  18:20:38  Show Profile  Reply
I found the answer. This function returns info about the "copied" file. In my case, there will only be one file in the clipboard, so the following code calls the "GetPasteValue" function. I'm sure you get the idea.

SourceFile := GetPasteValue ;
PastedFileName := ExtractFileName(SourceFile);
SourceExtn := UpperCase(ExtractFileExt(PastedFileName));



Function TfrmMain.GetPasteValue: String;
var
   f: THandle;
   buffer: Array [0..MAX_PATH] of Char;
   i, numFiles: Integer;
   sl: TStringList;
begin
  if Clipboard.HasFormat(CF_HDROP) then
  begin
    sl := TStringList.Create;
    try
      f:= Clipboard.GetAsHandle( CF_HDROP ) ;
      If f <> 0 Then
      Begin
        numFiles := DragQueryFile( f, $FFFFFFFF, nil, 0 ) ;
        sl.Clear;
        for i:= 0 to numfiles - 1 do
        begin
          buffer[0] := #0;
          DragQueryFile( f, i, buffer, sizeof(buffer)) ;
          sl.add( buffer ) ;
        end;
      end;
      if sl.Count > 0 then
         Result := sl.strings[0];

    finally
      Clipboard.close;
      FreeAndNil(sl);
    end;
  end
  else
  Result := 'NO CF_HDROP';
end;
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: