Constructing 48 bit RGB bufferedimage
Hi,
I'm a newbi, using Python in a Maths program called GeoGebra. From Python I call Java to be able to construct an image where each pixels color value is set from a mathematical function. The code, which is in Python and works (though the mathematical bits have been cut out), is:
Code :
# Bring in Java.
from java.awt.image import BufferedImage
from javax.imageio import ImageIO
from java.io import File
# Useful constants
fileCount = 2 # Number of files generated
dir = "C:/output/" # Directory to save files
subdir = "Tst/" # Subdirecrory
prefix = "Tst " # Prefix to filenames
sizeX = 400 # Number of pixels in x
sizeY = 400
# Create the image object.
img = BufferedImage(sizeX, sizeY, BufferedImage.TYPE_INT_RGB)
g = img.getGraphics()
# Make a number of files
for i in range(fileCount) :
# Step through every pixel
for x in range(sizeX):
for y in range(sizeY):
img.setRGB(x, y, functionOfPositions() )
# Save to file.
if not ImageIO.write(img, "png", File(dir + subdir + prefix + "%03d.png" % (i))): print "Save failed!"
However, I would like to produce 48 bit PNG (or TIFF) files for printing high quality prints. The code above produces 24 bit images.
The PNG format supports 16 bit color but BufferedImage does not. I believe that you may construct your own custom BufferedImage to support this but I don't know how to do this. Any help on this would be much appreciated.
Also: will Windows be able to read and display a 48-bit image as a 24 bit image on screen or will I have to produce both a 24 bit image for the screen and a 48 bit image for printing?
Re: Constructing 48 bit RGB bufferedimage
When you say 48bit images, do you mean 16 bit for each color (R/G/B)? Take a look at the SampleModel and ColorModel classes (see Learning Java 2D, Part 2 ) which should allow you to customize how the image data is represented. I can't provide much advice for rendering or printing this type of image, as typically this is done using objects that implement the Paint interface which I believe is restricted to a single int value (RGBA - 8 bits each)
Re: Constructing 48 bit RGB bufferedimage
Quote:
Originally Posted by
copeg
When you say 48bit images, do you mean 16 bit for each color (R/G/B)?
Yes.
Quote:
Take a look at the SampleModel and ColorModel classes (see
Learning Java 2D, Part 2 ) which should allow you to customize how the image data is represented.
I had a look there before:
Quote:
Images may use one of several subclasses of ColorModel in the Java 2D API libraries:
A ComponentColorModel, in which a pixel is represented by several discrete values, typically bytes, each representing one component of color, such as the red component of an RGB representation
A DirectColorModel, in which all components of a color are packed together in separate bits of the same single pixel value
An IndexColorModel, in which each pixel is a single value representing an index into a palette of colors
The ComponentColorModel would probably be the most appropriate, but how du you use it? What is a subclass (I'm new to this, remember)
However:
Quote:
For the image-type parameter, use one of the BufferedImage constants shown in Table 1, which specifies how the image data is stored for each of its pixels.
None of those describe anything that remotely resebles 3 x 16 bit data. I believe this is where I lose touch. To use BufferedImage I have to use one of those constants (?) unless I make a custom (?) bufferedimage. But how? Do I write custom methods for custom ColorModel objects and then instantiate them by something like BufferedImage.ColorModel = new MyColourModel()? I really feel I'm out on a limb here. Naively I thought this would be a routine hack but maybe it's not so common with 48 bit applications.