media.selectPhoto bloating image file size?

Hi,

In my app, the user can select a photo from the photo library and use it in the app. The photo is saved in the app’s Document Directory with the following code:

 media.selectPhoto({ mediaSource = media.PhotoLibrary, listener = onComplete, origin = event.target.contentBounds, destination = { baseDir = documentsDirectory, filename = fileName }, permittedArrowDirections = { "any" }, })

The problem is that the image size of the saved test photo that I am using becomes 6 MB on the device, when in fact the image itself is only 1,9 MB. Is media.selectPhoto adding something to the image before saving it?

I assume both original and destination images are jpg. If so, perhaps the original was compressed much whereas the corona save not so much?

Another thought. If the device has high ppi perhaps the image is being upscaled to fit screen.

@anaqim:

The photo was taken with the same device as where it is stored (iPhone 6S) and it is a jpg. The filename used when saving it in the Document Directory is also jpg, so there should be no format conversion or scaling issue there.

I checked the file size with a photo metadata investigator app on the device and it said 1,9 MB. I also downloaded it to my Mac using Image Capture and it was 1,9 MB then as well.

Could it be that the jpg is compressed on the device and that Corona, when saving it compresses it less?

@Corona staff:

I would appreciate if Corona staff could confirm this if that is the case…

Hi,
Can u add the  type=“image”   in media block.
 

[lua]

media.selectPhoto(

    {

        

        mediaSource = media.SavedPhotosAlbum,

        destination = { baseDir=system.DocumentsDirectory, filename=“DemoImage.jpg”, type=“image” } ,

        listener = imageSelectedListener,

    })

[/lua]

Note: I just want to make sure that this is not creating the issue.It is not a solution but just to make sure things.

  • Assif

@assif_tiger:

I cannot find the “type” parameer in the docs. Is this some kind of undocumented feature?

Hi,
I apologize for the above, but probably I used it in my previous work a year before.

Perhaps the doc might have been updated.

Still, I will try the demo & let u know.

Assif

Ok, thanks!

It sounds like we may be changing the compression when we save the local copy. I can ask engineering to stop what they are working on and look this up, but it doesn’t sound like it’s that huge of an issue. 

Rob

@Rob:

I understand of course that this may not be the most highly prioritized issue that your engineers may be working on but it would be nice if they could look at it when time permits.

However, just to understand what is going on: could you/they please just confirm that it is indeed a question of changing compression so that I don’t chase ghosts in my code…

Perhaps an idea to let users set own default jpg compression level somwhere, which every api respect, but probably not a huge issue no

@divmonkey
A new script with a single load and save shoukd confirm that as when nothing else is left, thats what is happening

@anaqim:

The code in my original post is all there is in this respect. Nothing is explicitly done with the image and I confirm the saved image file size  directly on the device via file sharing (on iTunes). My spontaneous conclusion would be that it has to do with the Corona compression but I cannot be sure.

What else could it be? Dont think youll get corona technicians to take a break at what they are doing to verify this for you.

Id say you got your answer. Its pretty common jpg behaviour as although there is a default setting on jpg compression, there is no standard so its up to each app developer how to handle this.

Please keep in mind that it is the holidays and getting any Engineering time right now is difficult. I looked around through the source today and we are just calling the device’s native features. I couldn’t track down where it came back. So I’ll have to ask someone to follow through with this, but it may be a bit before I can even get someone to look at this.  It might be best for you to file a bug report. Make sure to include a project that demonstrates the issue and the engineers can build, install, run and see the issue. Put that in a .zip file and use the Report a Bug link at the top of the page.

Rob

I assume both original and destination images are jpg. If so, perhaps the original was compressed much whereas the corona save not so much?

Another thought. If the device has high ppi perhaps the image is being upscaled to fit screen.

@anaqim:

The photo was taken with the same device as where it is stored (iPhone 6S) and it is a jpg. The filename used when saving it in the Document Directory is also jpg, so there should be no format conversion or scaling issue there.

I checked the file size with a photo metadata investigator app on the device and it said 1,9 MB. I also downloaded it to my Mac using Image Capture and it was 1,9 MB then as well.

Could it be that the jpg is compressed on the device and that Corona, when saving it compresses it less?

@Corona staff:

I would appreciate if Corona staff could confirm this if that is the case…

Hi,
Can u add the  type=“image”   in media block.
 

[lua]

media.selectPhoto(

    {

        

        mediaSource = media.SavedPhotosAlbum,

        destination = { baseDir=system.DocumentsDirectory, filename=“DemoImage.jpg”, type=“image” } ,

        listener = imageSelectedListener,

    })

[/lua]

Note: I just want to make sure that this is not creating the issue.It is not a solution but just to make sure things.

  • Assif

@assif_tiger:

I cannot find the “type” parameer in the docs. Is this some kind of undocumented feature?

Hi,
I apologize for the above, but probably I used it in my previous work a year before.

Perhaps the doc might have been updated.

Still, I will try the demo & let u know.

Assif

Ok, thanks!