Hi
I have 2 problems with a LookupOp that tries to blend a file that I read from
disc.
In the following code you can see that I read the same file from disc 2 times:
2 time thru the use of ImageIcon and 2 times thru the use of ImageIO.read.
The 4 source-images I get, are then converted to BufferedImages: 2 times thru
the use of the toBI-method, which is quite a straightfoward conversion to an
RGB-bufferedimage and 2 times thru the use of the toCBI-method which is a copy
from the Filthy Rich Clients Book, that says that you should always an
optimized buffered image.
On the 4 resulting bufferedimages I do a LookupOp that should brighten: on the
2 toBI-results it does so indeed; on the 2 toCBI-results it darkens iso
brightens ... ????
My second problem is that the buffered image that comes directly from
ImageIO.Read throws an "java.lang.IllegalArgumentException: Number of
color/alpha components should be 3 but length of bits array is 1" when using
the LookupOp filter on its result (without firrst converting it to another
buffered image, either thru toBI or toCBI). Somehow the format that is returned
from ImageIO.Read is not suited for my LookupOp??
Any help appreciated.
rob willemsen
============ code: 1 image.jpg of your own needed to run ==============
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.LookupOp;
import java.awt.image.LookupTable;
import java.awt.image.ShortLookupTable;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
public class rw_lookup_xp extends Applet {
private BufferedImage biSrc1, biDst1;
private BufferedImage biSrc2, biDst2;
private BufferedImage biSrc3, biDst3;
private BufferedImage biSrc4, biDst4;
private LookupOp op;
@Override
public void init() {
this.setSize(850, 350);
createLookup();
URL url = getClass().getResource("image.jpg");
biSrc1 = readImage1(url);
biSrc2 = readImage2(url);
biSrc3 = readImage3(url);
biSrc4 = readImage4(url);
}
@Override
public void paint(Graphics g) {
//super.paint(g);
Graphics2D g2 = (Graphics2D) g;
g2.drawImage(biSrc1, 10, 10, null);
//sleep(1000);
biDst1 = op.filter(biSrc1, null);
g2.drawImage(biDst1, 10, 160, null);
g2.drawImage(biSrc2, 210, 10, null);
//sleep(1000);
biDst2 = op.filter(biSrc2, null);
g2.drawImage(biDst2, 210, 160, null);
g2.drawImage(biSrc3, 410, 10, null);
//sleep(1000);
biDst3 = op.filter(biSrc3, null);
g2.drawImage(biDst3, 410, 160, null);
g2.drawImage(biSrc4, 610, 10, null);
//sleep(1000);
biDst4 = op.filter(biSrc4, null);
g2.drawImage(biDst4, 610, 160, null);
}
public void sleep(int time) {
try {
Thread.sleep(time);
} catch (InterruptedException evt) {
}
}
private void createLookup() {
short[] brighten = new short[256];
LookupTable table;
for (int i = 0; i < 256; i++) {
brighten[i] = (short) (128 + i / 2);
}
table = new ShortLookupTable(0, brighten);
op = new LookupOp(table, null);
}
private BufferedImage readImage1(URL url) {
Image image = new ImageIcon(url).getImage();
BufferedImage temp = toBI(image, BufferedImage.TYPE_INT_RGB);
return temp;
}
private BufferedImage readImage2(URL url) {
Image image = new ImageIcon(url).getImage();
BufferedImage temp1 = toBI(image, BufferedImage.TYPE_INT_RGB);
BufferedImage temp = toCBI(temp1);
return temp;
}
private BufferedImage readImage3(URL url) {
BufferedImage temp = null;
try {
temp = toBI(ImageIO.read(url), BufferedImage.TYPE_INT_RGB);
} catch (IOException e) {
e.printStackTrace();
}
return temp;
}
private BufferedImage readImage4(URL url) {
BufferedImage temp = null;
try {
temp = toCBI(ImageIO.read(url));
} catch (IOException e) {
e.printStackTrace();
}
return temp;
}
private BufferedImage toBI(Image image, int imageType) {
BufferedImage temp = new BufferedImage(
image.getWidth(null), image.getHeight(null), imageType);
Graphics2D g2 = temp.createGraphics();
g2.drawImage(image, null, null);
return temp;
}
//from the source of the Filthy Rich Clients book by Haase/Guy
private BufferedImage toCBI(BufferedImage image) {
GraphicsEnvironment e =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice d = e.getDefaultScreenDevice();
GraphicsConfiguration c = d.getDefaultConfiguration();
BufferedImage compatibleImage = c.createCompatibleImage(
image.getWidth(), image.getHeight());
Graphics g = compatibleImage.getGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
return compatibleImage;
}
}
[Message sent by forum member 'rtwillem' (rtwillem)]
http://forums.java.net/jive/thread.jspa?messageID=263920
===========================================================================
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".