How can I scaleDown the photo quality of captured with a device camera image?

In the my code I have a command:
[lua]media.show( media.Camera, onComplete , baseDir = system.DocumentsDirectory, filename = CameraShot.jpg" })[/lua]

The problem that user could capture a photo with a very high quality, so “CameraShot.jpg” will have too large size. And it will take a long time to upload the photo to the server.

How can I reduce with lua/Corona the “CameraShot.jpg” image quality and to receive the smaller file size before the upload of a just captured photo to the server?

[import]uid: 172733 topic_id: 34752 reply_id: 334752[/import]

If you have the image loaded, you can do something like:

-- compute the size of the new image, in this case no bigger than 200px wide  
local newScale = 200 / img.width  
  
-- scale the image  
img:scale(newScale,newScale)  

then save the new image back out. [import]uid: 199310 topic_id: 34752 reply_id: 138212[/import]

I was looking for something similar.

Rob, you mean using the display.save function?

rsc [import]uid: 181011 topic_id: 34752 reply_id: 138230[/import]

The display.save() function should take care of it. [import]uid: 199310 topic_id: 34752 reply_id: 138372[/import]

If you have the image loaded, you can do something like:

-- compute the size of the new image, in this case no bigger than 200px wide  
local newScale = 200 / img.width  
  
-- scale the image  
img:scale(newScale,newScale)  

then save the new image back out. [import]uid: 199310 topic_id: 34752 reply_id: 138212[/import]

I was looking for something similar.

Rob, you mean using the display.save function?

rsc [import]uid: 181011 topic_id: 34752 reply_id: 138230[/import]

@Rob thanks, it is really worked for me. I have additional issue with display.save() function on Android device only, I’ll open other ticket for that. [import]uid: 172733 topic_id: 34752 reply_id: 138779[/import]

@tatiana, what is the problem that you are facing? I also had some issues, may be I can help. [import]uid: 181011 topic_id: 34752 reply_id: 138807[/import]

The display.save() function should take care of it. [import]uid: 199310 topic_id: 34752 reply_id: 138372[/import]

@rsc on Android, after the command execution “display.save()” I see on the screen only just saved image with display.save() and all other display objects except this image disappear. The WA for it is to call system “applicationSuspend” and “applicationResume” events, but not always it works.

And on Android there also is additional issue. The resolution of the screen is too small for me for image quality that I want. So on iPhone I generate a new Image from the just-captured-photo-file with a large size (as 4000 x 3000 pxls) and isVisible = false property. I save this image as a new file and it works fine. On Android it saves me a black rect instead of the image because it cares because of isVisible = false property. I don’t know how can I reduce the image resolution onAndroid, but still to receive the good quality. [import]uid: 172733 topic_id: 34752 reply_id: 139131[/import]

@Rob thanks, it is really worked for me. I have additional issue with display.save() function on Android device only, I’ll open other ticket for that. [import]uid: 172733 topic_id: 34752 reply_id: 138779[/import]

@tatiana, what is the problem that you are facing? I also had some issues, may be I can help. [import]uid: 181011 topic_id: 34752 reply_id: 138807[/import]

@tatiana you are right. The display.save will only sabe the display object specified. If you want to save everything on the screen you will have to do the screenshot.

The display save actually works as a screenshot of only the specified object. So if the object is invisible, you will get a blank image.

I did not understand very well what you want to do in the overall. If you want to reduce file size to send the file via internet you should use the display.save(). If the image that you want to reduce the size will be only used on the own android device, you should have no problem using the screenshot or display.save, since the resolution that it will capture the image (assuming that you will have scaled the image to fill the entire screen before taking the screenshot or display.save) will be the maximum that the display can handle (so the user will not notice any difference).

rsc [import]uid: 181011 topic_id: 34752 reply_id: 139435[/import]

@rsc I agree, but this application will use many users with tablets/iPads, so we need also o keep a high quality resolution of the photos on our server. [import]uid: 172733 topic_id: 34752 reply_id: 139442[/import]

So a user can create image using the android phone and then upload the image to your server and that image could be downloaded to a table. Is that correct? [import]uid: 181011 topic_id: 34752 reply_id: 139485[/import]

@rsc yes, this is the flow
[import]uid: 172733 topic_id: 34752 reply_id: 139486[/import]

Hummm… as far as I know you really have only 2 options: (1) keep the original file size (resolution) (2) reduce the filesize but once you reduce, you will have a cap resolution limitation that will be the your android device screensize…

If you find any other solution, I would love to listen because it will be useful for me also.

rsc
[import]uid: 181011 topic_id: 34752 reply_id: 139488[/import]

For an app I am working on I am uploading the image at full resolution and then scaling it server side, not perfect but the best solution for the moment. [import]uid: 184705 topic_id: 34752 reply_id: 139507[/import]

Yes, that would works, but @tatiana was looking to reduce the image size before uploading so it would the upload would be faster…

How are you reducing the resolution on the server? Using C++? Do you have a code that could share?

rsc [import]uid: 181011 topic_id: 34752 reply_id: 139513[/import]

@rsc on Android, after the command execution “display.save()” I see on the screen only just saved image with display.save() and all other display objects except this image disappear. The WA for it is to call system “applicationSuspend” and “applicationResume” events, but not always it works.

And on Android there also is additional issue. The resolution of the screen is too small for me for image quality that I want. So on iPhone I generate a new Image from the just-captured-photo-file with a large size (as 4000 x 3000 pxls) and isVisible = false property. I save this image as a new file and it works fine. On Android it saves me a black rect instead of the image because it cares because of isVisible = false property. I don’t know how can I reduce the image resolution onAndroid, but still to receive the good quality. [import]uid: 172733 topic_id: 34752 reply_id: 139131[/import]