Recent

Author Topic: drop picture from browser  (Read 912 times)

mikutu

  • New Member
  • *
  • Posts: 16
drop picture from browser
« on: September 26, 2023, 04:39:35 am »
Drag and drop an image from the browser onto the application form.
How to catch this event?
Event OnDropFiles and property AllowDropFiles set and not working from this case.
Need a cross-platform solution (windows, linux)

Handoko

  • Hero Member
  • *****
  • Posts: 5374
  • My goal: build my own game engine using Lazarus
Re: drop picture from browser
« Reply #1 on: October 01, 2023, 06:05:46 am »
I don't think that is possible if the browser is Firefox, Chrome, Opera, Safari, etc. It may work only if you also write the browser. Maybe I'm not skilled enough, but that is what I believe.

TRon

  • Hero Member
  • *****
  • Posts: 3618
Re: drop picture from browser
« Reply #2 on: October 01, 2023, 07:05:53 am »
Drag and drop an image from the browser onto the application form.
How to catch this event?
Event OnDropFiles and property AllowDropFiles set and not working from this case.
Need a cross-platform solution (windows, linux)
Seem to work as expected for me.

However there is a big if. If the picture you want to drag actually contains a link to a webpage then the link (to that webpage) will be copied instead of the link to the actual image. And with that I also told you the other catch and that is that you only receive the link to the image (at least with Firefox on Linux as I only tested that). You would still have to actually download the image.

Code: [Select]
Memo1
files dropped
https://www.lazarus-ide.org/
files dropped
https://forum.lazarus.freepascal.org/index.php?action=profile;u=39078
files dropped
https://duckduckgo.com/?q=sample%20images&iax=images&ia=images&iai=https://cdn.photographylife.com/wp-content/uploads/2014/09/Nikon-D750-Image-Samples-2.jpg&t=ffab
The first "image" was the picture you see at the left top when you read these forums (links to a website, not the actual image).
The second "image" was the picture of user Handoko (links to a user profile webpage, not the actual image).
The last picture is a search for "sample images" at duck duck and I dragged and dropped the first image.

So, dragging and dropping images from a browser to a lazarus application might perhaps not be the most intuitive thing to do.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Memo1: TMemo;
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure FormDropFiles(Sender: TObject; const FileNames: array of string);
  18.   private
  19.   public
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. { TForm1 }
  30.  
  31. procedure TForm1.FormCreate(Sender: TObject);
  32. begin
  33.   Self.AllowDropFiles:= true;
  34. end;
  35.  
  36.  
  37. procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string);
  38. var
  39.   Filename: string;
  40. begin
  41.   Memo1.Append('files dropped');
  42.   for Filename in Filenames
  43.     do Memo1.Append(filename);
  44. end;
  45.  
  46. end.
  47.  

Also note that, depending on the platform, it is not possible to receive messages from non-elevated application to an elevated application. This comes into  play for users that have installed and run Lazarus as an elevated application (while the browser or other application you drag the image from is not running elevated).
« Last Edit: October 01, 2023, 07:33:43 am by TRon »
This tagline is powered by AI

Handoko

  • Hero Member
  • *****
  • Posts: 5374
  • My goal: build my own game engine using Lazarus
Re: drop picture from browser
« Reply #3 on: October 01, 2023, 07:50:10 am »
However there is a big if.

That is the problem. Most pictures on the web has a link, which is not linked to the image but to a web page.

 

TinyPortal © 2005-2018