Exemple #1
0
        private void WriteXorBitmap(BufferedImage img)
        {
            Raster raster = img.getRaster();

            switch (img.getColorModel().getPixelSize())
            {
            case 1:
                Write1(raster);
                break;

            case 4:
                Write4(raster);
                break;

            case 8:
                Write8(raster);
                break;

            case 24:
                Write24(raster);
                break;

            case 32:
                Raster alpha = img.getAlphaRaster();
                Write32(raster, alpha);
                break;
            }
        }
        public virtual BufferedImage filter(BufferedImage src, BufferedImage dest)
        {
            if (dest == null)
            {
                dest = createCompatibleDestImage(src, null);
            }
            int width  = src.getWidth();
            int height = src.getHeight();

            int[] inPixels  = new int[width * height];
            int[] outPixels = new int[width * height];
            src.getRaster().getDataElements(0, 0, width, height, inPixels);
            filter(inPixels, outPixels, width, height);
            dest.getRaster().setDataElements(0, 0, width, height, outPixels);
            return(dest);
        }
Exemple #3
0
        /// <summary>
        /// Encodes the <em>AND</em> bitmap for the given image according the its
        /// alpha channel (transparency) and writes it to the given output.
        /// </summary>
        /// <param name="img">
        ///            the image to encode as the <em>AND</em> bitmap. </param>
        private void WriteAndBitmap(BufferedImage img)
        {
            WritableRaster alpha = img.getAlphaRaster();

            // indexed transparency (eg. GIF files)
            if (img.getColorModel() is IndexColorModel && img.getColorModel().hasAlpha())
            {
                int w = img.getWidth();
                int h = img.getHeight();

                int bytesPerLine = GetBytesPerLine1(w);

                byte[] line = new byte[bytesPerLine];

                IndexColorModel icm    = (IndexColorModel)img.getColorModel();
                Raster          raster = img.getRaster();

                for (int y = h - 1; y >= 0; y--)
                {
                    for (int x = 0; x < w; x++)
                    {
                        int bi = x / 8;
                        int i  = x % 8;
                        // int a = alpha.getSample(x, y, 0);
                        int p = raster.getSample(x, y, 0);
                        int a = icm.getAlpha(p);
                        // invert bit since and mask is applied to xor mask
                        int b = ~a & 1;
                        line[bi] = SetBit(line[bi], i, b);
                    }

                    writer.Write(line);
                }
            }
            // no transparency
            else if (alpha == null)
            {
                int h = img.getHeight();
                int w = img.getWidth();
                // calculate number of bytes per line, including 32-bit padding
                int bytesPerLine = GetBytesPerLine1(w);

                byte[] line = new byte[bytesPerLine];
                for (int i = 0; i < bytesPerLine; i++)
                {
                    line[i] = (byte)0;
                }

                for (int y = h - 1; y >= 0; y--)
                {
                    writer.Write(line);
                }
            }
            // transparency (ARGB, etc. eg. PNG)
            else
            {
                int w = img.getWidth();
                int h = img.getHeight();

                int bytesPerLine = GetBytesPerLine1(w);

                byte[] line = new byte[bytesPerLine];

                for (int y = h - 1; y >= 0; y--)
                {
                    for (int x = 0; x < w; x++)
                    {
                        int bi = x / 8;
                        int i  = x % 8;
                        int a  = alpha.getSample(x, y, 0);
                        // invert bit since and mask is applied to xor mask
                        int b = ~a & 1;
                        line[bi] = SetBit(line[bi], i, b);
                    }

                    writer.Write(line);
                }
            }
        }
 public Rectangle2D getBounds2D(BufferedImage src)
 {
     return(src.getRaster().getBounds());
 }