Java 类java.awt.image.BandCombineOp 实例源码

项目:jglrEngine    文件:ImageUtils.java   
public static BufferedImage recolor(BufferedImage src, Color sc)
{
    float[][] colorMatrix =
    {
            {
                    ((float)sc.getRed()) / 255f, 0, 0, 0
            },
            {
                    ((float)sc.getGreen()) / 255f, 0, 0, 0
            },
            {
                    ((float)sc.getBlue()) / 255f, 0, 0, 0
            },
            {
                    0f, 0f, 0f, 1f
            }
    };
    BandCombineOp changeColors = new BandCombineOp(colorMatrix, null);
    Raster sourceRaster = src.getRaster();
    WritableRaster displayRaster = sourceRaster.createCompatibleWritableRaster();
    changeColors.filter(sourceRaster, displayRaster);
    return new BufferedImage(src.getColorModel(), displayRaster, true, null);
}
项目:iSeleda    文件:ShadowFilter.java   
@Override
   public BufferedImage filter(BufferedImage src, BufferedImage dst) {
       int width = src.getWidth();
       int height = src.getHeight();

       float xOffset = distance * (float) Math.cos(angle);
       float yOffset = -distance * (float) Math.sin(angle);

       if (dst == null) {
           if (addMargins) {
               ColorModel cm = src.getColorModel();
               dst = new BufferedImage(cm, cm.createCompatibleWritableRaster(src.getWidth() + (int) (Math.abs(xOffset) + radius), src.getHeight() + (int) (Math.abs(yOffset) + radius)), cm.isAlphaPremultiplied(), null);
           } else {
               dst = createCompatibleDestImage(src, null);
           }
       }

       float shadowR = ((shadowColor >> 16) & 0xff) / 255f;
       float shadowG = ((shadowColor >> 8) & 0xff) / 255f;
       float shadowB = (shadowColor & 0xff) / 255f;

       // Make a black mask from the image's alpha channel
       float[][] extractAlpha = {
               {0, 0, 0, shadowR},
               {0, 0, 0, shadowG},
               {0, 0, 0, shadowB},
               {0, 0, 0, opacity}
       };
       BufferedImage shadow = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
       new BandCombineOp(extractAlpha, null).filter(src.getRaster(), shadow.getRaster());
       shadow = new GaussianFilter(radius).filter(shadow, null);

       Graphics2D g = dst.createGraphics();
       g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
       if (addMargins) {
           float radius2 = radius / 2;
           float topShadow = Math.max(0, radius - yOffset);
           float leftShadow = Math.max(0, radius - xOffset);
           g.translate(leftShadow, topShadow);
       }
       g.drawRenderedImage(shadow, AffineTransform.getTranslateInstance(xOffset, yOffset ) );
    if ( !shadowOnly ) {
        g.setComposite( AlphaComposite.SrcOver );
        g.drawRenderedImage( src, null );
    }
    g.dispose();

       return dst;
}
项目:Lucee4    文件:ShadowFilter.java   
public BufferedImage filter( BufferedImage src, BufferedImage dst ) {
       int width = src.getWidth();
       int height = src.getHeight();

       if ( dst == null ) {
           if ( addMargins ) {
            ColorModel cm = src.getColorModel();
            dst = new BufferedImage(cm, cm.createCompatibleWritableRaster(src.getWidth(), src.getHeight()), cm.isAlphaPremultiplied(), null);
        } else
            dst = createCompatibleDestImage( src, null );
    }

       float shadowR = ((shadowColor >> 16) & 0xff) / 255f;
       float shadowG = ((shadowColor >> 8) & 0xff) / 255f;
       float shadowB = (shadowColor & 0xff) / 255f;

    // Make a black mask from the image's alpha channel 
       float[][] extractAlpha = {
           { 0, 0, 0, shadowR },
           { 0, 0, 0, shadowG },
           { 0, 0, 0, shadowB },
           { 0, 0, 0, opacity }
       };
       BufferedImage shadow = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
       new BandCombineOp( extractAlpha, null ).filter( src.getRaster(), shadow.getRaster() );
       shadow = new GaussianFilter( radius ).filter( shadow, (BufferedImage)null );

    float xOffset = distance*(float)Math.cos(angle);
    float yOffset = -distance*(float)Math.sin(angle);

    Graphics2D g = dst.createGraphics();
    g.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, opacity ) );
    if ( addMargins ) {
        //float radius2 = radius/2;
        float topShadow = Math.max( 0, radius-yOffset );
        float leftShadow = Math.max( 0, radius-xOffset );
        g.translate( topShadow, leftShadow );
    }
    g.drawRenderedImage( shadow, AffineTransform.getTranslateInstance( xOffset, yOffset ) );
    if ( !shadowOnly ) {
        g.setComposite( AlphaComposite.SrcOver );
        g.drawRenderedImage( src, null );
    }
    g.dispose();

       return dst;
}
项目:webcamstudio    文件:ShadowFilter.java   
@Override
   public BufferedImage filter( BufferedImage src, BufferedImage dst ) {
       int width = src.getWidth();
       int height = src.getHeight();

       if ( dst == null ) {
           if ( addMargins ) {
            ColorModel cm = src.getColorModel();
            dst = new BufferedImage(cm, cm.createCompatibleWritableRaster(src.getWidth(), src.getHeight()), cm.isAlphaPremultiplied(), null);
        } else {
               dst = createCompatibleDestImage( src, null );
           }
    }

       float shadowR = ((shadowColor >> 16) & 0xff) / 255f;
       float shadowG = ((shadowColor >> 8) & 0xff) / 255f;
       float shadowB = (shadowColor & 0xff) / 255f;

    // Make a black mask from the image's alpha channel 
       float[][] extractAlpha = {
           { 0, 0, 0, shadowR },
           { 0, 0, 0, shadowG },
           { 0, 0, 0, shadowB },
           { 0, 0, 0, opacity }
       };
       BufferedImage shadow = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
       new BandCombineOp( extractAlpha, null ).filter( src.getRaster(), shadow.getRaster() );
       shadow = new GaussianFilter( radius ).filter( shadow, null );

    float xOffset = distance*(float)Math.cos(angle);
    float yOffset = -distance*(float)Math.sin(angle);

    Graphics2D g = dst.createGraphics();
               g.setRenderingHint(RenderingHints.KEY_RENDERING,
                                  RenderingHints.VALUE_RENDER_SPEED);
               g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                  RenderingHints.VALUE_ANTIALIAS_OFF);
               g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                                  RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
               g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                                  RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
               g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
                                  RenderingHints.VALUE_COLOR_RENDER_SPEED);
               g.setRenderingHint(RenderingHints.KEY_DITHERING,
                                  RenderingHints.VALUE_DITHER_DISABLE);
    g.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, opacity ) );
    if ( addMargins ) {
        float radius2 = radius/2;
        float topShadow = Math.max( 0, radius-yOffset );
        float leftShadow = Math.max( 0, radius-xOffset );
        g.translate( topShadow, leftShadow );
    }
    g.drawRenderedImage( shadow, AffineTransform.getTranslateInstance( xOffset, yOffset ) );
    if ( !shadowOnly ) {
        g.setComposite( AlphaComposite.SrcOver );
        g.drawRenderedImage( src, null );
    }
    g.dispose();

       return dst;
}
项目:Lucee    文件:ShadowFilter.java   
@Override
public BufferedImage filter( BufferedImage src, BufferedImage dst ) {
       int width = src.getWidth();
       int height = src.getHeight();

       if ( dst == null ) {
           if ( addMargins ) {
            ColorModel cm = src.getColorModel();
            dst = new BufferedImage(cm, cm.createCompatibleWritableRaster(src.getWidth(), src.getHeight()), cm.isAlphaPremultiplied(), null);
        } else
            dst = createCompatibleDestImage( src, null );
    }

       float shadowR = ((shadowColor >> 16) & 0xff) / 255f;
       float shadowG = ((shadowColor >> 8) & 0xff) / 255f;
       float shadowB = (shadowColor & 0xff) / 255f;

    // Make a black mask from the image's alpha channel 
       float[][] extractAlpha = {
           { 0, 0, 0, shadowR },
           { 0, 0, 0, shadowG },
           { 0, 0, 0, shadowB },
           { 0, 0, 0, opacity }
       };
       BufferedImage shadow = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
       new BandCombineOp( extractAlpha, null ).filter( src.getRaster(), shadow.getRaster() );
       shadow = new GaussianFilter( radius ).filter( shadow, (BufferedImage)null );

    float xOffset = distance*(float)Math.cos(angle);
    float yOffset = -distance*(float)Math.sin(angle);

    Graphics2D g = dst.createGraphics();
    g.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, opacity ) );
    if ( addMargins ) {
        //float radius2 = radius/2;
        float topShadow = Math.max( 0, radius-yOffset );
        float leftShadow = Math.max( 0, radius-xOffset );
        g.translate( topShadow, leftShadow );
    }
    g.drawRenderedImage( shadow, AffineTransform.getTranslateInstance( xOffset, yOffset ) );
    if ( !shadowOnly ) {
        g.setComposite( AlphaComposite.SrcOver );
        g.drawRenderedImage( src, null );
    }
    g.dispose();

       return dst;
}
项目:WebLookAndFeelLite    文件:ShadowFilter.java   
@Override
public BufferedImage filter ( BufferedImage src, BufferedImage dst )
{
    int width = src.getWidth ();
    int height = src.getHeight ();

    if ( dst == null )
    {
        if ( addMargins )
        {
            ColorModel cm = src.getColorModel ();
            dst = new BufferedImage ( cm, cm.createCompatibleWritableRaster ( src.getWidth (), src.getHeight () ),
                    cm.isAlphaPremultiplied (), null );
        }
        else
        {
            dst = createCompatibleDestImage ( src, null );
        }
    }

    // Make a black mask from the image's alpha channel
    float[][] extractAlpha = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, opacity } };
    BufferedImage shadow = new BufferedImage ( width, height, BufferedImage.TYPE_INT_ARGB );
    new BandCombineOp ( extractAlpha, null ).filter ( src.getRaster (), shadow.getRaster () );
    shadow = new GaussianFilter ( radius ).filter ( shadow, null );

    Graphics2D g = dst.createGraphics ();
    g.setComposite ( AlphaComposite.getInstance ( AlphaComposite.SRC_OVER, opacity ) );
    if ( addMargins )
    {
        int topShadow = Math.max ( 0, radius - yOffset );
        int leftShadow = Math.max ( 0, radius - xOffset );
        g.translate ( topShadow, leftShadow );
    }
    g.drawRenderedImage ( shadow, AffineTransform.getTranslateInstance ( xOffset, yOffset ) );
    if ( !shadowOnly )
    {
        g.setComposite ( AlphaComposite.SrcOver );
        g.drawRenderedImage ( src, null );
    }
    g.dispose ();

    return dst;
}
项目:captcha4j    文件:ShadowFilter.java   
public BufferedImage filter( BufferedImage src, BufferedImage dst ) {
       int width = src.getWidth();
       int height = src.getHeight();

    float xOffset = distance*(float)Math.cos(angle);
    float yOffset = -distance*(float)Math.sin(angle);

       if ( dst == null ) {
           if ( addMargins ) {
            ColorModel cm = src.getColorModel();
            dst = new BufferedImage(cm, cm.createCompatibleWritableRaster(src.getWidth() + (int) (Math.abs(xOffset) + radius), src.getHeight() + (int) (Math.abs(yOffset) + radius)), cm.isAlphaPremultiplied(), null);
        } else
            dst = createCompatibleDestImage( src, null );
    }

       float shadowR = ((shadowColor >> 16) & 0xff) / 255f;
       float shadowG = ((shadowColor >> 8) & 0xff) / 255f;
       float shadowB = (shadowColor & 0xff) / 255f;

    // Make a black mask from the image's alpha channel 
       float[][] extractAlpha = {
           { 0, 0, 0, shadowR },
           { 0, 0, 0, shadowG },
           { 0, 0, 0, shadowB },
           { 0, 0, 0, opacity }
       };
       BufferedImage shadow = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
       new BandCombineOp( extractAlpha, null ).filter( src.getRaster(), shadow.getRaster() );
       shadow = new GaussianFilter( radius ).filter( shadow, null );

    Graphics2D g = dst.createGraphics();
    g.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, opacity ) );
    if ( addMargins ) {
        float radius2 = radius/2;
        float topShadow = Math.max( 0, radius-yOffset );
        float leftShadow = Math.max( 0, radius-xOffset );
        g.translate( leftShadow, topShadow );
    }
    g.drawRenderedImage( shadow, AffineTransform.getTranslateInstance( xOffset, yOffset ) );
    if ( !shadowOnly ) {
        g.setComposite( AlphaComposite.SrcOver );
        g.drawRenderedImage( src, null );
    }
    g.dispose();

       return dst;
}