/** * Set current pen color. Default to black if null. * * @param c new pen color. */ public void setColor(Color c) { if (c != null) { m_localGraphicsState.setColor(c); if (m_psGraphicsState.getColor().equals(c)) { return; } m_psGraphicsState.setColor(c); } else { m_localGraphicsState.setColor(Color.black); m_psGraphicsState.setColor(getColor()); } m_printstream.print(getColor().getRed() / 255.0); m_printstream.print(" "); m_printstream.print(getColor().getGreen() / 255.0); m_printstream.print(" "); m_printstream.print(getColor().getBlue() / 255.0); m_printstream.println(" setrgbcolor"); }
/** * PS see http://astronomy.swin.edu.au/~pbourke/geomformats/postscript/ Java * http://show.docjava.com:8086/book/cgij/doc/ip/graphics/SimpleImageFrame.java.html */ public boolean drawImage( Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) { try { // get data from image int[] pixels = new int[width * height]; PixelGrabber grabber = new PixelGrabber(img, 0, 0, width, height, pixels, 0, width); grabber.grabPixels(); ColorModel model = ColorModel.getRGBdefault(); // print data to ps m_printstream.println("gsave"); m_printstream.println( xTransform(xScale(x)) + " " + (yTransform(yScale(y)) - yScale(height)) + " translate"); m_printstream.println(xScale(width) + " " + yScale(height) + " scale"); m_printstream.println( width + " " + height + " " + "8" + " [" + width + " 0 0 " + (-height) + " 0 " + height + "]"); m_printstream.println("{<"); int index; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { index = i * width + j; m_printstream.print(toHex(model.getRed(pixels[index]))); m_printstream.print(toHex(model.getGreen(pixels[index]))); m_printstream.print(toHex(model.getBlue(pixels[index]))); } m_printstream.println(); } m_printstream.println(">}"); m_printstream.println("false 3 colorimage"); m_printstream.println("grestore"); return true; } catch (Exception e) { e.printStackTrace(); return false; } }