Image Rotation

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: Klaus, FourthWorld, heatherlaine, kevinmiller

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am
Location: Australia

Re: Image Rotation

Post by bidgeeman » Thu Sep 07, 2017 12:19 am

Yes...I tried that stack a while ago and had all sorts of problems with it trying to get it to work properly.
I will revisit though and post my results.
Bidge

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2028
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Image Rotation

Post by [-hh] » Thu Sep 07, 2017 12:35 am

Marginal note (Angle and resize in one step).
  1. In LC Builder one can do that easily.
  2. With an image of screen size one can do that also in LC Script by using javascript in a browser widget. See for example Jonathan's stack "Browser Widget Image Manipulator" in Sample Stacks.
BUT both methods need a computation for the smallest size they need when being rotated (if you wish to resize the parent of the image accordingly). This will be a (small) part of my talk at LC Global in November.

With smaller image sizes one can do that already perfectly in LC Script by accessing the raw imageData. For example my stack "Perspective Image Distortion 1.3.1" (see Sample Stacks) does this for more complicated 4-point-shapes than rectangles.
[There you can set the relativePoints of the control-poly to the rotated points of your image's rectangle.]

Probably in December I'll make a "Fast Perspective Distortion" stack.
shiftLock happens

MaxV
Posts: 1574
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Image Rotation

Post by MaxV » Thu Sep 07, 2017 12:22 pm

bidgeeman wrote: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 
   # I 
   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
You just need this:
########CODE to copy and paste#######
on scrollBarDrag pvalue
lock screen
# I have the original invisible image called "i1", but I always work wit a copy "i2"
put pValue/100 into sScale
if there is an image "i2" then delete image "i2"
clone image "i1"
set the name of the last image to "i2"
set the width of img "i2" to (round ( (the width of image "i1") * sScale)
set the height of img "i2" to (round (the height of image "i1") * sScale)
set the visible of image "i2" to true
set the imagedata of image "i2" to the imagedata of image "i2"
unlock screen
end scrollBarDrag
#####END OF CODE generated by http://tinyurl.com/j8xf3xq with livecode 9.0.0-dp-6#####
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am
Location: Australia

Re: Image Rotation

Post by bidgeeman » Thu Sep 07, 2017 1:07 pm

Wow...that worked brilliantly MaxV!
I can't place a "grab me" command on the duplicate image as it replaces itself and the code is lost.
Is there a way to stop the image defaulting position to the top left corner each time? I will have a
play around with it and see if I can work it out.
Thanks so much again.
Bidge

Klaus
Posts: 11009
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Image Rotation

Post by Klaus » Thu Sep 07, 2017 1:24 pm

Hi David,
bidgeeman wrote:I can't place a "grab me" command on the duplicate image as it replaces itself and the code is lost.
sure you can't add this to the cloned image in the script? I bet you can! :D

Hint:
...
put "on mousedown" & CR & "grab me" & CR & "end mousedown" into tScript
...
bidgeeman wrote:Is there a way to stop the image defaulting position to the top left corner each time?
Do you want it at the SAME loc(ation) as image "i1"?

Hint:
"binfile" erm, I mean "loc"! :D


Best

Klaus

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am
Location: Australia

Re: Image Rotation

Post by bidgeeman » Thu Sep 07, 2017 1:28 pm

LOL Klaus :)
I was just thinking about placing the grab me into the script but you beat me to it!
Might try and set image "i1" to the same loc as image "i2" so that they can be both
dragged around.
Thanks
Binfile...errr...Bidge :lol:

MaxV
Posts: 1574
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Image Rotation

Post by MaxV » Fri Sep 08, 2017 9:50 am

bidgeeman wrote:Wow...that worked brilliantly MaxV!
I can't place a "grab me" command on the duplicate image as it replaces itself and the code is lost.
???
When you clone an object, also the code is cloned.
Put all the code you need in the image "i1" and it will be cloned.
Otherwise, put the code in a custom property, for example:

Code: Select all

set the script of image "i2" to the templateScript1 of image "i1"
the custom property templateScript1 of image "i1" contains all.
Do you know what is a custom property? See http://livecode.wikia.com/wiki/Custom_properties
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am
Location: Australia

Re: Image Rotation

Post by bidgeeman » Fri Sep 08, 2017 10:06 am

Hi MaxV.
Thank you again. The code does get copied you are correct :)
I have struck only one small problem. For some reason the resolution of the original image is degraded and the copy becomes slightly pixelated when using the resize. I Don't know what could be causing it?
Bidge

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3338
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Image Rotation

Post by richmond62 » Sun Sep 10, 2017 12:58 pm

original image is degraded
This has been an ongoing problem with Livecode since the extinction of the dinosaurs,
and, at the moment at least, the way to go would seem to be with SVG widgets.

MaxV
Posts: 1574
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Image Rotation

Post by MaxV » Sun Sep 10, 2017 8:00 pm

bidgeeman wrote:Hi MaxV.
Thank you again. The code does get copied you are correct :)
I have struck only one small problem. For some reason the resolution of the original image is degraded and the copy becomes slightly pixelated when using the resize. I Don't know what could be causing it?
Bidge
If you enlarge an small image, it gets pixelated. But if the original image is bigger than the resized one, it can't be pixelated.
See also this post (there is a button to translate it in your mother tongue): http://livecodeitalia.blogspot.it/2014/ ... li_88.html .
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am
Location: Australia

Re: Image Rotation

Post by bidgeeman » Sun Sep 10, 2017 11:47 pm

Hi MaxV.
Once again thanks for your feedback :)
Regards
Bidge

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2342
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Image Rotation

Post by jmburnod » Sat Apr 27, 2019 1:42 pm

Hi All
Hermann said:
There is a stack "Angle and Resize an Image" (by Paul Hibbert) on "Sample Stacks" to that problem.
Yes for an image resized proportionaly mais no for a distorded image.
but I experimented "imageHandles89_v110" from hh and it works for this goal :D
You may download it on sample stacks
Thanks again Hermann
Jean-Marc

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”