Hi all, I've been looking around for a premade algorithm to pixelate an image or something similar that I could expand on although I've only been able to find descriptions of the algorithm so I've attempted to make it. What it does is loops through every pixel in a BufferedImage, loaded from a 16-bit PNG image file (byte for each component) and it divides the current X and Y components by the square size . From here it performs a further nested for loop to total the pixel colours in the block that this pixel is in.

It then divides by the block size, which is represented by the "pp" field, except it's squared because it samples pixels in a square along the X and Y axes. According to a few explanations I've read this should give me the average pixel colour for this block and every pixel in this block should be coloured in it. The algorithm I've written works somewhat in that the general shape of the image is preserved after the pixelation with far less detail, as is expected. The problem is that the colours are completely wrong and I'll show you how in the image below:

You cant just add ints and then devide, it works for numbers, but it really messes up colors.this way 0x000100 / 2 becomes 0x000080, so very black-green becomes blue.i guess you should separate the colors, and count these up or something.Im sure there is some kind of blending algorithm.

Thanks for both your replies. I've substituted the single colour divides and used the components and it works great. I was just also wondering whether the magnification of the image is expected or whether I've glossed over another detail. :p Normally when I see pixelation the area of the image that's been pixelated is to scale with the rest of the image.

I've sorted it now. Previously I'd made a magnification method and I think I borrowed too much logic from it. The working solution just loops through the outer for loops in steps the size of the block size. Then an inner set of nested for loops samples each of the pixels in that block, finds the average colour and then loops through them setting each to the colour of the average.It's not the best solution but I'll post it here in case anyone needs a starting point.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org