>> Does anyone know whether there's anwyay to use floating point data to make
>> a >> greyscale BufferedImage?
[quoted text clipped - 5 lines]
>>
>> Ideas?
Errors corrected from last try; test suite added. ;)
public static void main(String[] args)
{
final int w = 320;
final int h = 240;
SampleModel sm = new ComponentSampleModel(
DataBuffer.TYPE_FLOAT, w, h, 1, w, new int[] {0});
DataBuffer db = new DataBufferFloat(w * h);
WritableRaster wr = Raster.createWritableRaster(sm, db, null);
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorModel cm = new ComponentColorModel(
cs, false, true, Transparency.OPAQUE, DataBuffer.TYPE_FLOAT);
final BufferedImage bi = new BufferedImage(cm, wr, true, null);
Graphics2D g2 = bi.createGraphics();
g2.setRenderingHint(
RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(Color.BLACK);
g2.fillRect(0, 0, w, h);
g2.setColor(Color.WHITE);
g2.drawLine(0, 0, w, h);
g2.drawLine(w, 0, 0, h);
g2.drawOval(w/4, h/4, w/2, h/2);
g2.dispose();
Frame f = new Frame("Float Graphics");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
f.setLayout(new BorderLayout());
Canvas c = new Canvas() {
public void paint(Graphics g) {
g.drawImage(bi, 0, 0, null);
}
};
c.setSize(w, h);
f.add(c, BorderLayout.CENTER);
f.pack();
f.show();
}
Peter Ashford - 02 May 2005 12:55 GMT
>>>Does anyone know whether there's anwyay to use floating point data to make
>>>a >> greyscale BufferedImage?
[quoted text clipped - 7 lines]
>
> Errors corrected from last try; test suite added. ;)
<code snipped>
Awesome! Great! Thanks very much - looks like exactly what I needed.
Thanks for the effort :o)
Peter.