Get/set individual pixels in image
Hi Mike, I'm playing with imagez for a small project.
Right away I wanted to be able to get or set individual pixels in an image. I first went down the hard path of pulling out pixels from the image into a Java array, aseting them, and putting them back using set-pixels. Then I discovered (.setRGB img x y color) which works quite well, though it requires digging into the details of BufferedImage. Would you be open to a PR that wrapped .getRGB and .setRGB into the API you're providing with this library?
Yes I think that would be fine. Though it might be worth doing some benchmarking - individual pixel setting needs to be pretty fast in order to be useful in many cases so we don't want to encourage people to use an approach that adds unnecessary overheads.
Probably an API function is OK as long as it gets inlined
Great! Regarding benchmarking: I am using it for this project (see screenshot) and the lines appear instantly on the image; so it's certainly fast enough for my purposes. I'm sure it won't be as fast as Java arrays, but you still have to set-pixels if you do it that way anyways (don't you?), so I'm not sure why that would matter.
I'll try to put something together tomorrow when I have a minute.
Your project looks cool!
The array based stuff tends to have a slight advantage if you are doing something very customised and need to get / set a large number of times on the same data (implementing blurs, cellular automata, real-time animation, stuff like that...). You probably won't notice the difference if you are just setting some of the the pixels once :-)
so yes, I agree a nice interface to get / set pixels would be good for general purpose use.