How can i draw text above a image i already have in a pixel array?
Hi,
I'm working on a computer vision project, but instead of working all the time in real time processing i often use one image processing to test some algorithms before implement them on the real time application.
I want to draw some debug data in that single images but i dont know how to do it in this single image way.
I want to draw lines and points! How can i do that?
For example, in the real time application i use the following code:
currentFrame.setData(svc.getNextRaster());
Graphics g = this.getGraphics();
g.drawImage(currentFrame, 0, 0, null);
g.drawLine(pointx1,pointy1,pointx2,pointy2);
But in my single image processing application it doesnt know what is the this.getGraphics();
Thx,
Best regards,
Nuno
# 3
Hey,
I have done the following, but i still have doubts:
BufferedImage in = ImageIO.read(new File(args[0]));
int imgCols = in.getWidth();
int imgRows = in.getHeight();
int[] pixels = new int[imgCols * imgRows];
PixelGrabber pg = new PixelGrabber(in, 0, 0, imgCols, imgRows, pixels, 0, imgCols);
try {
pg.grabPixels();
System.out.println("Pixel grabbed with sucess!");
} catch (InterruptedException e) {
System.err.println("Interrupted waiting for pixels!");
}
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
System.err.println("Image fetch aborted or errored!");
}
boundingBox(pixels,imgCols,imgRows); // processing stuff
BufferedImage middle = new BufferedImage(imgCols, imgRows, BufferedImage.TYPE_INT_RGB);
middle.setRGB(0, 0, imgCols, imgRows, pixels, 0, imgCols);
Graphics g = middle.createGraphics();
g.setColor(Color.GREEN);
g.drawLine(0,0,imgCols,imgRows); // create drawings
// And now? How to get the pixel array again? Or save directly to a file?
BufferedImage out = new BufferedImage(imgCols, imgRows, BufferedImage.TYPE_INT_RGB);
out.setRGB(0, 0, imgCols, imgRows, pixels, 0, imgCols);
Thx,
Nuno
lpxa at 2007-7-7 22:38:54 >
