我想看看里面是怎么对图片的颜色进行像素处理的,可是jdk的源代码中只有这样的声明内容:    /**
     * Sets the paint mode of this graphics context to overwrite the 
     * destination with this graphics context's current color. 
     * This sets the logical pixel operation function to the paint or
     * overwrite mode.  All subsequent rendering operations will
     * overwrite the destination with the current color. 
     */
    public abstract void setPaintMode();    /**
     * Sets the paint mode of this graphics context to alternate between 
     * this graphics context's current color and the new specified color. 
     * This specifies that logical pixel operations are performed in the 
     * XOR mode, which alternates pixels between the current color and 
     * a specified XOR color. 
     * <p>
     * When drawing operations are performed, pixels which are the 
     * current color are changed to the specified color, and vice versa. 
     * <p>
     * Pixels that are of colors other than those two colors are changed 
     * in an unpredictable but reversible manner; if the same figure is 
     * drawn twice, then all pixels are restored to their original values. 
     * @param     c1 the XOR alternation color
     */
    public abstract void setXORMode(Color c1);因为Graphics只是个虚类,没有实现,他的另个子类我也看了,同样没有实现内容,这部分代码是怎么写的呢?
或者哪位有能实现这种类似功能的开源包或者代码的,请提示一下!

解决方案 »

  1.   

    Graphics的子类DebugGraphics不是抽象类有源码。
      

  2.   

    DebugGraphics类中这个方法是调用的,所以也没有实际代码。
      

  3.   

    DebugGraphics里面这么写的
    Graphics  graphics;
    public void setPaintMode() {
            if (debugLog()) {
                info().log(toShortString() + " Setting paint mode");
            }
            graphics.setPaintMode();
        }
     public void setXORMode(Color aColor) {
            if (debugLog()) {
                info().log(toShortString() + " Setting XOR mode: " + aColor);
            }
            graphics.setXORMode(aColor);
        }
      

  4.   

    你看Component中getGraphics()的代码:
        /**
         * Creates a graphics context for this component. This method will
         * return <code>null</code> if this component is currently not
         * displayable.
         * @return a graphics context for this component, or <code>null</code>
         *             if it has none
         * @see       #paint
         * @since     JDK1.0
         */
        public Graphics getGraphics() {
            if (peer instanceof LightweightPeer) {
                // This is for a lightweight component, need to
                // translate coordinate spaces and clip relative
                // to the parent.
                if (parent == null) return null;
                Graphics g = parent.getGraphics();
                if (g == null) return null;
                if (g instanceof ConstrainableGraphics) {
                    ((ConstrainableGraphics) g).constrain(x, y, width, height);
                } else {
                    g.translate(x,y);
                    g.setClip(0, 0, width, height);
                }
                g.setFont(getFont());
                return g;
            } else {
                ComponentPeer peer = this.peer;
                return (peer != null) ? peer.getGraphics() : null;
            }
        }
      

  5.   


    这里面调用的是父类的setPaintMode()方法,我想看的正是父类的setPaintMode()是怎么实现的,所以这段代码没有帮助。
      

  6.   

    这段代码跟setPaintMode()和setXORMode(Color c1)方法有任何关系吗?
      

  7.   

    为了寻找Graphics的实现。sun.java2d.SunGraphics2D.java
    http://www.google.com/codesearch/p?hl=en#Vph8Harfcw0/src/share/classes/sun/java2d/SunGraphics2D.java&q=sun.java2d.SunGraphics2D&sa=N&cd=3&ct=rc    public void setPaintMode() {
            setComposite(AlphaComposite.SrcOver);
        }    public void setXORMode(Color c) {
            if (c == null) {
                throw new IllegalArgumentException("null XORColor");
            }
            setComposite(new XORComposite(c, surfaceData));
        }
      

  8.   

    看到了,谢谢。有sun这个包的文档下载吗?我看到里面有很多好东西
      

  9.   

    这个属于底层实现,没有类似javadoc的文档。有兴趣的话可以看看OpenJDK。