I am creating a custom JPanel that displays an image in the background on top of a custom color. What I want to do is to have the edges of the top image blend into the background color. Only the outer 20 pixels or so. I have to do this at runtime due to the nature of the program, so using Photoshop or the like isn't an option. I've tried something like this:
The idea being that if I draw a series of concentric shapes around the image, while incrementally lowering the transparency, it will produce a blending effect. The problem is that when rendered, there are lines in the corners of the image that I can't figure out how to get rid of. It also seems like a brute force approach, and as such isn't very elegant code.
Another idea I had was start in the middle of the image and move outward radially while slowly lowering the opacity of the pixels as I get closer to the edges. But I don't even know where to start for that (apart from at the center of the image.)
Any ideas, suggestions, guidelines, pointers, tips, thoughts, axioms, or rambling pontifications would be greatly appreciated. Thank you.
Code:
int red = value;
int green = value;
int blue = value;
int alpha = alphaMinimum;
int x = 0;
int y = 0;
for (int alpha = 255; alpha >= alphaMinimum; alpha -= 5)
{
g2d.setColor (new Color (value, value, value, alpha));
g2d.drawRoundRect (
x++, y++, width, height, radius, radius);
width -= 2;
height -= 2;
}
Another idea I had was start in the middle of the image and move outward radially while slowly lowering the opacity of the pixels as I get closer to the edges. But I don't even know where to start for that (apart from at the center of the image.)
Any ideas, suggestions, guidelines, pointers, tips, thoughts, axioms, or rambling pontifications would be greatly appreciated. Thank you.
Comment