Another problem with display.save()

Hi there!
I use display.save() trying to save an image that i want to use later.
My problem is this: When I save the image, this one is what i see instead of watching the elements I've got before pressing the save button, i.e., I want to save the image but not to watch the result (image.jpg) in my iPhone screen.

Is it possible?, what am I doing wrong?

This is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
display.setStatusBar( display.HiddenStatusBar )
local ui=require("ui")
 
local width,height=display.contentWidth,display.contentHeight
local background=display.newImage("background.jpg")
local rect=display.newRect(0,(height-80),width,height)
rect:setFillColor(174,78,0)
local my_image=display.newImage("foo.png",90,90)
 
local function saving()
        local baseDir = system.DocumentsDirectory
        local toSave=display.newGroup()
        toSave:insert(background)
        toSave:insert(my_image)
        display.save(toSave,"image.jpg",baseDir)
end
 
local save_button = ui.newButton{
        default = "save_button.png",
        over = "save_button.png",
        onRelease = saving,
        emboss = true
}
 
save_button.x=width/2
save_button.y=height-35

can you elaborate a bit more.

c.

Hello!

Thanks for your reply, Carlos!
That's all my code.
Before pressing the save button that's what I can see in the simulator: www.ogrove.net/before.png
And after pressing the save button, that's what I see: www.ogrove.net/after.png

What I want is to save the image but watch the scene and work as before pressing the button.
Now, pressing the button the image is what I get and I can't interact with the app.

Could you tell me what am I doing wrong?

TIA

thats because you are creating a new group and inserting the image into the group. the stacking order of the group will put the image on top.

ergo why you can't go back

c.

That's right!, but I need to create a new group, isn't? I think it is not possible to do it other way...
Must I send the image to the bottom of the group? Is it a good practice?
If I try to remove the image I don't see anything at the scene.
I'm confused... I thing it would possible to save the image and don't added it to the stack (only create a jpg file)

or you could just do

1
2
3
toSave:insert(display.newImage("foo.jpg",0,0))
display.save(toSave,"image.jpg",baseDir)
toSave:RemoveSelf();

Mmmmm... well, I need to save the background too (because can't save png images), and my idea is to add more elements to the group "toSave"
I don't know if I am understanding you well, but I think with your code I only could save my foo.png image, isn't it?

As you have made noticed, I am a newbie and I appreciate so much your help.

This is my code now, after your instructions:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
display.setStatusBar( display.HiddenStatusBar )
local ui=require("ui")
 
local width,height=display.contentWidth,display.contentHeight
local background=display.newImage("background.jpg")
local rect=display.newRect(0,(height-80),width,height)
rect:setFillColor(174,78,0)
local my_image=display.newImage("foo.png",90,90)
 
local function saving()
        local baseDir = system.DocumentsDirectory
        local toSave=display.newGroup()
        local my_image2=my_image
        toSave:insert(display.newImage("background.jpg"))
        toSave:insert(display.newImage("foo.png",90,90))
        display.save(toSave,"image.jpg",baseDir)
        toSave:removeSelf()
end
 
local save_button = ui.newButton{
        default = "save_button.png",
        over = "save_button.png",
        onRelease = saving,
        emboss = true
}
 
save_button.x=width/2
save_button.y=height-35

On this way, it seems it is a duplication of code, isn't it?

Carlos??
Anyone??

call display.captureScreen( ) then the save the resulting image.

hide all elements that you don't want on the screen right before calling display.captureScreen( )

thens how them

c.

Thanks, Carlos!
I'll try as you say and I tell you.

views:1464 update:2011/10/1 9:04:19
corona forums © 2003-2011