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.

[2186 byte] By [jigar.mehtaa] at [2007-11-26 13:45:02]
# 1
1) Create an ImageIcon using the image.2) Add the ImageIcon to a JLabel3) Add a Border to the JLabel4) Add the JLabel to the GUI
camickra at 2007-7-8 1:19:18 > top of Java-index,Desktop,Core GUI APIs...
# 2

contentPanel.underFrameImg = screenImg.getSubimage(x, y, w, h);

imageBorder = BorderFactory.createLineBorder(Color.red,4);

Icon subImage = new ImageIcon(contentPanel.underFrameImg);

JLabel jbl = new JLabel(subImage);

jbl.setBorder(imageBorder);

Here i cannot add JLabel to the GUI,since the parent screen image captured is added to the cell component of a table,which is then written of to a document.

If i can,get the 4th step u mentioned,then let me know how in the given scenario,esle is there any other way around.I m not an expert on this swing topics.

Thanks for ur reply so far..,looking fwd for more help from ur side.

jigar.mehtaa at 2007-7-8 1:19:18 > top of Java-index,Desktop,Core GUI APIs...
# 3
If all you want is a line border you can just draw a red rectangle around your image.Graphics g = contentPanel.underFrameImg.createGraphics();g.setColor(Color.RED);g.drawRect(0, 0, contentPanel.underFrameImg.getWidth()-1, contentPanel.underFrameImg.getHeight()-1);
Rodney_McKaya at 2007-7-8 1:19:18 > top of Java-index,Desktop,Core GUI APIs...
# 4
Thank you very much!!your ideas worked well.I gratefully appreciate your helpa nd hope you got ur reward points.Thanks again and looking froward for more assistance in future.
jigar.mehtaa at 2007-7-8 1:19:18 > top of Java-index,Desktop,Core GUI APIs...