Login  Register

A question on image type converter

Posted by Daan Zhu on Dec 03, 2007; 3:01pm
URL: http://imagej.273.s1.nabble.com/A-question-on-image-type-converter-tp3697886.html

Dear ImageJ Users,
I need to write a program to simulate "ImageJ type converter".
My Images are signed 12-bit image and I need to convert to 8-bit (1
byte) gray image. ImageJ's output is exactly my wanted output.
Unfortunately I don't really know who ImageJ works. I investigated
ImageJ's source code.
------------------------------
ImagePlus imp = new ij.io.Opener imageOpener.openImage("Img12Bit.tif");
java.awt.Image img = ip.createImage();
BufferedImage bi = new BufferedImage(img.getWidth(null),
img.getHeight(null), BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g2 = bi.createGraphics();
g2.drawImage(img, 0, 0, null);
g2.dispose();
ImageIO.write(bi, "jpg", new File("Img8Bit.jpg"));
-------------------------------

It looks simple. But I can not understand how BufferedImage, Graphics2D works
pixel by pixel? Could any people kindly advise me?
If any people are interested to this question, I would like to send my
test program with sample image. Thank you.

Regards,

Daan