Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2005

Tip: Looking for answers? Try searching our database.

Buffered image using float data

Thread view: 
Peter Ashford - 02 May 2005 00:06 GMT
Does anyone know whether there's anwyay to use floating point data to
make a greyscale BufferedImage?

I'd like this because I want an image I can edit and get the results
directly in floating point format.  There's a unsigned 16bit format
which is better than 8bit, but I'm using the data for heightfield info
which doesn't need to be restricted to 16 bit int accuracy.

Ideas?

TIA.
Betty - 02 May 2005 01:07 GMT
> Does anyone know whether there's anwyay to use floating point data to
> make a greyscale BufferedImage?
[quoted text clipped - 3 lines]
> which is better than 8bit, but I'm using the data for heightfield info
> which doesn't need to be restricted to 16 bit int accuracy.

You could keep your data in floating point separate from the BufferedImage
and convert it when you want to put it on the screen.
Peter Ashford - 02 May 2005 01:55 GMT
>>Does anyone know whether there's anwyay to use floating point data to
>>make a greyscale BufferedImage?
[quoted text clipped - 6 lines]
> You could keep your data in floating point separate from the BufferedImage
> and convert it when you want to put it on the screen.

True.  However, I will be updating a 3d image on the basis on the data
in the bitmap and editing the bitmap, converting the results and
updating the 3d image will be much slower than getting the data directly
from the bitmap in the correct format.

More significantly, as the edits to the buffered image are being used to
alter the heightmap, if the image uses 16bit int accuracy, it will apply
that limitation to the float buffer.  This is the problem I'm trying to
avoid in the first place.  If it weren't for this problem I could just
use a 16bit greyscale image for the data and live with the resolution
restraints.
Boudewijn Dijkstra - 02 May 2005 11:41 GMT
> Does anyone know whether there's anwyay to use floating point data to make a
> greyscale BufferedImage?
[quoted text clipped - 5 lines]
>
> Ideas?

SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_FLOAT, w, h, 1, w,
new int[] {0});
DataBuffer db = new DataBufferFloat(w * h);
WritableRaster wr = Raster.createRaster(sm, db, null);
ColorSpace cs = ColorSpace.getInstance(CS_GRAY);
ColorModel cm = new ComponentColorModel(cs, false, true, Transparency.OPAQUE,
DataBuffer.TYPE_FLOAT);
BufferedImage bi = new BufferedImage(cm, wr, true, null);
Boudewijn Dijkstra - 02 May 2005 11:56 GMT
>> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.