# How do I programmatically remove an image's background color?

I have a sprite sheet (image) and want to draw it on screen.

image  = sprite sheet image
x      = player x position
y      = player y position
width  = player width
height = player height

public class main extends japplet
{
...

public void paint(Graphics g)
{
g.drawImage(image, x, y, x+width, y+height,
0, 0, 40, 40 ,sprite_sheet.m1);
}
}


On the sprite sheet, I have the image of a player with a blue background color. Calling drawImage shows the blue background too. I could remove the color with Photoshop, but I really don't want to, because it would remove part of my player.

Can I remove the background color with Java code?

• Are you really having that big a problem using Photoshop that you think it'd be easier to do this programmatically? Anyway, this is a question for StackOverflow Mar 23 '13 at 3:26
• This should help stackoverflow.com/questions/14097386/… Mar 23 '13 at 13:57
• What exactly do you mean by "it will remove part of my player"? If you (as a person) cannot remove the color in Photoshop, how is an algorithm supposed to do it automatically? Mar 24 '13 at 5:38
• It might help if you included a picture of your actual sprite, and some hint of how you want it to look like in the game (and maybe an example of what goes wrong when you try to remove the background in Photoshop). Mar 24 '13 at 13:22