Link to home
Start Free TrialLog in
Avatar of Patrix78
Patrix78

asked on

[java.awt.print] How print in grayscale ?

Hello

I use the java.awt.print  for printing.

but i do not find the way to print in grayscale

how program the PrinterJob in order to print in grayscale?

Patrice
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

I think you have to give params to the Colorspace.
Avatar of Patrix78
Patrix78

ASKER

My code for printing is (sorry for the presentation of the code)

public int print(Graphics g,PageFormat pageFormat,int pageIndex) throws PrinterException
{

    if (pageIndex>nombreDePages-1)
        return NO_SUCH_PAGE;
    else
        this.numeroDePage=pageIndex+1;

    Graphics2D g2D = (Graphics2D)g;

    if (this.mode==Print.NORMAL_PAGE)
    {
        if (pageOrientation==PageFormat.PORTRAIT)
            g2D.scale(0.92,1);
        else
            g2D.scale(0.95,1);
    }


    g2D.translate(12,12);
    paint(g2D);

    return PAGE_EXISTS;
}

In fact, i think i need to apply the filter to the g2D object, but i do nok know how redrawn the g2D in grayscale

maybe i need to extract the Image object of the g2D,
and redraw with g2D.drawImage(new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY, null)

it's the way to follow?

regards

Patrice
ASKER CERTIFIED SOLUTION
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.