Can I add an overlay to an image and save it again?

Hi,

I need to take a picture from the camera and save it to file which I already know how to do. But then I would like to take a png file to add as an overlay to brand the image like I want and then save the image again in the app. I prefer the final image to be either JPG or PNG if it has to be. I did a search and could not find anything on this.

Thanks!

Warren
[import]uid: 184193 topic_id: 35331 reply_id: 335331[/import]

You don’t need Enterprise for that…
What about this?

x = display.newImage("image.png");  
y = display.newImage("overlay.png");  
z = display.newGroup();  
z:insert(x);  
z:insert(y);  
display.save(z,"newimage.png");  

EDIT:
I just realized that you were attempting to add an overlay on a camera image. While the code above will work for smaller images, it’ll probably be a stretch to get it to work for full-resolution images from the camera. :frowning: [import]uid: 70847 topic_id: 35331 reply_id: 140453[/import]

It should still work @ingemar, he would just need to scale things accordingly.
[import]uid: 199310 topic_id: 35331 reply_id: 140482[/import]

Thanks for the code example. I will try this. The image from the camera will be saved as an image first. So I was wondering about what Rob said as far as scaling. Each camera may save the image a different size. How should I handle this? Should I resize the camera picture to be the same width as the overlay since it is like a frame overlay? I think I saw where you can crop an image also.

Thanks,

Warren
[import]uid: 184193 topic_id: 35331 reply_id: 140647[/import]

Hi, I finally got to test the code above and it displayed correct on the screen. But it did not save the image. I was running this on my PC in the simulator. So will it save the image on my computer in the source directory since I specified the ResourceDirectory? I did not get any error messages in the simulator output.

Thanks

Warren

x = display.newImage("woman.png")  
y = display.newImage("box.png")  
z = display.newGroup()  
z:insert(x)  
z:insert(y)  
local baseDir = system.ResourceDirectory  
display.save(z,"newimage.jpg",baseDir)  

[import]uid: 184193 topic_id: 35331 reply_id: 140766[/import]

You can’t save to the resource directory. It’s read-only.
display.save() can save to the following directories:

system.DocumentsDirectory (default) system.TemporaryDirectory system.CachesDirectory [import]uid: 70847 topic_id: 35331 reply_id: 140773[/import]

Thanks, I’m learning something new every day! So I guess I can’t see this work on the simulator. And if I run it on the phone I cannot browse to those locations to see if it saved either huh? I’m using Android on a Samsung Galaxy SII.

Warren
[import]uid: 184193 topic_id: 35331 reply_id: 140774[/import]

I looked in the sandbox files and saw it was saved there. So it works!!

Thanks again for your help.

Warren
[import]uid: 184193 topic_id: 35331 reply_id: 140779[/import]

You don’t need Enterprise for that…
What about this?

x = display.newImage("image.png");  
y = display.newImage("overlay.png");  
z = display.newGroup();  
z:insert(x);  
z:insert(y);  
display.save(z,"newimage.png");  

EDIT:
I just realized that you were attempting to add an overlay on a camera image. While the code above will work for smaller images, it’ll probably be a stretch to get it to work for full-resolution images from the camera. :frowning: [import]uid: 70847 topic_id: 35331 reply_id: 140453[/import]

It should still work @ingemar, he would just need to scale things accordingly.
[import]uid: 199310 topic_id: 35331 reply_id: 140482[/import]

Thanks for the code example. I will try this. The image from the camera will be saved as an image first. So I was wondering about what Rob said as far as scaling. Each camera may save the image a different size. How should I handle this? Should I resize the camera picture to be the same width as the overlay since it is like a frame overlay? I think I saw where you can crop an image also.

Thanks,

Warren
[import]uid: 184193 topic_id: 35331 reply_id: 140647[/import]

Hi, I finally got to test the code above and it displayed correct on the screen. But it did not save the image. I was running this on my PC in the simulator. So will it save the image on my computer in the source directory since I specified the ResourceDirectory? I did not get any error messages in the simulator output.

Thanks

Warren

x = display.newImage("woman.png")  
y = display.newImage("box.png")  
z = display.newGroup()  
z:insert(x)  
z:insert(y)  
local baseDir = system.ResourceDirectory  
display.save(z,"newimage.jpg",baseDir)  

[import]uid: 184193 topic_id: 35331 reply_id: 140766[/import]

You can’t save to the resource directory. It’s read-only.
display.save() can save to the following directories:

system.DocumentsDirectory (default) system.TemporaryDirectory system.CachesDirectory [import]uid: 70847 topic_id: 35331 reply_id: 140773[/import]

Thanks, I’m learning something new every day! So I guess I can’t see this work on the simulator. And if I run it on the phone I cannot browse to those locations to see if it saved either huh? I’m using Android on a Samsung Galaxy SII.

Warren
[import]uid: 184193 topic_id: 35331 reply_id: 140774[/import]

I looked in the sandbox files and saw it was saved there. So it works!!

Thanks again for your help.

Warren
[import]uid: 184193 topic_id: 35331 reply_id: 140779[/import]