Example #1
0
        /**
         * @see Graphics#drawImage(Image, int, int, int, int, int, int, int, int, Color, ImageObserver)
         */
        public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
        {
            double dwidth  = (double)dx2 - dx1;
            double dheight = (double)dy2 - dy1;
            double swidth  = (double)sx2 - sx1;
            double sheight = (double)sy2 - sy1;

            //if either width or height is 0, then there is nothing to draw
            if (dwidth == 0 || dheight == 0 || swidth == 0 || sheight == 0)
            {
                return(true);
            }

            double scalex = dwidth / swidth;
            double scaley = dheight / sheight;

            double          transx = sx1 * scalex;
            double          transy = sy1 * scaley;
            AffineTransform tx     = AffineTransform.getTranslateInstance(dx1 - transx, dy1 - transy);

            tx.scale(scalex, scaley);

            BufferedImage mask = new BufferedImage(img.getWidth(observer), img.getHeight(observer), BufferedImage.TYPE_BYTE_BINARY);
            Graphics      g    = mask.getGraphics();

            g.fillRect(sx1, sy1, (int)swidth, (int)sheight);
            drawImage(img, mask, tx, null, observer);
            return(true);
        }
Example #2
0
        public void fillBackground(BufferedImage dest)
        {
            Graphics g = dest.getGraphics();

            g.setColor(colorFactory.getColor(0));
            g.fillRect(0, 0, dest.getWidth(), dest.getHeight());
        }
        private BufferedImage toBufferedImage(BitMatrix bitMatrix)
        {
            if (bitMatrix == null)
            {
                throw new IllegalArgumentException("BitMatrix cannot be null");
            }
            int           width  = bitMatrix.getWidth();
            int           height = bitMatrix.getHeight();
            BufferedImage image  = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED);

            image.createGraphics();
            Graphics2D graphics = (Graphics2D)image.getGraphics();

            graphics.setColor(Color.WHITE);
            graphics.fillRect(0, 0, width, height);
            graphics.setColor(Color.BLACK);
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    if (bitMatrix.get(i, j))
                    {
                        graphics.fillRect(i, j, 1, 1);
                    }
                }
            }
            return(image);
        }
        public QuercusImage(int width, int height)
        {
            _bufferedImage = new BufferedImage(width, height,
                                               BufferedImage.TYPE_INT_RGB);
            _graphics = (Graphics2D)_bufferedImage.getGraphics();

            _isBlankImage = true;
        }
 public QuercusImage(Env env, string filename)
 {
     try {
         _bufferedImage = ImageIO.read(filename.openRead());
         _graphics      = (Graphics2D)_bufferedImage.getGraphics();
     }
     catch (IOException e) {
         throw new QuercusException(e);
     }
 }
 public QuercusImage(InputStream inputStream)
 {
     try {
         _bufferedImage = ImageIO.read(inputStream);
         _graphics      = (Graphics2D)_bufferedImage.getGraphics();
     }
     catch (IOException e) {
         throw new QuercusException(e);
     }
 }
Example #7
0
 private void setPaint(Paint paint, boolean invert, double xoffset, double yoffset)
 {
     this.paint = paint;
     if (paint is Color)
     {
         cb.setColorFill((Color)paint);
     }
     else if (paint is GradientPaint)
     {
         GradientPaint gp = (GradientPaint)paint;
         Point2D       p1 = gp.getPoint1();
         transform.transform(p1, p1);
         Point2D p2 = gp.getPoint2();
         transform.transform(p2, p2);
         Color             c1      = gp.getColor1();
         Color             c2      = gp.getColor2();
         PdfShading        shading = PdfShading.simpleAxial(cb.getPdfWriter(), (float)p1.getX(), (float)p1.getY(), (float)p2.getX(), (float)p2.getY(), c1, c2);
         PdfShadingPattern pat     = new PdfShadingPattern(shading);
         cb.setShadingFill(pat);
     }
     else
     {
         try {
             BufferedImage img  = null;
             int           type = BufferedImage.TYPE_4BYTE_ABGR;
             if (paint.getTransparency() == Transparency.OPAQUE)
             {
                 type = BufferedImage.TYPE_3BYTE_BGR;
             }
             img = new BufferedImage((int)width, (int)height, type);
             Graphics2D g        = (Graphics2D)img.getGraphics();
             Shape      fillRect = new Rectangle2D.Double(0, 0, img.getWidth(),
                                                          img.getHeight());
             g.setPaint(paint);
             g.fill(fillRect);
             if (invert)
             {
                 AffineTransform tx = new AffineTransform();
                 tx.scale(1, -1);
                 tx.translate(-xoffset, -yoffset);
                 g.drawImage(img, tx, null);
             }
             com.lowagie.text.Image image   = com.lowagie.text.Image.getInstance(img, null);
             PdfPatternPainter      pattern = cb.createPattern(width, height);
             image.setAbsolutePosition(0, 0);
             pattern.addImage(image);
             cb.setPatternFill(pattern);
         } catch (Exception ex) {
             cb.setColorFill(Color.gray);
         }
     }
 }
        public override BufferedImage filter(BufferedImage src, BufferedImage dest)
        {
            if (dest == null)
            {
                dest = createCompatibleDestImage(src, null);
            }
            double     width  = dest.getWidth();
            double     height = dest.getHeight();
            Graphics2D g2     = (Graphics2D)src.getGraphics();

            g2.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
            Random r  = new Random();
            int    cp = 4 + r.Next(3);

            int[] xPoints = new int[cp];
            int[] yPoints = new int[cp];
            width -= 10;
            for (int i = 0; i < cp; i++)
            {
                xPoints[i] = (int)((int)5 + (i * width) / (cp - 1));
                yPoints[i] = (int)(height * (r.NextDouble() * 0.5 + 0.2));
            }
            int subsections = 6;

            int[] xPointsSpline = new int[(cp - 1) * subsections];
            int[] yPointsSpline = new int[(cp - 1) * subsections];
            for (int i = 0; i < cp - 1; i++)
            {
                double x0 = i > 0 ? xPoints[i - 1] : 2 * xPoints[i] - xPoints[i + 1];
                double x1 = xPoints[i];
                double x2 = xPoints[i + 1];
                double x3 = (i + 2 < cp) ? xPoints[i + 2] : 2 * xPoints[i + 1] - xPoints[i];
                double y0 = i > 0 ? yPoints[i - 1] : 2 * yPoints[i] - yPoints[i + 1];
                double y1 = yPoints[i];
                double y2 = yPoints[i + 1];
                double y3 = (i + 2 < cp) ? yPoints[i + 2] : 2 * yPoints[i + 1] - yPoints[i];
                for (int j = 0; j < subsections; j++)
                {
                    xPointsSpline[i * subsections + j] = (int)catmullRomSpline(x0, x1, x2, x3, 1.0 / subsections * j);
                    yPointsSpline[i * subsections + j] = (int)catmullRomSpline(y0, y1, y2, y3, 1.0 / subsections * j);
                }
            }
            for (int i = 0; i < xPointsSpline.Length - 1; i++)
            {
                g2.setColor(colorFactory.getColor(i));
                g2.setStroke(new BasicStroke(2 + 2 * r.nextFloat()));
                g2.drawLine(xPointsSpline[i], yPointsSpline[i], xPointsSpline[i + 1], yPointsSpline[i + 1]);
            }
            return(src);
        }
        public void draw(string text, BufferedImage canvas, FontFactory fontFactory, ColorFactory colorFactory)
        {
            Graphics2D g  = (Graphics2D)canvas.getGraphics();
            TextString ts = convertToCharacters(text, g, fontFactory, colorFactory);

            arrangeCharacters(canvas.getWidth(), canvas.getHeight(), ts);
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
            g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
            foreach (TextCharacter tc in ts.Characters)
            {
                g.setColor(tc.Color);
                g.drawString(tc.iterator(), (float)tc.X, (float)tc.Y);
            }
        }
Example #10
0
        public virtual BufferedImage applyFilters(BufferedImage source)
        {
            BufferedImage dest = source;

            foreach (BufferedImageOp filter in Filters)
            {
                //if (filter.GetType().Equals(typeof(CurvesImageOp)))
                //	continue;
                dest = filter.filter(dest, null);
            }
            int x = (source.getWidth() - dest.getWidth()) / 2;
            int y = (source.getHeight() - dest.getHeight()) / 2;

            source = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
            source.getGraphics().drawImage(dest, x, y, null);
            return(source);
        }
 public Graphics2D debugGetOverlayGraphics()
 {
     image = new BufferedImage(ownerBoard.B_WIDTH, ownerBoard.B_HEIGHT, BufferedImage.TYPE_INT_ARGB);
     //image.
     return (Graphics2D)image.getGraphics();
 }