Copy an image from Browser widget into LiveCode

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

golife
Posts: 103
Joined: Fri Apr 02, 2010 12:10 pm

Re: Copy an image from Browser widget into LiveCode

Post by golife » Mon Jan 25, 2021 6:50 pm

I have tested again and the problem continues to be present:

Code: Select all

on mouseUp
   import snapshot from widget "browser"
   set the text of image "image" to the text of the last image
   if the number of images > 1 then delete the last image
end mouseUp
The last image does not contain any data. If the lockloc of the target image is not set then the target image will resize to the size of the snapshot. But there is no data.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Copy an image from Browser widget into LiveCode

Post by bogs » Mon Jan 25, 2021 8:35 pm

I asked if you used the code I posted (directly from the dictionary) which was ...

Code: Select all

#  copy this code and paste it directly into the handler you are using to import the snapshot from...

local myRect, winID
put the rect of widget "browser" into myRect
put the windowID of stack "o" into winID
import snapshot from rect myRect of window winID  ## could also use export, btw...


I tested that code as shown in Win 10, it worked there, but having re-read most of this thread, I wonder if we are working at cross purposes.

On re-reading, it sounds like you are trying to grab one image from a web page, not as I thought, an image *of* the web page.

If the 2nd interpretation is correct, then Richard is write, parsing the html will most likely net your goal.
Image

golife
Posts: 103
Joined: Fri Apr 02, 2010 12:10 pm

Re: Copy an image from Browser widget into LiveCode

Post by golife » Tue Jan 26, 2021 2:31 pm

Thank you for testing. Highly appreciated )))

I am trying to grab the picture of the browser widget, whether that is a website or anything else. I can do this using my screen rect technique explained above. Directly I cannot do it. So, calculating the screen rect from the widget's rect works.

On my computer (Windows 10) it definitely does not work using "import snapshot from widget "browser".

In all other cases, I would need to know the screen rect of any other object and then could also make a screenshot. Such screen rect can be obtained from calling the system for a system window. In case of websites, yes, it can be done in another way.

The main question here is the browser widget.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Copy an image from Browser widget into LiveCode

Post by bogs » Tue Jan 26, 2021 4:15 pm

golife wrote:
Tue Jan 26, 2021 2:31 pm
I am trying to grab the picture of the browser widget, whether that is a website or anything else.

I can do this using my screen rect technique explained above. Directly I cannot do it. So, calculating the screen rect from the widget's rect works.
Did you try the code I posted above then? It captures a snapshot of the browser widget directly much like the code you posted. The main difference (from my pov) is that it doesn't build the rect manually by adding offsets from screen global as you did, instead, it is shorter because it uses the rect based on the stack location using the windowID.

I tested it on Win 7 through 10, it works here to do what your describing as far as I can tell.
Image

golife
Posts: 103
Joined: Fri Apr 02, 2010 12:10 pm

Re: Copy an image from Browser widget into LiveCode

Post by golife » Tue Jan 26, 2021 5:48 pm

Thank you again. Yes, I am aware of the windows id, and as I mentioned, I can get the rect of any window of the Window desktop using it's id. It is a good solution and better than calculating the relative rect.

The problem here is the LC command addressing the widget itself: Import snapshot from widget "browser" -- which should simply work. That was the actual reason even posting anything since it was mentioned in previous posts.

Yes?/No? :roll:

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Copy an image from Browser widget into LiveCode

Post by bogs » Tue Jan 26, 2021 6:00 pm

put "N" into Bool :D

Dunno if you saw this post earlier...
bogs wrote:
Sun Jan 24, 2021 10:27 pm
golife wrote:
Sun Jan 24, 2021 8:14 pm
Simply using "import snapshot from widget "browser" does not work, because the browser content has it's own layer.
aPic_exportSnapshot.png
It seems more likely to me that something has gone awry with snapshot, and it probably needs a bug report filed. Just my opinion :D
In other words, skip the browser altogether, and put an ordinary field on a card, then import the snapshot from the rect of the field. Without specifying the window the field is relative too, you get exactly the same result.

From the dictionary in Lc 6.x -
To import a snapshot for a portion of a stack you use the form:
import snapshot from rect[angle] of window windowID
Where windowID is the windowID property of the required stack.
I'm not entirely sure how much farther that same goes back, I'll leave it to you as an excercize since I am going to eat lunch now :D

On the other side of that, at least now I am pretty sure it is not a bug :mrgreen:
Image

Post Reply

Return to “Internet”