[Resolved] change the black background when using display.save

Hi max here ,

I am using the display.save option in my project. but every picture i take gets a black background ,this wont do for me you see as i am plotting black lines, circles, rect etc.

I tried to use to turn the background to white as per advice on the forum
display.setDefault( “background”, 255, 255, 255, 255) but this doesn’t seem to work either

only other way is that i can put a white rect in the beginning to the display group but that will give me a larger image than i need and i need to crop it which is hectic.

Is there any other way to change the background im running out of options

Thankyou [import]uid: 115284 topic_id: 25861 reply_id: 325861[/import]

White background captures just fine - did you forget to insert it into the group perhaps? Is there a reason you are trying to use the method above rather than simply displaying a white rectangle to use as the background?

Run this - it will save and display fine with the white rect behind it.
[lua]g = display.newGroup()

local background = display.newRect( 0, 0, 200, 60 )
g:insert(background)

local image_array = {}

for i = 1, 3 do
image_array[i] = display.newRect( i*50, 20, 20, 20 )
image_array[i]:setFillColor(255,0,0)
g:insert(image_array[i])
end
local baseDir = system.DocumentsDirectory
display.save( g, “entireGroup.jpg”, baseDir )

local test = display.newImage(“entireGroup.jpg”, baseDir)
test.x, test.y = 100, 100[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 25861 reply_id: 104605[/import]

Hi

What I am doing in my project is using touch to draw an image say cirlce on the screen . I only want the image of the circle so i just insert the circle into the group and save it.

circle might be of different size so i dont want a background that is larger than the image itself.

the background of the output when i do display.save i want to change that from black to white cause the black circle is not visible with the black bg.

[import]uid: 115284 topic_id: 25861 reply_id: 104624[/import]

Try to think about how you can solve the problem using what you already know - you know if you use no background it will be black, so you know you need to use a background. You don’t want users to see it? Put one in and remove it immediately.

Try running this code;

[lua]local baseDir = system.DocumentsDirectory

g = display.newGroup()

local myCircle = display.newCircle(160,220,30)
myCircle:setFillColor(255, 0, 0)
g:insert(myCircle)

local function saveImage()
local background = display.newRect( 0, 0, myCircle.width, myCircle.height )
background.x, background.y = myCircle.x, myCircle.y
g:insert(background)
background:toBack()
display.save( g, “entireGroup.jpg”, baseDir )
background:removeSelf()
end

local function loadImage()
local test = display.newImage(“entireGroup.jpg”, baseDir)
test.x, test.y = 100, 100
end

local btn1 = display.newRect( 10, 300, 60, 30 )
local btn2 = display.newRect( 250, 300, 60, 30 )

btn1:addEventListener(“tap”, saveImage)
btn2:addEventListener(“tap”, loadImage)[/lua]

Button left saves, button on right loads. Will work fine I believe.

Peach :slight_smile: [import]uid: 52491 topic_id: 25861 reply_id: 104809[/import]

Thank you peach,
Its a good idea for the circle , I found a complex solution for a line its working ok now. [import]uid: 115284 topic_id: 25861 reply_id: 105252[/import]