display.save : Unable to narrow down the proper image size

Hello all,

I am building a graphic editor with Corona and everything is going smoothly for the most part. However, there is a case when I need to create a mask dynamically and I need to ensure that both width/height are divided by 4 to be compliant to mask usage (no problem here either)

I can create very complex mask with the snapshot API and specify a width/height that is divided by 4. 

The problem is when I save the file (display.save), it is not saved with the actual width/height that I’ve specified but instead the file dimensions is adjusted based on the content scaling of the app. I understand that. Unfortunately, this is sometime screwing the actual size of the mask file that is no longer compliant to the divided by 4 rules as the number can even be odd on some devices.

Does any one, would know a magic recipes so, my saved file is still with a width/height divided by 4 ?

For sure, the best way would be for Corona to offer the ability to specify when saving to save as absolute, but I do not think it is possible.

My scaling mode in config.lua is “adaptive”

local maskGroup = display.newSnapshot( 128, 256) -- doing here a few operations to be create the mask display.save( maskGroup , { filename = maskFileName, jpegQuality = 1, captureOffscreenArea=true, backgroundColor={0,0,0,0} } )

Any help would be greatly appreciated.

Hi, 

Yes display.save does not do the best job here.

Prepare the image with the mask, take a snapshot, save that.

Works for me.

Tip, make the object alpha 1 just before you take the snapshot, then alpha 0, and it wont show on screen.

Hi,

This is not really helping me, as I need to save my mask (created in a snaphot) and then load it dynamically to apply to a group, so I can crop easily my image or other graphical item into it. The manipulation is all realtime so, your proposal would not work in that case…

It is the scaling.  You need to take note of the scaling

  • display.contentScaleX
  • display.contentScaleY

,and adjust the size of your image before saving it.  

I had to deal with this extensively when writing the now defunct EAT project. 

-Ed

You can download my icon generator here (uses SSK to save files):

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2017/09/iconGenerator.zip

The app takes an existing images and resizes it to a number of targets sizes then saves them in the system.DocumentsDirectory

Run this in a ‘borderless 640x960’ simulated device and it should work flawlessly, then experiment with other sizes to see it break.

It should be able to handle a number of odd sizes, but not all.

Anyways, I hope it gives you a starting place to work this out.

@roaminggame, yes I do take into account the scaling to adjust the size, but regardless in some sizes, it breaks. I will look at your example in case I miss something.Thanks for your help.

Questions:

  1. Is your scaling something other than 1.0?  If so, what is it?
  2. What does your config.lua file look like.  i.e. What settings are you using?
  3. What settings are you using in your build.settings file for desktop app?
  4. Are you seeing this problem in the simulator and/or your desktop final build?

I am always using the “adaptive” scaling in config and I’ve been testing solely on the simulator at this point with different device sizes. But you are right, let me run a few tests as windows app and on a few Android and iOS devices to see if I get the same result. I sometime forget that the simulator is not always that reliable with some API.

I will keep you posted and thanks for reminded me that.

Ok, all good when running as a native windows app or on the device. It seems on the simulator there is a few caveat.

Yeah,  between the simulator scaling to fit the screen and the way it deals with ‘adaptive’ scaling I think you’re better off confirming final results with a build.  At least for this case.

Best of luck on your project!

Tip:

When developing EAT I actually did this.

  1. When running on the simulator, I used ‘letterBox’ scaling as well as a size that was sure not to be re-scaled in the simulator.  I also simulated using a ‘custom device’ which had the benefit of no border and a controlled resolution.

  2. When running desktop build I used ‘adapative’.

Thanks for your tip, I am going to try it :slight_smile:

Hi, 

Yes display.save does not do the best job here.

Prepare the image with the mask, take a snapshot, save that.

Works for me.

Tip, make the object alpha 1 just before you take the snapshot, then alpha 0, and it wont show on screen.

Hi,

This is not really helping me, as I need to save my mask (created in a snaphot) and then load it dynamically to apply to a group, so I can crop easily my image or other graphical item into it. The manipulation is all realtime so, your proposal would not work in that case…

It is the scaling.  You need to take note of the scaling

  • display.contentScaleX
  • display.contentScaleY

,and adjust the size of your image before saving it.  

I had to deal with this extensively when writing the now defunct EAT project. 

-Ed

You can download my icon generator here (uses SSK to save files):

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2017/09/iconGenerator.zip

The app takes an existing images and resizes it to a number of targets sizes then saves them in the system.DocumentsDirectory

Run this in a ‘borderless 640x960’ simulated device and it should work flawlessly, then experiment with other sizes to see it break.

It should be able to handle a number of odd sizes, but not all.

Anyways, I hope it gives you a starting place to work this out.

@roaminggame, yes I do take into account the scaling to adjust the size, but regardless in some sizes, it breaks. I will look at your example in case I miss something.Thanks for your help.

Questions:

  1. Is your scaling something other than 1.0?  If so, what is it?
  2. What does your config.lua file look like.  i.e. What settings are you using?
  3. What settings are you using in your build.settings file for desktop app?
  4. Are you seeing this problem in the simulator and/or your desktop final build?

I am always using the “adaptive” scaling in config and I’ve been testing solely on the simulator at this point with different device sizes. But you are right, let me run a few tests as windows app and on a few Android and iOS devices to see if I get the same result. I sometime forget that the simulator is not always that reliable with some API.

I will keep you posted and thanks for reminded me that.

Ok, all good when running as a native windows app or on the device. It seems on the simulator there is a few caveat.