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


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?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I think you have to give params to the Colorspace.
Patrix78Author Commented:
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;

    Graphics2D g2D = (Graphics2D)g;

    if (this.mode==Print.NORMAL_PAGE)
        if (pageOrientation==PageFormat.PORTRAIT)


    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?


You may want to take a look at how RGB to grayscale conversion has been approached here.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.