i have a png that i’m importing with a transparency and I want to invert select regions of it as the mouse moves over the region but I’m having trouble with it.
i don’t know too much about transparent images but the way i’d normally go about inverting a regular image doesn’t work, probalby due to the alpha channel, i’m just unsure how to work with it …
Hello Mesteno, If i get it right you are working with Alpha Chanel in that way instead of using “img.width*img.height*3” you have to take care about the 4th alpha pixel. I understod that you want to preserve that mask. So you have to “jump it”. I use something like
unsigned char * pixels = transparency.getPixels();
for (int i = 0; i < transparency.width*transparency.height*4; i++){
if (i%4 != 3) pixels[i] -= 255;
}
transparency.setFromPixels( pixels, transparency.width, transparency.height,OF_IMAGE_COLOR_ALPHA ,false );
On the ImageLoaderExample on apps/examples. It works for me. I hope for you to.
i had tried something similar but was running into the problem in setFromPixels() of forgetting to put the new type to OF_IMAGE_COLOR_ALPHA, causing it to break because it had an extra channel… thank you!