"Print Image" Problem

Hi! My name is Adrian Luna, I am doing a proyect in JAVA where I need to print an image in a plotter.

I have had success when I print an image in a common printer using the class "PrinterJob" and "Book", but the plotter does not recieve the information.

In order to resolve the problem, I have to use the class "PrintJob" and the plotter replies very well. But now, there is a exception (Exception occurred during event dispatching: java.lang.IllegalArgumentException: invalid ColorModel) when I use the instruction:

"g.drawImage(imgPrint,(int)imgX,(int)imgY,(int)imgWidth,(int)imgHeight,Color.white,null);"

Thank you, I will be glad if you could help me.

***********************************************

This is the code:

PrintJob pj = toolkit.getPrintJob (this,"Print",properties);

if (pj != null)

{

Graphics g = pj.getGraphics();

pageDim = pj.getPageDimension();

double imgX = 0;

double imgY = 0;

double imgWidth = pageDim.width;

double imgHeight = pageDim.height;

imgX = centimetroToPixel((double)1.0);

imgY = imgX;

imgWidth -= ((double)2*imgX);

imgHeight -= ((double)2*imgY);

g.setColor(Color.white);

g.fillRect(0,0,(int)pageDim.width,(int)pageDim.height);

g.drawImage(imgPrint,(int)imgX,(int)imgY,(int)imgWidth,(int)imgHeight,Color.white,null);

g.dispose();

pj.end();

}

public double centimetroToPixel(double x)

{

return (double)((x*10*1224)/(double)431.8);

}

*********************************************

[1613 byte] By [adrianluna] at [2007-9-26 3:01:46]
# 1
Hello,Have you tried with another color (Color.black for instance) to check wheter the error occured with white or not.By the way, I'm not sure it's a good idea to give null as the last argument. Please check this out too.Hope this helps,Stephane
-DarkLord- at 2007-6-29 11:00:09 > top of Java-index,Archived Forums,Java Programming...
# 2
Hi,I think your problem is the format of the image imgPrint. How did you create it? As I know it must be compatible with your plotter's color model.Try to create it with the GraphicsConfiguration.createCompatibleImage() method.Hope it helps. Regards,Martin
edosoft at 2007-6-29 11:00:09 > top of Java-index,Archived Forums,Java Programming...
# 3

Thanks -DarkLord- and edosoft.

DarkLord: If I understand, I have to rewrite the instruction "g.drawImage(imgPrint,(int)imgX,(int)imgY,(int)imgWidth,(int)imgHeight,Color.white,null);

"

as

"g.drawImage(imgPrint,(int)imgX,(int)imgY,(int)imgWidth,(int)imgHeight,Color.black,null);

"

I tried but I have the same problem

"Exception occurred during event dispatching: java.lang.IllegalArgumentException: invalid ColorModel"

Any coment pleasea send me!!!

*********************************************

edosoft:

In the original proyect, I have to create my own image and I do it on a BufferedImage, with the next instruction:

"private BufferedImage imagenMatriz = new BufferedImage (pageDim.width,pageDim.height,BufferedImage.TYPE_INT_RGB);"

But I did a small program where I test how to print a image from a file such as "GIF" or "JPG"

I get the image with the next set of intructions

+++++++++++++++

imgPrint = getToolkit().getImage("world.gif");

MediaTracker tracker = new MediaTracker(this);

try

{

tracker.addImage(imgPrint,0);

tracker.waitForAll(0);

} catch (Exception e)

{

e.printStackTrace();

}

+++++++++++++++++++++++

Could you send me some examples about GraphicsConfiguration.createCompatibleImage() ?

Thanks!!!

adrianluna at 2007-6-29 11:00:09 > top of Java-index,Archived Forums,Java Programming...