File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Gray scale unformatted images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Gray scale unformatted images" Watch "Gray scale unformatted images" New topic

Gray scale unformatted images

Nate Lockwood
Ranch Hand

Joined: Feb 22, 2010
Posts: 83
I'm really new at Java coming over from C/C++ and know little about GUIs so far. I'll probably use JavaBeans or jEdit for the project I have after I learn more basic java.

For part of the GUI I will need to display an image. The pixels are bytes, that is, one byte is one pixel, and are gray scale. No color bands are encoded in the bytes. I will get the data into a byte array after a little processing but don't see how to create an image from this array and while I've seen some code examples for image display they tend to be color images, formatted such as JPEG, and read from files. I assume that the image will be displayed on a panel.

Can anyone point me to some example code for displaying an array of byte as an monochrome image?

I know that I could probably stuff the bytes into integers so that for each pixel each band/color has the same value but this appears to be overkill.

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
I'm not sure of the specifics, but this probably involves creating a DataBufferByte object, using that to create a Raster object, and finally creating a BufferedImage from the Raster, probably of type TYPE_BYTE_GRAY.
I agree. Here's the link:
subject: Gray scale unformatted images
jQuery in Action, 3rd edition