Reduce image resolution

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
shoshinsha
Posts: 35
Joined: Fri Jul 18, 2014 5:17 am

Reduce image resolution

Post by shoshinsha » Tue Dec 30, 2014 6:21 am

Hi All,

Would like to know if there is any way to reduce image resolution?

I'm using mobilePickPhoto to take/pick a photo, but the maxWidth and maxHeight parameters are only available on iOS devices.
So I'm trying to figure out a way to do so for Android.
Although I'm able to downsize the image "physically" (the height and width on screen), but when the image is uploaded (to our server), it is still of the original size.

Thanks and regards,
Vikki.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Reduce image resolution

Post by Simon » Tue Dec 30, 2014 6:35 am

Hi Vikki,
After you resize the image

Code: Select all

set the imagedata of image "myImage" to the imagedata of image "myImage"
Super cool :)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

shoshinsha
Posts: 35
Joined: Fri Jul 18, 2014 5:17 am

Re: Reduce image resolution

Post by shoshinsha » Tue Dec 30, 2014 11:16 am

Hi Simon,

Thanks for the workaround. But if I use the set imagedata function my image will be broken after uploaded to the server...
And the image is sometimes not "processed" (image area is shown as blank after taking a picture). The image could not be "reference" to another card too.

On my stack:

Code: Select all

on upload_take_photo
   mobilePickPhoto "camera", 500, 667
   if the result = "" then
      put the last image into image "mypic" of card "campaign1"
      send "resize_img" to me in 0 second ##the function to resize the image
      set the imagedata of image "mypic" of card "campaign1" to the imagedata of image "mypic" of card "campaign1"
      ...
end upload_take_photo
The image after uploaded: http://vo.my/p/4U/4UWISP/f/Image.jpg

Thank you.

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Reduce image resolution

Post by MaxV » Tue Dec 30, 2014 4:58 pm

Why do you send the message "resize_image"?

Code: Select all

on upload_take_photo
   mobilePickPhoto "camera", 500, 667
   if the result = "" then
      put the last image into image "mypic" of card "campaign1"
     resize_img
      set the imagedata of image "mypic" of card "campaign1" to the imagedata of image "mypic" of card "campaign1"
      ...
end upload_take_photo
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

William Jamieson
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 212
Joined: Fri Feb 01, 2013 1:31 am
Contact:

Re: Reduce image resolution

Post by William Jamieson » Wed Dec 31, 2014 12:07 am

I ran into this the other day. For some reason my Livecode crashes when I have a 4MB photo placed on the stack as the last image after using MobilePickPhoto

Here was my solution that worked really well, really fast, and ready to be put into the server.

I downsize the photo immediately into a size that is reasonable by using

Code: Select all

MobilePickPhoto "camera"
put the long id of the last image of this card into tID
set the layer of tID to 1 --I remove the image from sight
wait 10 milliseconds with messages --This takes a lot of processing power for my little android processor so I let it take a breath
lock screen
put myIdealHeight / the height of tID into tRatio --Maintains the aspect ratio
put the width of tID into tW
export snapshot of tID at size ((tW * tRatio), myIdealHeight) to myPhotoVariable as JPEG
delete tID
unlock screen

---Now do what ever you need with the binFile, put it in a URL, a folder, post it to a server, put it in an image object, send it to another mobile device, store it in a custom property (don't know why you would do that) etc. Once the file size is smaller, it is easier for the processor to work with so you wont have to worry about lag time. 

This code hasn't failed yet. Even tried using on my tablet from times BC and still worked. Takes about 50-80 milliseconds for me.

Hope this helps!

Cheers,

-Will

shoshinsha
Posts: 35
Joined: Fri Jul 18, 2014 5:17 am

Re: Reduce image resolution

Post by shoshinsha » Mon Jan 05, 2015 2:29 am

It works! :D :D :D
Thanks, Will!!

Post Reply