okay guys. run this code and it explains the entire problem with display.save and steps you through how display.save() is broken and how in 30 seconds you can witness the problem I’m having in my App.
display.setStatusBar(display.HiddenStatusBar)
display.setDefault( “anchorX”, 0 )
display.setDefault( “anchorY”, 0 )
W=display.contentWidth
H=display.contentHeight
local ts=“What we have here is a colored grid that is 2 screens wide and 2 screens high. Move grid around to see that it’s larger than one screen.”
TextObject=display.newText({text=ts,x=0,y=0,width=W,height,0,font=native.systemFont,fontSize=H*.05,align=“left”})
–====================================================================
function saveAsImage()
TextObject:removeEventListener(“touch”,saveAsImage)
– save the display group
local gw=G_grid.width
local gh=G_grid.height
display.save( G_grid, { filename=“entireGroup.png”, baseDir=system.DocumentsDirectory, isFullResolution=true, backgroundColor={0,0,0,0} } )
– delete original display objects and group now that we have saved the file
local a
for a=1,#G_grid do
display.remove(D_grid)
end
display.remove(G_grid)
G_grid=nil
– now load the image and scale it down as defined by variable ‘sc’
local img = display.newImage(“entireGroup.png”, system.DocumentsDirectory)
local sc=50 – % percent of scale after load
local ts=“This displays the saved image at”…sc…"%. When set to 50%, this should fill screen, because 50% of 2x2 screens is a 1x1 filled screen. "
ts=ts…"However, if you analyze the ‘entireGroup.png’ file, you will see that it was saved with the proper resolution. "
ts=ts…“However, only what is visible on the screen at the time of the save is actually visible in the file itself.”
ts=ts…“This is not evident in a ‘preview’ program, but loading the ‘entireGroup.png’ file up in photoshop makes this clear.\n\n”
ts=ts…“Also, the loaded Image Resolution of “…img.width…“x”…img.height…” is actually smaller than the saved image file resolution of “…gw…“x”…gh…” because the non-displayed area which wasn’t visible on screen at the time of the display.save was transparent and is cropped when loaded.”
TextObject.text=ts
TextObject:toFront()
img.x = (W*.5)-(gw*sc*.01*.5)
img.y = (H*.5)-(gh*sc*.01*.5)
img.width=gw*sc*.01
img.height=gh*sc*.01
– this code allows you to move the newly loaded image around to see it’s size
local imgX,imgY,touchX,touchY,x,y --allow us to scroll and see the height of the example
local function scroll(event)
if event.phase==“began” then
imgX=img.x
imgY=img.y
touchX=event.x
touchY=event.y
elseif event.phase==“moved” then
if (imgY~=nil and touchY~=nil) or (imgX~=nil and touchX~=nil) then
x=imgX-(touchX-event.x)
y=imgY-(touchY-event.y)
img.x=x
img.y=y
end
elseif event.phase==“ended” then
imgX=nil
imgY=nil
end
end
img:addEventListener(“touch”,scroll)
end
TextObject:addEventListener(“touch”, saveAsImage)
–====================================================================
function createGrid()
– create grid to see the position of field
G_grid=display.newGroup()
D_grid={}
local z1,z2,x,y
for z1=1,20 do
for z2=1,20 do
if anchor==0 then
x=(z1-.5)*(W*.1)
y=(z2-.5)*(H*.1)
else
x=(z1-.5)*(W*.1)
y=(z2-.5)*(H*.1)
end
– create obj in grid
D_grid[#D_grid+1]=display.newRect(x,y,W*.1,H*.1)
D_grid[#D_grid]:setFillColor(z1*.05,z2*.05,(z1+z2)*.025)
– add object to group
G_grid:insert(D_grid[#D_grid])
end
end
--because the grid is 2 screens wide and high, let’s center what we see on group
G_grid.x=-W*.5
G_grid.y=-H*.5
– this code allows us to scroll the grid around, since it is larger than one screen
local img=G_grid
local imgX,imgY,touchX,touchY,x,y --allow us to scroll and see the height of the example
function scrollGrid(event)
if event.phase==“began” then
imgX=img.x
imgY=img.y
touchX=event.x
touchY=event.y
elseif event.phase==“moved” then
if (imgY~=nil and touchY~=nil) or (imgX~=nil and touchX~=nil) then
x=imgX-(touchX-event.x)
y=imgY-(touchY-event.y)
img.x=x
img.y=y
end
elseif event.phase==“ended” then
imgX=nil
imgY=nil
TextObject.text=“You can keep moving the image around if you like, but when you are ready, click on this text object to perform the display.save and display.newImage - after which the code will reload the saved image at 50% resolution. This can be adjusted in the code by modifying the variable ‘sc’.”
TextObject:toFront()
end
end
G_grid:addEventListener(“touch”,scrollGrid)
end
–====================================================================
createGrid()
TextObject:toFront()
I have the project in zip file if you’d like me to post it as a bug, again.