Get/Set Pixel Color

Corona Version: 2011.591
System Version: OSX 10.7
Computer HW Info: Macbook
iPhone Generation: n/a
iPhone Firmware Version: n/a

Type (API, Runtime, Multimedia, Optimization, Network, Devices, Deployment etc):
API

Description:
Would like function GetPixel() , returning a table of R,G.B (plus possibly A) values from an image.

This would allow (among other things) use of an image as a map for tiled games, and for some aspects of image manipulation.

Would like SetPixel(image, x,y, colour{}) so that an image can be amended/created from whole cloth if required.

(This obviously then opens the door for a hundred more requests for drawing functions such as lines and rects onto an image. One way to achieve that might be to allow for newImage, newText, etc to operate on an invisible display context, which would be saved to a file)
[import]uid: 108660 topic_id: 19815 reply_id: 319815[/import]

+1

did you follow Notch (Minecraft) coding his game for Ludum Dare?
http://de.twitch.tv/notch/b/302867302

I love what he did there with the spritesheet: he draws monocrome sprites and sets the color of the objects in code by coloring the pixels. That way he only has to draw one avatar, by coloring the sprite he can create a lot of different characters.

it would be great if we could do so in corona sdk…
-finefin

[import]uid: 70635 topic_id: 19815 reply_id: 77248[/import]

Create a grayscale image, put it on the screen, and then do this to it:

image:setFillColor( 255, 0, 0 )

…and it will turn red.

That may not be what Notch was doing (I didn’t see) but it is a way to use one image and color it differently for other uses.

jay [import]uid: 9440 topic_id: 19815 reply_id: 77271[/import]

right, you can tint the whole image.
but you can’t tint individual pixels,
like “tint all pixels with the value RGB to new value RGB”.

we would be able to, let’s say, create *one* “warrior” sprite and color each warrior instance’s armor individually while the skin tone is always the same…

-finefin
[import]uid: 70635 topic_id: 19815 reply_id: 77275[/import]

Yeah, that would be awesome. :slight_smile: I’ll give a +1 to the idea of get/set pixels.

Until then, warrior armor in greyscale, naked warrior in skin tones. Tint the armor, slap it on the naked warrior, both into a group and then move the group around.

(Okay, I know workarounds don’t work for every situation and can be really clunky, besides. I’m just brainstorming.) :slight_smile:

Jay
[import]uid: 9440 topic_id: 19815 reply_id: 77276[/import]

naked warriors? Apple won’t approve … hehe just kidding :wink: [import]uid: 70635 topic_id: 19815 reply_id: 77292[/import]

FWIW, I have discovered that I can use a combination of display.newRect and display.newGroup()
to create a set of small colored rectangles.

Then I can save a ‘screen grab’ for that display group as a JPG file.

So that’s one way to create bitmaps on the fly in the application.
Can’t read the pixels back from the JPG of course, but it’s a work around of a kind.
I could certainly create a spriteset using that method.
[import]uid: 108660 topic_id: 19815 reply_id: 77293[/import]