Page 2 of 3
Re: Image Rotation
Posted: Wed Sep 06, 2017 8:41 am
by MaxV
bidgeeman wrote:
Trying to import an image from a folder without using the loc so that it will rotate without distortion. problem is that when I import an image it is larger than the stack so I resize it on import. All good there but when I rotate the image with a slider it pops back to it's original size. How do you overcome this?
Resize the image, then:
Code: Select all
set the imageData of image myImage to the imageData of image myImage
then you can rotate it.
See
http://livecode.wikia.com/wiki/ImageData
Re: Image Rotation
Posted: Wed Sep 06, 2017 9:05 am
by bidgeeman
Hi MaxV.
Please forgive my new user ignorance but when the code refers to "myImage" does that have to be a pathway that refers to an actual image like: image "1" of stack Images? I tried that and it did not work?
Code: Select all
set the imageData of image "i1" of stack "ImageArea" to the imageData of image "i1" of stack "ImageArea"
I am using a slider to rotate the image
Code: Select all
set the angle of image "i1" of stack "ImageArea" to pScrollValue
Bidge
Re: Image Rotation
Posted: Wed Sep 06, 2017 11:01 am
by Klaus
Hi David,
you only need a long descriptor in scripts if the object is not on the current card of the defaultstack!
Don't forget to also add the CARD to it:
... imageData of image "i1" OF CD 2 of stack "ImageArea", if the "target" stack has more than one card!
Best
Klaus
Re: Image Rotation
Posted: Wed Sep 06, 2017 11:11 am
by bidgeeman
Hi Klaus. Yes. the imagage is on a separate card as per the script above but like I mentioned the set ImageData did not work. The image still shrank as it rotated.
Not sure what i did wrong?
Bidge
Re: Image Rotation
Posted: Wed Sep 06, 2017 11:17 am
by bidgeeman
I added the script to the image rotate slider and the image shrank away to nothing!!!
Code: Select all
set the imageData of image "i1" of stack "ImageArea" to the imageData of image "i1" of stack "ImageArea"
set the angle of image "i1" of stack "ImageArea" to pScrollValue
Bidge
Re: Image Rotation
Posted: Wed Sep 06, 2017 11:52 am
by MaxV
Please see this video, you make something wrong:
https://youtu.be/sSOPwx1YSFw
Re: Image Rotation
Posted: Wed Sep 06, 2017 12:38 pm
by bidgeeman
Ahh MaxV...thank you that worked well. I see that you left the image unlocked. My image was being locked by the code I was using and was not allowing the image to resize itself. I have had to rebuild the code I had originally to accommodate this and it works well for image rotating now but my resizing slider does not retain the last size of the image when it is set by the slider as this was relying on locking the image to the new size. How can I get around this?
Code: Select all
on scrollBarDrag pvalue
lock screen
put pValue/100 into sScale
set the width of img "i1" to the formattedWidth of img "i1"
set the height of img "i1" to the formattedWidth of img "i1"
set the lockloc of img "i1" to false
put the width of img "i1" into sWidth
put the height of img "i1" into sHeight
set the width of img "i1" to (sWidth * sScale)
set the height of img "i1" to (sHeight * sScale)
set the visible of img "i1" to true
unlock screen
end scrollBarDrag
EDIT: I have tried setting the locloc but it keeps reverting back as soon as the locloc is set back to false to allow the image to rotate.
Thanks again
Bidge
Re: Image Rotation
Posted: Wed Sep 06, 2017 1:13 pm
by bidgeeman
Here is my stack.
The resize button will not work if the image has been rotated as well as the image will not retain it's size after being resized.
I don't know what is wrong.
Bidge
Re: Image Rotation
Posted: Wed Sep 06, 2017 1:26 pm
by Klaus
Hi David,
use this script for the RESIZE scrollbar:
Code: Select all
on scrollBarDrag pvalue
lock screen
## Setting H and W also changes the LOC!
put the loc of img "i1" into tLoc
put pValue/100 into sScale
## The engine knows these things! :-)
set the width of img "i1" to round(the formattedWidth of img "i1" * sScale)
set the height of img "i1" to round(formattedHeight of img "i1" * sScale)
## So it does not walk around on the card:
set the loc of img "i1" to tLoc
unlock screen
end scrollBarDrag
No need to reset to formattedwidth/height and to un-/lock the size -> loclock
Best
Klaus
Re: Image Rotation
Posted: Wed Sep 06, 2017 1:30 pm
by bidgeeman
Hi Klaus.
That works fine but when I try to rotate the image with the rotate slider it pops back to it's original size?
EDIT: Sorry to be a pain but your code locks the image so that the rotation does not work. It's back to the original problem of the image resizing when it rotates.
Bidge
Re: Image Rotation
Posted: Wed Sep 06, 2017 1:52 pm
by bogs
Well, one sure way I can think of is to reduce the size of the image through code to the size you need, lets say 300x200 (works best if all your images are the same size or aspect), then copy it to a temp. folder or variable or container at that size, then import the smaller image.
Alternately, create actual thumbnails of all your images, and load the thumbnail.
Re: Image Rotation
Posted: Wed Sep 06, 2017 6:33 pm
by [-hh]
As I already wrote a few posts above:
There is a stack "Angle and Resize an Image" (by Paul Hibbert) on "Sample Stacks" to that problem.
Re: Image Rotation
Posted: Wed Sep 06, 2017 6:59 pm
by richmond62
This is going to sound really corny . . .
If and when I want images to rotate in Livecode, as anything but monochrome svg images screw up in a major way when rotated,
I make pre-rotated images in GIMP and import ALL of them (yeah, yeah, I know that causes an fairly 'expensive' overhead in terms
of hard-drive real-estate) and then call each one at a rotation point.
This guarantees the image comes out without fuzzy-wuzzy-do-dahs, parts of the image mission, resizing of the image and so on.
Re: Image Rotation
Posted: Wed Sep 06, 2017 7:26 pm
by bogs
Why would that sound corny? It is a means to an end, I've used it myself in other languages than this one. Of course, I'll avoid bringing up any reference to some of the things
I've done that
I considered corny, c'est la guerre
Re: Image Rotation
Posted: Wed Sep 06, 2017 7:49 pm
by Klaus
Hi David,
please check the stack that Hermann mentioned a couple of times, you need the workaround described in that stack to make it work!
It just does not work as we exspect it to do!
Here the direct link:
http://livecodeshare.runrev.com/stack/6 ... e-an-Image
Best
Klaus