Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Constructing 48 bit RGB bufferedimage

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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:

    # 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?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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)

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Constructing 48 bit RGB bufferedimage

    Quote Originally Posted by copeg View Post
    When you say 48bit images, do you mean 16 bit for each color (R/G/B)?
    Yes.

    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:

    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:

    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.

Similar Threads

  1. Help needed with constructing a while loop please!
    By Bentino in forum Loops & Control Statements
    Replies: 5
    Last Post: March 19th, 2012, 11:10 AM
  2. Constructing Strings
    By Farmer in forum Loops & Control Statements
    Replies: 5
    Last Post: September 3rd, 2011, 10:24 AM
  3. Creating a bufferedimage!
    By Vexst in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: June 16th, 2010, 08:05 AM
  4. free memory of bufferedimage
    By mr_empty in forum Java SE APIs
    Replies: 2
    Last Post: January 19th, 2010, 06:14 AM
  5. Replies: 2
    Last Post: June 29th, 2009, 03:06 PM

Tags for this Thread