display.save() bug or i don't understand how it works....

Hi.

I tried this little code:

local path=system.TemporaryDirectory local fileName="1.jpg" local newFileName="1\_snap.jpg" local img=display.newImageRect(fileName, path, 320,172) img.x=display.contentWidth\*.5 img.y=display.contentHeight\*.5 local function saveWithDelay() display.save( img, { filename=newFileName, baseDir=path, isFullResolution=true} ) end timer.performWithDelay( 1000, saveWithDelay )

the new file is always bigger than the original.

i’ve 3 files:

1.jpg (320x172)

1@2X.jpg (640x344)

1@4X.jpg (1280x688)

file created:

1_snap.jpg (1365x734)

is this the normal behavior?

Best regards,

Carlos.

@Carlos,

When content scaling is enabled, display.save() saves the image in the device’s native resolution. For instance, if this method is used to save a 100×200 pixel display object, it may have more actual pixels when saved on a device with higher resolution.

http://docs.coronalabs.com/daily/api/library/display/save.html

Also, I’m suspicious of the ‘isFullResolution’ doucmentation.

isFullResolution (optional)

Boolean. If true, the image is not scaled to the size of the screen of the device.

To me, the name implies the opposite of what the docs say…now I’ll have to examine this.

Have you tried a number/variety of different settings?  If so which?

For the sake of your experiments, I’d temporarily diable the @2x, @3x business in config.lua till you get a handle on scaling the saved image.  i.e. Too many variables while you experiment only makes the problem less tractable.

Also, please tell us the goal you are trying to achieve. i.e. What outcome do you want?

i’m downloading a file from a server then i put the image inside a snapshot group

my goal is to get a partial snapshot of an image so i can use it in my app. all went well till i used display.save()

i thought it was the snapshot was doing something wrong…but i striped all my code and reduce it so i could find the problem.

my question is. is this a normal behavior of the display.save()? if so its useless. i want a precise dimension, if i can’t controll that i cant use it. i tried a lot of combinations. isFllResolution=false or true dont resolve the problem. i tried changing my config.lua. still with same problem.

i know i can display.newImageRect with the dimensions i need but it’s waste of space saving images with larger size i need and my app will have more than 1000 images…

btw thx for the help roaminggamer :wink:

after some work this is the best i can do for what my propose is (save a croped image to a file with the resolution i wanted):

local dir = system.TemporaryDirectory local centerX=display.contentWidth\*.5 local centerY=display.contentHeight\*.5 local w, h, c = 300, 200, 100 -- width, height, croped local original="1.jpg" local croped="2.jpg" local img = display.newImageRect(original, w,h) local snapshot = display.newSnapshot( w, 100 ) snapshot.group:insert( img ) snapshot.x=centerX snapshot.y=centerY snapshot.width = w\*display.contentScaleX snapshot.height = c\*display.contentScaleY display.save( snapshot, croped, dir) snapshot:removeSelf() snapshot=nil

still is not the exact size i wanted, but close enought.

@Carlos,

When content scaling is enabled, display.save() saves the image in the device’s native resolution. For instance, if this method is used to save a 100×200 pixel display object, it may have more actual pixels when saved on a device with higher resolution.

http://docs.coronalabs.com/daily/api/library/display/save.html

Also, I’m suspicious of the ‘isFullResolution’ doucmentation.

isFullResolution (optional)

Boolean. If true, the image is not scaled to the size of the screen of the device.

To me, the name implies the opposite of what the docs say…now I’ll have to examine this.

Have you tried a number/variety of different settings?  If so which?

For the sake of your experiments, I’d temporarily diable the @2x, @3x business in config.lua till you get a handle on scaling the saved image.  i.e. Too many variables while you experiment only makes the problem less tractable.

Also, please tell us the goal you are trying to achieve. i.e. What outcome do you want?

i’m downloading a file from a server then i put the image inside a snapshot group

my goal is to get a partial snapshot of an image so i can use it in my app. all went well till i used display.save()

i thought it was the snapshot was doing something wrong…but i striped all my code and reduce it so i could find the problem.

my question is. is this a normal behavior of the display.save()? if so its useless. i want a precise dimension, if i can’t controll that i cant use it. i tried a lot of combinations. isFllResolution=false or true dont resolve the problem. i tried changing my config.lua. still with same problem.

i know i can display.newImageRect with the dimensions i need but it’s waste of space saving images with larger size i need and my app will have more than 1000 images…

btw thx for the help roaminggamer :wink:

after some work this is the best i can do for what my propose is (save a croped image to a file with the resolution i wanted):

local dir = system.TemporaryDirectory local centerX=display.contentWidth\*.5 local centerY=display.contentHeight\*.5 local w, h, c = 300, 200, 100 -- width, height, croped local original="1.jpg" local croped="2.jpg" local img = display.newImageRect(original, w,h) local snapshot = display.newSnapshot( w, 100 ) snapshot.group:insert( img ) snapshot.x=centerX snapshot.y=centerY snapshot.width = w\*display.contentScaleX snapshot.height = c\*display.contentScaleY display.save( snapshot, croped, dir) snapshot:removeSelf() snapshot=nil

still is not the exact size i wanted, but close enought.