Page 1 of 1

image processing

Posted: Thu Mar 22, 2012 4:03 pm
by berndg
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.

Re: image processing

Posted: Thu Mar 22, 2012 4:12 pm
by sturgis
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.

Re: image processing

Posted: Thu Mar 22, 2012 6:02 pm
by Klaus
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

Re: image processing

Posted: Thu Mar 22, 2012 7:07 pm
by berndg
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.