Turn white pixels transparent
in
Programming Questions
•
1 year ago
Hi,
I want to write a program that will turn white pixels transparent. I have a bunch of images I need edited, and I think this would be the fastest way.
I've found some examples in the forum, but none of them save the image with transparent pixels to my desktop. Am I missing something here?
Here is one of the examples I am working with:
- String FILENAME = "oak.png";
- PImage img;
- PImage newImg;
- int x;
- int y;
- int i;
-
- img = loadImage( FILENAME );
- newImg = createImage( img.width, img.height, ARGB );
- for( x = 0; x < img.width; x++ ){
- for( y = 0; y < img.height; y++ ){
- i = ( ( y * img.width ) + x );
- if( img.pixels[i] == color( 0, 0, 0 ) ){
- newImg.pixels[i] = color( 0, 0, 0, 0 );
- }
- else {
- newImg.pixels[i] = img.pixels[i];
- }
- }
- }
- newImg.save( FILENAME );
1