|
Author |
Topic: Transparency tool (Read 2320 times) |
|
granster
|
Transparency tool
« on: Feb 6th, 2005, 5:40pm » |
|
I would like to make a tool to read an image file and change every byte that is near to white to pure white and then save the file. I've got several images of tree and other objects that look like they are on a pure white background but when I try to use them as a transparent gif or sprite they have some off white areas that cover the background. I've been trying to figure out how to do this searching through these messages and using the reference section but still haven't figured it out. Any help/suggestions?
|
Live long and prosper
|
|
|
st33d
|
Re: Transparency tool
« Reply #1 on: Mar 2nd, 2005, 9:29pm » |
|
Yeah. I think I might need a tool like that at some point. Code: BImage file; void setup(){ file = loadImage ("d.gif"); size(file.width, file.height); } void draw(){ for (int i = 0; i < file.pixels.length; i++){ whiter(file.pixels[i],i); } background(file); save("white.tif"); println("done"); } //whiting out function void whiter(color w, int p){ /* we've got three 255 values in a color add those numbers together and colors near white should be from the max(765) to say 600? play around with the value and add stuff to the red, green and blue values to catch other stuff. */ if (red(w)+blue(w)+green(w) > 600){ file.pixels[p] = #FFFFFF; //or change this to your transparency color for a .gif } } |
| My function is sloppy too. I've passed "i" twice. Ah well, it works anyway.
|
« Last Edit: Mar 2nd, 2005, 9:42pm by st33d » |
|
I could murder a pint.
|
|
|
|