Rotating And Saving An Image.

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Googie85
Posts: 188
Joined: Tue Aug 05, 2014 10:07 am

Rotating And Saving An Image.

Post by Googie85 » Fri Sep 16, 2022 4:55 am

Hi Guys!!!

I am trying to rotate an image 270 Degrees and then save the image back to an image file. The code is:

Code: Select all

on mouseDown
   set the visible of image "TEST" to true
   
   put the screenrect into blah
   put specialFolderPath("documents") & slash & "Nav.jpg" into GEST
   
   export snapshot from rect blah to file GEST as JPEG   
   
   put "binfile:"&GEST into POL
   put URL POL into image "TEST"
   
   set the angle of image "TEST" to 270
   
   //SAVE IMAGE CODE HERE
   
   put specialFolderPath("documents") & slash & "NavYY.jpg" into GEST1
   put "binfile:"&GEST1 into HYU
   export image "TEST" to URL HYU
   
   //
   
   set the URL of widget "Browser" to GEST1
   
end mouseDown


The resulting file (export image "TEST" to URL HYU) turns out to be a 6.5MB file that is corrupted and cannot be viewed. Is there a simpler way to rotate an image file that I am missing?

Many Thanks,

Googie.

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

Re: Rotating And Saving An Image.

Post by richmond62 » Fri Sep 16, 2022 9:18 am

Screen Shot 2022-09-16 at 11.18.44 AM.png
-

Code: Select all

on mouseUp
   answer file "Select image:"
   if the result is not cancel then
      import paint from file it
      set the name of the last control to "XYZ"
   end if
   set the left of img "XYZ" to 10
   clone img "XYZ"
   set the name of the last control to "XXX"
   set the loc of img "XXX" to 600,200
   set the angle of img "XXX" to 270
   ----
    ask file "Choose where you wish to save your image"if the result = "cancel" 
  then exit mouseUp
  else
   export snapshot from img "XXX" to file it & ".png" as PNG
end if
delete img "XYZ"
delete img "XXX"
end mouseUp
Attachments
Round we go.livecode.zip
Stack.
(1.05 KiB) Downloaded 22 times
Last edited by richmond62 on Fri Sep 16, 2022 9:29 am, edited 1 time in total.

Googie85
Posts: 188
Joined: Tue Aug 05, 2014 10:07 am

Re: Rotating And Saving An Image.

Post by Googie85 » Fri Sep 16, 2022 9:26 am

I have no problem rotating the image, rather, saving the image to a .jpg or .png .

Any ideas?

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

Re: Rotating And Saving An Image.

Post by richmond62 » Fri Sep 16, 2022 9:30 am

Try the stack I have just uploaded: that will save PNG images.
-
Screen Shot 2022-09-16 at 11.34.30 AM.png

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

Re: Rotating And Saving An Image.

Post by jmburnod » Fri Sep 16, 2022 12:26 pm

Hi,
You maybe have to add "as PNG" or "as JPG" after this line
export image "TEST" to URL HYU
Beat regards
Jean-Marc
https://alternatic.ch

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

Re: Rotating And Saving An Image.

Post by richmond62 » Fri Sep 16, 2022 2:33 pm

The whole problem probably has got to do with NOT being allowed to export
images on Android.

stam
Posts: 1521
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Rotating And Saving An Image.

Post by stam » Fri Sep 16, 2022 6:06 pm

richmond62 wrote:
Fri Sep 16, 2022 2:33 pm
The whole problem probably has got to do with NOT being allowed to export
images on Android.
Is that really the case? A quick glance at the code above suggest that Googie85 is trying to save to specialFolderPath("documents") which should be doable on mobile? (unless it isn't permitted to save files to the sandboxed Documents folder on Android?).

I wonder if it's not the export that is failing but the 'set the URL' statement sent to the browser widget (last line)?
Dictionary for Browser Widget wrote:In particular, file: URLs must be of the form file://absolute path, and the path should be URL-encoded.
As far as i can tell the URL to the browser widget is passed in format specialFolderPath("documents") & slash & "<filename>" which a) will miss the "file://" bit and b) won't be URL-encoded...

HTH
S.
Last edited by stam on Fri Sep 16, 2022 6:10 pm, edited 1 time in total.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6696
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Rotating And Saving An Image.

Post by jacque » Fri Sep 16, 2022 6:08 pm

richmond62 wrote:
Fri Sep 16, 2022 2:33 pm
The whole problem probably has got to do with NOT being allowed to export
images on Android.
That's news to both me and the documentation. I think Jean-Marc identified the problem. The docs say:

Code: Select all

 If you don't specify a format, the file is exported as PBM, PGM, or PPM.
I think those formats are old. Specifying an image format will produce a more modern and compact image file.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Rotating And Saving An Image.

Post by richmond62 » Fri Sep 16, 2022 8:24 pm

PBM: Perfect Bowel Movement . . . 8)

I wonder if anyone remembers those image formats.

I remember learning about JPG in 1993.

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

Re: Rotating And Saving An Image.

Post by Klaus » Fri Sep 16, 2022 8:42 pm

richmond62 wrote:
Fri Sep 16, 2022 8:24 pm
I wonder if anyone remembers those image formats.
I do! :-)

I learned to know these formats from Metacard in 1992.
Never heard of them before and actually never after that.

I thinke these are pixel formats from the UNIX "stone age".

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

Re: Rotating And Saving An Image.

Post by richmond62 » Fri Sep 16, 2022 8:54 pm

Yes, they are mentioned in the RunRev version 1 dictionary.

Post Reply

Return to “Android Deployment”