Saving image larger than screen

Hello,

I am wanting to merge two images together because I am adding a watermark image to the first image. I do this by the code below and works fine. The problem is the image is larger than the screen. The documentation said the entire image must be on the screen. Mine was not and it was clipped when it was saved. Is there any possible way to do this?

Is the only way to do this is to scale the image to fit in the screen and then save it? I know how to use the scale method but I do not know how to make it just fit in the screen. Does anyone know how to use scale to have the image fit just inside the screen? I want to keep the aspect ratio of the image I am scaling.

Thanks!

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

[import]uid: 184193 topic_id: 35800 reply_id: 335800[/import]

I’ve been doing some math where I can use display.newImageRect to display the image at a specific size and I am able to get it to fit inside the screen to save. The only problem is the largest I can set it is 320 which is the dispplay.viewableContentWidth. I have the app set to the 320x480 size. Is that the biggest I can go with this?

Thanks
[import]uid: 184193 topic_id: 35800 reply_id: 142409[/import]

Hi @warrenwsav,
Do you have all of the images at multiple sizes to use with “newImageRect”? Or do you just want to scale one image file to fit the screen? Can you please post your updated code with the method you describe in the follow-up post?

Thanks,
Brent [import]uid: 200026 topic_id: 35800 reply_id: 142413[/import]

Hi Brent,

below is the code I am using to resize and display. The main image is the picture I captured from the camera which is big. The brand1.jpg is a small image which is a watermark I want to add to the top left of the image. So far all of this works until I try removing the image and brand from the screen. It does not go any further. So I have an error somewhere. Can you help? I GREATLY appreciate it!

Warren

 -- Load image captured by camera  
 myImage = display.newImage( "CameraShot.jpg",system.TemporaryDirectory)  
 -- Get sizes for image to fit in screen  
 local w = myImage.width  
 local h = myImage.height  
 local w2 = display.viewableContentWidth  
 local h2 = 0  
 h2 = (h \* w2) / w  
 myImage:removeSelf()  
  
 -- Reload image with size to fit on screen  
 local myimage2 = display.newImageRect( "CameraShot.jpg",system.TemporaryDirectory, w2, h2 )  
 myimage2.x = 160  
 myimage2.y = 240  
  
 -- Add brand image to top right corner of image  
 -- Manually placing image right now  
 myBrand = display.newImage( "brand1.jpg",system.ResourceDirectory)  
 myBrand.x = 70  
 myBrand.y = 43  
 local z = display.newGroup()  
 z:insert(myImage2)  
 z:insert(myBrand)  
 -- Save combined images to file  
 local baseDir = system.TemporaryDirectory  
 display.save(z,"newimage.jpg",baseDir)  
 -- Remove image - this does not work!!! \<\<\<\<\< -- Tried two different ways, removeSelf did not work for some reason  
 -- Neither did moving the images off the screen  
 myImage2.x = 4000  
 myBrand.y = 4000  
 myImage2:removeSelf()  
 myBrand:removeSelf()  
  
 -- Reload new image to screen  
 -- Not getting down to here so I commented lines out  
 --local myImage3 = display.newImageRect( "newimage.jpg",system.TemporaryDirectory, 150, 130 )  
 --myImage3.x = 105  
 --myImage3.y = 268  

[import]uid: 184193 topic_id: 35800 reply_id: 142417[/import]

It seems the code stops at or after the display.save method. I looked in the documentation and did not see where you could add a listener event for it so I can continue code there.

Any thoughts?

Thanks!
[import]uid: 184193 topic_id: 35800 reply_id: 142420[/import]

Hi @warrenwsav,
Can you tell me the error message you’re receiving? Or is it just silently failing with no error?

By the way, with this watermarked image assembled, is your intent to save it to the photo library? Or elsewhere, like a dedicated directory?

Brent [import]uid: 200026 topic_id: 35800 reply_id: 142455[/import]

I am not getting any error. It just seems to stop after saving the new image. I am saving it to the temporary directory where I save the picture from the camera. I had used the same code to combine and save a new image before and it worked locally with the new image saved in the sandbox for testing.

I am trying to add a watermark to the camera image before I upload it. Like I said, it seems everything is working right up to the Save method. I can’t test this locally in the Corona program because I am using the camera and Facebook for this

Thanks for your help!

Warren
[import]uid: 184193 topic_id: 35800 reply_id: 142457[/import]

Any ideas?

Thanks!!!
[import]uid: 184193 topic_id: 35800 reply_id: 142505[/import]

Hi @warrenwsav,
So just to recap, this IS working properly in the Corona Simulator? The image is loaded, scale determined, second image loaded, then it is saved to the temporary directory? And then on the Simulator, it removes the image properly, but on a device, not? I’m trying to figure out if this is a coding issue or a device issue. Which device and OS are you testing on?

Brent

[import]uid: 200026 topic_id: 35800 reply_id: 142525[/import]

Hopefully this will help. I cannot run my full project on the simulator because it uses the camera and Facebook before it gets to this step. What I did run on the simulator was the 7 lines of code I posted in the first thread that combines two images and saves them. I don’t know if this part is working on the page I posted because it is on the phone. It gets down to where it saves the file and stops. It does not add the text in the lines after or anything else. I was wondering if the save method stops any other code from running so I ran the 7 lines of code with other stuff after for testing and it ran. So not sure why it stops in the code I have posted.

I am 99.9% sure this is not a device problem since I can run the test code and it works. And I doubt it is an error in the corona software. So I do not know why it stops at the Save method. I can send you the entire project to compile and run on an android phone if you want. I am using a Samsung Galaxy S2 and so far everything works fine on it. I will load the test on it to make sure it works fine but sure it does.

Thanks for your help on this.

Warren
[import]uid: 184193 topic_id: 35800 reply_id: 142529[/import]

I’ve been doing some math where I can use display.newImageRect to display the image at a specific size and I am able to get it to fit inside the screen to save. The only problem is the largest I can set it is 320 which is the dispplay.viewableContentWidth. I have the app set to the 320x480 size. Is that the biggest I can go with this?

Thanks
[import]uid: 184193 topic_id: 35800 reply_id: 142409[/import]

Hi @warrenwsav,
Do you have all of the images at multiple sizes to use with “newImageRect”? Or do you just want to scale one image file to fit the screen? Can you please post your updated code with the method you describe in the follow-up post?

Thanks,
Brent [import]uid: 200026 topic_id: 35800 reply_id: 142413[/import]

Hi Brent,

below is the code I am using to resize and display. The main image is the picture I captured from the camera which is big. The brand1.jpg is a small image which is a watermark I want to add to the top left of the image. So far all of this works until I try removing the image and brand from the screen. It does not go any further. So I have an error somewhere. Can you help? I GREATLY appreciate it!

Warren

 -- Load image captured by camera  
 myImage = display.newImage( "CameraShot.jpg",system.TemporaryDirectory)  
 -- Get sizes for image to fit in screen  
 local w = myImage.width  
 local h = myImage.height  
 local w2 = display.viewableContentWidth  
 local h2 = 0  
 h2 = (h \* w2) / w  
 myImage:removeSelf()  
  
 -- Reload image with size to fit on screen  
 local myimage2 = display.newImageRect( "CameraShot.jpg",system.TemporaryDirectory, w2, h2 )  
 myimage2.x = 160  
 myimage2.y = 240  
  
 -- Add brand image to top right corner of image  
 -- Manually placing image right now  
 myBrand = display.newImage( "brand1.jpg",system.ResourceDirectory)  
 myBrand.x = 70  
 myBrand.y = 43  
 local z = display.newGroup()  
 z:insert(myImage2)  
 z:insert(myBrand)  
 -- Save combined images to file  
 local baseDir = system.TemporaryDirectory  
 display.save(z,"newimage.jpg",baseDir)  
 -- Remove image - this does not work!!! \<\<\<\<\< -- Tried two different ways, removeSelf did not work for some reason  
 -- Neither did moving the images off the screen  
 myImage2.x = 4000  
 myBrand.y = 4000  
 myImage2:removeSelf()  
 myBrand:removeSelf()  
  
 -- Reload new image to screen  
 -- Not getting down to here so I commented lines out  
 --local myImage3 = display.newImageRect( "newimage.jpg",system.TemporaryDirectory, 150, 130 )  
 --myImage3.x = 105  
 --myImage3.y = 268  

[import]uid: 184193 topic_id: 35800 reply_id: 142417[/import]

It seems the code stops at or after the display.save method. I looked in the documentation and did not see where you could add a listener event for it so I can continue code there.

Any thoughts?

Thanks!
[import]uid: 184193 topic_id: 35800 reply_id: 142420[/import]

Hi @warrenwsav,
Can you tell me the error message you’re receiving? Or is it just silently failing with no error?

By the way, with this watermarked image assembled, is your intent to save it to the photo library? Or elsewhere, like a dedicated directory?

Brent [import]uid: 200026 topic_id: 35800 reply_id: 142455[/import]

I am not getting any error. It just seems to stop after saving the new image. I am saving it to the temporary directory where I save the picture from the camera. I had used the same code to combine and save a new image before and it worked locally with the new image saved in the sandbox for testing.

I am trying to add a watermark to the camera image before I upload it. Like I said, it seems everything is working right up to the Save method. I can’t test this locally in the Corona program because I am using the camera and Facebook for this

Thanks for your help!

Warren
[import]uid: 184193 topic_id: 35800 reply_id: 142457[/import]

Any ideas?

Thanks!!!
[import]uid: 184193 topic_id: 35800 reply_id: 142505[/import]

Hi @warrenwsav,
So just to recap, this IS working properly in the Corona Simulator? The image is loaded, scale determined, second image loaded, then it is saved to the temporary directory? And then on the Simulator, it removes the image properly, but on a device, not? I’m trying to figure out if this is a coding issue or a device issue. Which device and OS are you testing on?

Brent

[import]uid: 200026 topic_id: 35800 reply_id: 142525[/import]

Hopefully this will help. I cannot run my full project on the simulator because it uses the camera and Facebook before it gets to this step. What I did run on the simulator was the 7 lines of code I posted in the first thread that combines two images and saves them. I don’t know if this part is working on the page I posted because it is on the phone. It gets down to where it saves the file and stops. It does not add the text in the lines after or anything else. I was wondering if the save method stops any other code from running so I ran the 7 lines of code with other stuff after for testing and it ran. So not sure why it stops in the code I have posted.

I am 99.9% sure this is not a device problem since I can run the test code and it works. And I doubt it is an error in the corona software. So I do not know why it stops at the Save method. I can send you the entire project to compile and run on an android phone if you want. I am using a Samsung Galaxy S2 and so far everything works fine on it. I will load the test on it to make sure it works fine but sure it does.

Thanks for your help on this.

Warren
[import]uid: 184193 topic_id: 35800 reply_id: 142529[/import]