I am trying to combine two separate images into one larger image (each one
still discrete) and then I need to be able to put the resulting image
through some transformation, like an invert.  One image is black & white (2
bits/pixel) and one is grayscale (4 bits/pixel).  When I load each into a
BufferedImage, the grayscale loads as a TYPE_BYTE_BINARY and the black &
white as a TYPE_BYTE_GRAY.  I then create the combined image as follows -

/* code sample */
BufferedImage combined = new BufferedImage( Math.max( grayImage.getWidth(),
bwImage.getWidth() ), grayImage.getHeight()+bwImage.getHeight(),
BufferedImage.TYPE_BYTE_GRAY );

Graphics2D g = combined.createGraphics();
g.drawImage( grayImage, null, 0, 0 );
g.drawImage( bwImage, null, 0, grayImage.getHeight() );

/* end of code sample */

After this, I pass the new image to a special JPanel I have created to
display the image.  The resulting image displays just fine, however, if I
try to run an invert on it, the black & white image becomes completely
black, not inverted.  Also, if I run it through a sharpening filter,
nothing seems to happen to the black and white image and the grayscale
image ends up looking like crap.  Here is the code I use for invert and
sharpen -

/* 2nd code sample */
    public void invert()
    {
         byte[] intensity = new byte[256];
         for(int i=0; i<256; i++)
         {
             intensity[i] = (byte) (256 - i);
         }

         ByteLookupTable blt = new ByteLookupTable(0, intensity);
         LookupOp op = new LookupOp(blt, null);
         op.filter( imageToDisplay, imageToDisplay );
         imagePanel.setImage( imageToDisplay );
    }

    public void sharpen()
    {
         float[] sharpenArray = { -1, -1, -1, -1,  9, -1, -1, -1, -1 };

         Kernel kernel = new Kernel(3, 3, sharpenArray );
         ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
         cOp.filter(imageToDisplay, imageToDisplay );
         imagePanel.setImage( imageToDisplay );
    }

/* end of code sample */

Any thoughts on why I may be getting these strange results?  Should I be using a 
different image type for the combined image?

Any help would be greatly appreciated.

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to