Pixel Alteration in an image/image rotation
Hi, I am trying to devise a game, and I have come to a graphical snag. I have a gif image that is a spike with a black background (to avoid confusion, here it is :http://img442.imageshack.us/img442/8008/spike5.gif).
Unfortunately, due to its nature, it has a spot in the lower-left corner that blocks another image. I think I can solve this by either taking this picture:http://img408.imageshack.us/img408/6256/spike1.gif, and rotating it, so that it would be flat at the angle I need, or I could alter the image, in java, so that each black pixel becomes transparent, which is ok, because of the game also has a black background. I would need it so that it would either only affect the area of the picture of the buffer, or it would take the image and return it as an altered image. What would be recommended to do and how can it be done?
Re: Pixel Alteration in an image/image rotation
Try changing the pixels to transparent by setting there aplha value's to zero.
Code :
public Image makeTransparent(Image im){
BufferedImage bIm = .... code to create buffered image
int pixelColor = bIm.getRGB(x, y);
int r = (c & 0x00ff0000) >> 16;
int g = (c & 0x0000ff00) >> 8;
int b = c & 0x000000ff;
Color c = new Color(r, g, b);
// Fuzzy algorithm to make a colour match that suits your needs, since they will probably not be the exact same colour.
if(fuzzy returned colour match){
// Set pixel value to a colour defined with 0 alpha
}
// repeat
return new Image(bIm.getGraphics());
}
Something like that,
Regard,
Chris
Re: Pixel Alteration in an image/image rotation
This doesn't work because there is no constructor for Image. I kept trying different things like making it an ImageIcon to return, or adding a graphic object, but it doesn't work, but I can't get it to work without crashing.
Re: Pixel Alteration in an image/image rotation
I found a website that explains how to make one color transparent using colorFilters. Here it is.