Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Gray scale unformatted images  RSS feed

Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Posts: 42975
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!