Image selection?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Ericjp
Posts: 9
Joined: Thu May 08, 2008 8:14 am

Image selection?

Post by Ericjp » Thu May 08, 2008 12:36 pm

I'm new to Revolution, just had it a few weeks. I've been able to do quite a bit with graphics, but there's one problem I can't seem to solve.

I load a jpeg file from disk and display it as an image. Just as an example, it's picture of a scene with a car in the foreground.

What I want to do is be able to select the car by clicking a number of points around it (as you can do in apps such as Photoshop). Once selected, I want to copy the selection as a new image on a higher level in exactly the same place, so there is no obvious change. I can then move another graphic onto the scene which will show in front of the main image but behind the car.

I hope I've explained this ok. I've tried using the polygon tool, backgroundPattern etc, but can't get anywhere. I'd be grateful for any pointers or suggestions from more knowledgeable users of Rev.

Many thanks.

Eric

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sun May 11, 2008 4:34 pm

Hi Eric,

It is possible to do this. First, create a polygon. Make the polygon transparent, fill the inside of it with black. Export to an image. Use this image to set the maskdata of the original picture. Export the original picture, which now has the same form as the polygon.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Ericjp
Posts: 9
Joined: Thu May 08, 2008 8:14 am

Post by Ericjp » Tue May 13, 2008 10:42 am

Hello Mark. Many thanks for your reply. Yes, that all makes sense, and I'm working my way through it.

I've found one problem, which is to do with selecting the polygon tool. The dictionary states for the polygon:
Comments:
When using the Polygon tool, the cursor is a crosshairs shape (over images) or an arrow (anywhere else).
I get a crosshairs shape over the whole card and not just the image I'm working on, so once the polygon tool is selected, I can't click on anything else!

Eric

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Tue May 13, 2008 10:46 am

Hi Eric,

It is not a simple as selecting the polygon tool manuall and drawing one. You need to create a graphic and set the rect of that graphic to the rect of the original picture. Now you can draw a polygon on top of the original picture.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Ericjp
Posts: 9
Joined: Thu May 08, 2008 8:14 am

Post by Ericjp » Tue May 13, 2008 11:23 am

Hi Mark.

Thanks to your original reply, I've actually achieved the result I wanted. As you suggested, I've created a new image the same size as the original, gone into polygon tool mode, drawn a polygon, set the inside to black, and used that for the maskData. Its all worked ok.

But I still only have the crosshairs on the screen when I select the polygon tool. So now I need to work out a way of getting back into browse mode after I've drawn the polygon.

Thanks again.

Eric.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Tue May 13, 2008 11:32 am

Eric,

Maybe you can use the mouseMove message and check whether the mouseLoc is within the image rect. If so, choose the polygon tool. Choose the browse tool otherwise.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Ericjp
Posts: 9
Joined: Thu May 08, 2008 8:14 am

Post by Ericjp » Wed May 14, 2008 2:50 pm

Hi Mark. Thanks again for your suggestions.

The problem I'm having is getting back to the browser tool. All the 'mouse...' messages seem to only work when in browser mode, so once I've chosen the polygon or dropper tool, I can't work out a way to reset to the browser. Well, that's not quite accurate, as I've written a little handler which chooses the browser when any key is pressed.

I'd like a way to do it by just clicking outside the image I'm working on.

Quite a learning curve, isn't it?

Eric.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed May 14, 2008 3:11 pm

Eric:

Code: Select all

on mouseMove
  if the mouseLoc is within the rect of grc x then choose browse tool
end mouseMove
Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Ericjp
Posts: 9
Joined: Thu May 08, 2008 8:14 am

Post by Ericjp » Wed May 14, 2008 5:01 pm

Mark, you're a genius!

It turned out to be a bit more complicated because I already had a mousemove doing something else in the graphic (allowing the graphic to be grabbed and moved around within the confines of a group). But I got there in the end. I can now select either a polygon tool or a dropper tool and have then operate only within the rect of the image.

Great stuff! Once again, many thanks for your help.

Eric.

Post Reply