Create Rectangle border to a subImage obtained from a BufferedImage.
Hi !
I have captured Image using.
screenImage = robot.createScreenCapture(Rectangle r).
Now i obtain a subImage of this screenImage on mouseTrack on Screen using Insets.
I get the size of subImage and use these dimensions to getSubImage form the screenImage .
contentPanel.underFrameImg = screenImg.getSubimage(x, y, w, h);
Now i want a border along this image.Can someone guide me how do i do this.
Beneath is the code i used to get the SubImage.
publicvoid resetUnderImg()
{
if (robot!=null && screenImg!=null)
{
Rectangle frameRect = getBounds();
Insets frameInsets = getInsets();
contentPanel.paintX = 0;
contentPanel.paintY = 0;
int x = frameRect.x + frameInsets.left;
if (x < 0)
{
contentPanel.paintX =- x;
x = 0;
}
int y = frameRect.y + frameInsets.top;
if (y < 0)
{
contentPanel.paintY =- y;
y = 0;
}
int w = frameRect.width - frameInsets.left - frameInsets.right;
if (x + w > screenImg.getWidth())
w = screenImg.getWidth()- x;
int h = frameRect.height - frameInsets.top - frameInsets.bottom;
if (y + h > screenImg.getHeight())
h = screenImg.getHeight() - y;
contentPanel.underFrameImg = screenImg.getSubimage(x, y, w, h);
//imageBorder = BorderFactory.createLineBorder(Color.red,4);
}
}
It would be of great Help.
Thanks and regards,
Jigar.

