'Pasting' Images

Hi,

I want to paste a copy of an image onto another one. I knew how to do this in XCode/Cocoa using ImageContexts and DrawInRects.

Is there any way to do something similar in Corona? [import]uid: 168478 topic_id: 33772 reply_id: 333772[/import]

Can you clarify the effect you’re trying to do a bit better? Are you wanting to draw image B where image A is? Do you want to blend them some how so there is a new image that’s a mix of A and B? [import]uid: 199310 topic_id: 33772 reply_id: 134321[/import]

Hi Rob. I’m looking for option 2, adding one image to another to make a third ‘composite’ image. In Objective C / Cocoa it’s possible to apply blendmodes to the process too so you can use the technique to not only ‘paste’ one image into another, but to apply other effects like shadows, etc. [import]uid: 168478 topic_id: 33772 reply_id: 134517[/import]

Corona supports blend modes:

http://www.coronalabs.com/blog/2012/10/30/creative-effects-using-blend-modes/
[import]uid: 199310 topic_id: 33772 reply_id: 134551[/import]

Can you clarify the effect you’re trying to do a bit better? Are you wanting to draw image B where image A is? Do you want to blend them some how so there is a new image that’s a mix of A and B? [import]uid: 199310 topic_id: 33772 reply_id: 134321[/import]

Hi Rob.
Those blendmodes do look pretty good, thanks. My only remaining question is how to permanently add one image to another, so that the resulting image can be treated as one image. This would mean that any amount of images could be added to a base image (e.g. a background image of a game) without needing to keep layers of image resources. [import]uid: 168478 topic_id: 33772 reply_id: 134670[/import]

You can save images using display.captureBounds() and display.save() which might help you. [import]uid: 199310 topic_id: 33772 reply_id: 134702[/import]

Hi Rob. I’m looking for option 2, adding one image to another to make a third ‘composite’ image. In Objective C / Cocoa it’s possible to apply blendmodes to the process too so you can use the technique to not only ‘paste’ one image into another, but to apply other effects like shadows, etc. [import]uid: 168478 topic_id: 33772 reply_id: 134517[/import]

Corona supports blend modes:

http://www.coronalabs.com/blog/2012/10/30/creative-effects-using-blend-modes/
[import]uid: 199310 topic_id: 33772 reply_id: 134551[/import]

Hi Rob,

I’m trying to use display.captureBounds but the simulator just hangs when it gets to that part:-

 local screenBounds =  
 {  
 xMin = 0,  
 xMax = display.contentWidth,  
 yMin = 0,  
 yMax = display.contentHeight,  
 }  
 print "captureBounds"  
 local bushes = display.captureBounds(screenBounds)  
 print "remove"  
 gameScreen.backgroundGroup:removeSelf()  
 gameScreen.backgroundGroup:insert(bushes.image)  

It prints the ‘captureBounds’ message but not the ‘remove’ one.

Basically I’ve displayed a background image in one layer and added some bushes on top in another. As the bushes are static and never need to interact with anything, it’s an unnecessary resource drain to keep the image objects. I’d much prefer to draw the bushes, capture the image of the bushes on top of the background, and replace the background image with the captured image of the background with the bushes. [import]uid: 168478 topic_id: 33772 reply_id: 134889[/import]

I’ve never actually done that. Hopefully someone else in the community might have some advice.

You’re also capturing the full screen, perhaps one of the other display.capture() functions might work better for you. [import]uid: 199310 topic_id: 33772 reply_id: 134909[/import]

Hi Rob.
Those blendmodes do look pretty good, thanks. My only remaining question is how to permanently add one image to another, so that the resulting image can be treated as one image. This would mean that any amount of images could be added to a base image (e.g. a background image of a game) without needing to keep layers of image resources. [import]uid: 168478 topic_id: 33772 reply_id: 134670[/import]

You can save images using display.captureBounds() and display.save() which might help you. [import]uid: 199310 topic_id: 33772 reply_id: 134702[/import]

Hi Rob,

I’m trying to use display.captureBounds but the simulator just hangs when it gets to that part:-

 local screenBounds =  
 {  
 xMin = 0,  
 xMax = display.contentWidth,  
 yMin = 0,  
 yMax = display.contentHeight,  
 }  
 print "captureBounds"  
 local bushes = display.captureBounds(screenBounds)  
 print "remove"  
 gameScreen.backgroundGroup:removeSelf()  
 gameScreen.backgroundGroup:insert(bushes.image)  

It prints the ‘captureBounds’ message but not the ‘remove’ one.

Basically I’ve displayed a background image in one layer and added some bushes on top in another. As the bushes are static and never need to interact with anything, it’s an unnecessary resource drain to keep the image objects. I’d much prefer to draw the bushes, capture the image of the bushes on top of the background, and replace the background image with the captured image of the background with the bushes. [import]uid: 168478 topic_id: 33772 reply_id: 134889[/import]

I’ve never actually done that. Hopefully someone else in the community might have some advice.

You’re also capturing the full screen, perhaps one of the other display.capture() functions might work better for you. [import]uid: 199310 topic_id: 33772 reply_id: 134909[/import]

Bounce.

I’m not sure if the ‘Capture’ functions are what I’m after. I can’t seem to get them to work properly and even if I do, having to use the whole ‘display’ context to grab from is a real hassle. I’m basically looking for a way of using an image as a base to add and combine other images to, but as Corona display.image objects are textures, that would mean Corona would be creating a texture resource by combining other texture resources. I guess that’s just not possible?

Is there any methods in Corona that, under the hood, use Core Graphics / Cocos2D / Quartz to manipulate images? Something that I could use to create an image resource that I could later use as a texture / display.image? [import]uid: 168478 topic_id: 33772 reply_id: 136169[/import]

Hi @claritygames,
My thoughts on whether you can accomplish ALL that you need is: probably not. Corona doesn’t currently allow you to manipulate images at the core pixel level. It uses an object-based display system, not pixel-based, as you surely know already.

Probably the best you could do is to render all of your objects into a single display group with a transparent background. Then, you could use display.save() to save that group to an image file, which could then be loaded later, almost like a paintbrush.

Brent [import]uid: 200026 topic_id: 33772 reply_id: 136184[/import]

Hi @Brent,

certainly I wouldn’t be expecting as fine a granularity as per pixel manipulation. What I’m talking about is the kind of thing you’re doing with the blendmodes, which was something I thought you couldn’t do with textures, but rather with low-level Core Graphics manipulation. Maybe I’m getting the wrong end of the stick here, but as Corona does a lot of stuff that I was doing in Core Graphics/Quartz (especially the blend modes) I thought you were doing this using similar methods under the hood.

Still, for most of the things I want to do Corona is great so I can make do without this other stuff! [import]uid: 168478 topic_id: 33772 reply_id: 136199[/import]

Bounce.

I’m not sure if the ‘Capture’ functions are what I’m after. I can’t seem to get them to work properly and even if I do, having to use the whole ‘display’ context to grab from is a real hassle. I’m basically looking for a way of using an image as a base to add and combine other images to, but as Corona display.image objects are textures, that would mean Corona would be creating a texture resource by combining other texture resources. I guess that’s just not possible?

Is there any methods in Corona that, under the hood, use Core Graphics / Cocos2D / Quartz to manipulate images? Something that I could use to create an image resource that I could later use as a texture / display.image? [import]uid: 168478 topic_id: 33772 reply_id: 136169[/import]

Hi @claritygames,
My thoughts on whether you can accomplish ALL that you need is: probably not. Corona doesn’t currently allow you to manipulate images at the core pixel level. It uses an object-based display system, not pixel-based, as you surely know already.

Probably the best you could do is to render all of your objects into a single display group with a transparent background. Then, you could use display.save() to save that group to an image file, which could then be loaded later, almost like a paintbrush.

Brent [import]uid: 200026 topic_id: 33772 reply_id: 136184[/import]