image processing

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
berndg
Posts: 17
Joined: Thu Mar 22, 2012 3:37 pm

image processing

Post by berndg » Thu Mar 22, 2012 4:03 pm

Pardon the newbie question. I struggle with the sparse documentation in the area, or maybe I haven't found it yet. I wonder if someone here can kick me into the right direction, so here's what I hope to accomplish:

1. import an image, but do not show it
2. create a copy of that image
3. cut a specific rectangle from that image
4. assign the snippet to a button's icon

Following is a little tester that I wrote:

Code: Select all

on mouseUp
	put the width of button "b1" into w
	put the height of button "b1" into h

	create image "skin"
	put image "test.jpg" into image "skin"
	crop image "skin" to 50, 50, 50+w, 50+h
        -- future: manipulate image "skin" further (apply gloss and reflection effects)
	set the icon of button "b1" to image "skin"
end mouseUp
I can now see the new image on the card, not as a skin on button "b1". Image "skin" appears at the location specified by the rectangle, but the crop appears to be taken from the centre of the source image.

Suggestions and pointers will be much appreciated.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: image processing

Post by sturgis » Thu Mar 22, 2012 4:12 pm

You should go through this thread http://forums.runrev.com/viewtopic.php? ... nipulation and download the stack from the sig of cbodel in that thread.

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: image processing

Post by Klaus » Thu Mar 22, 2012 6:02 pm

Hi Bernd,

yep, "crop" will always work from the center of the image.
So this is not the tool for you :-)

I would use "import snapshot" with something like this_

Code: Select all

put the width of button "b1" into w
put the height of button "b1" into h

## No need for an extra image!
##create image "skin"

## Now postion your image to the topleft corner of the card = 0,0
## This way we can calculate the RECT that we want to SNAP a SHOT from :-)
set the topleft of image "test.jpg" to 0,0

lock screen

## I think that is what you wanted?
import snapshot from rect (50,50,50+w,50+h) of img "test.jpg"

## Now hide the new image
hide last image
put the ID of last image to tIcon
set the icon of button "b1" totIcon
unlock screen
Tested and works! :D


Best

Klaus

berndg
Posts: 17
Joined: Thu Mar 22, 2012 3:37 pm

Re: image processing

Post by berndg » Thu Mar 22, 2012 7:07 pm

Ah, import snapshot, just the ticket!

Here's the final tester - now onwards to the real thing.

Code: Select all

on mouseUp
	lock screen
	set showName of button "b1" to false
	put the rectangle of button "b1" into theRect
	import snapshot from rectangle theRect of image "test.jpg" 
	hide last image
	set the icon of button "b1" to the ID of last image
	unlock screen
end mouseUp
Many thanks for the assistance.

Post Reply