How can I make an image border as gradient. I googled a lot, but didn't find correct suggestion. Any one can help me...
Any suggestion please...
How can I make an image border as gradient. I googled a lot, but didn't find correct suggestion. Any one can help me...
Any suggestion please...
This is an interesting one. I first thought that there should be a simple solution, using some
Graphics#drawRoundRect
call with the appropriatePaint
, but it's not sooo simple.However, one solution is implemented in the following example:
The image is painted as-it-is into a new image. Then the edges and corners are painted. These consist of rectangles. Each rectangle for one edge is filled with a
GradientPaint
that interpolates between "completely transparent" and "completely opaque". Similarily, the rectangles for the corners are filled with aRadialGradientPaint
interpolating between the same colors. These are painted with theAlphaComposite.DstOut
composition rule, so that the actual pixels of the image are slowly "blending out" towards the border.(The checkerboard pattern is only painted in the background of the component, to emphasize that it iterpolates towards transparent pixels at the border)
Create a transparent image of the same size, draw the white border and blur it. Than copy it on top of the image that you want to have the gradient border on.
Reference: http://www.jhlabs.com/ip/blurring.html
Hope that helps!