Example #1
0
 public void fitSize() {
   BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB);
   FontMetrics fm = bi.getGraphics().getFontMetrics(font);
   java.awt.geom.Rectangle2D rect = fm.getStringBounds(text, bi.getGraphics());
   w = rect.getWidth() + font.getSize();
   h = rect.getHeight();
 }
  private void createShadowBorder() {
    backgroundImage =
        new BufferedImage(
            getWidth() + SHADOW_WIDTH, getHeight() + SHADOW_WIDTH, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D) backgroundImage.getGraphics();

    try {
      Robot robot = new Robot(getGraphicsConfiguration().getDevice());
      BufferedImage capture =
          robot.createScreenCapture(
              new Rectangle(getX(), getY(), getWidth() + SHADOW_WIDTH, getHeight() + SHADOW_WIDTH));
      g2.drawImage(capture, null, 0, 0);
    } catch (AWTException e) {
      e.printStackTrace();
    }

    BufferedImage shadow =
        new BufferedImage(
            getWidth() + SHADOW_WIDTH, getHeight() + SHADOW_WIDTH, BufferedImage.TYPE_INT_ARGB);
    Graphics graphics = shadow.getGraphics();
    graphics.setColor(new Color(0.0f, 0.0f, 0.0f, 0.3f));
    graphics.fillRoundRect(6, 6, getWidth(), getHeight(), 12, 12);

    g2.drawImage(shadow, getBlurOp(7), 0, 0);
  }
Example #3
0
  /**
   * Converts an image (RGB, RGBA, ... whatever) to a binary one based on given threshold
   *
   * @param image the image to convert. Remains untouched.
   * @param threshold the threshold in [0,255]
   * @return a new BufferedImage instance of TYPE_BYTE_GRAY with only 0'S and 255's
   */
  private static BufferedImage thresholdImage(Image imgIn, Image imgOut, int threshold) {
    if (imgOut.getBufferedImage().getType() != BufferedImage.TYPE_BYTE_GRAY) {
      final BufferedImage result =
          new BufferedImage(imgIn.getWidth(), imgIn.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
      final Graphics g = result.getGraphics();
      g.drawImage(imgIn.getBufferedImage(), 0, 0, null);
      g.dispose();

      imgOut.setBufferedImage(result);
      System.err.println("Image was converted into BufferedImage.TYPE_BYTE_GRAY type");
    }

    BufferedImage result = imgOut.getBufferedImage();
    result.getGraphics().drawImage(imgIn.getBufferedImage(), 0, 0, null);
    WritableRaster raster = result.getRaster();
    int[] pixels = new int[imgIn.getWidth()];
    for (int y = 0; y < imgIn.getHeight(); y++) {
      raster.getPixels(0, y, imgIn.getWidth(), 1, pixels);
      for (int i = 0; i < pixels.length; i++) {
        pixels[i] = (pixels[i] < threshold) ? 0 : 255;
      }
      raster.setPixels(0, y, imgIn.getWidth(), 1, pixels);
    }
    return result;
  }
Example #4
0
  private BufferedImage getFontImage(char ch) {
    // Create a temporary image to extract the character's size
    BufferedImage tempfontImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = (Graphics2D) tempfontImage.getGraphics();
    if (antiAlias == true) {
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }
    g.setFont(font);
    fontMetrics = g.getFontMetrics();
    int charwidth = fontMetrics.charWidth(ch) + 8;

    if (charwidth <= 0) {
      charwidth = 7;
    }
    int charheight = fontMetrics.getHeight() + 3;
    if (charheight <= 0) {
      charheight = fontSize;
    }

    // Create another image holding the character we are creating
    BufferedImage fontImage;
    fontImage = new BufferedImage(charwidth, charheight, BufferedImage.TYPE_INT_ARGB);
    Graphics2D gt = (Graphics2D) fontImage.getGraphics();
    if (antiAlias == true) {
      gt.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }
    gt.setFont(font);

    gt.setColor(Color.WHITE);
    int charx = 3;
    int chary = 1;
    gt.drawString(String.valueOf(ch), (charx), (chary) + fontMetrics.getAscent());

    return fontImage;
  }
Example #5
0
    private void paintToImage(
        final BufferedImage img, final int x, final int y, final int width, final int height) {
      // clear the prior image
      Graphics2D imgG = (Graphics2D) img.getGraphics();
      imgG.setComposite(AlphaComposite.Clear);
      imgG.setColor(Color.black);
      imgG.fillRect(0, 0, width + blur * 2, height + blur * 2);

      final int adjX = (int) (x + blur + offsetX + (insets.left * distance));
      final int adjY = (int) (y + blur + offsetY + (insets.top * distance));
      final int adjW = (int) (width - (insets.left + insets.right) * distance);
      final int adjH = (int) (height - (insets.top + insets.bottom) * distance);

      // let the delegate paint whatever they want to be blurred
      imgG.setComposite(AlphaComposite.DstAtop);
      if (prePainter != null) prePainter.paint(imgG, adjX, adjY, adjW, adjH);
      imgG.dispose();

      // blur the prior image back into the same pixels
      imgG = (Graphics2D) img.getGraphics();
      imgG.setComposite(AlphaComposite.DstAtop);
      imgG.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
      imgG.setRenderingHint(
          RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
      imgG.drawImage(img, blurOp, 0, 0);

      if (postPainter != null) postPainter.paint(imgG, adjX, adjY, adjW, adjH);
      imgG.dispose();
    }
Example #6
0
 private static ImageElement fetchImageProperties(
     final BufferedImage source,
     final ImageType imageType,
     final String id,
     final Date modifiedDate,
     final String mimeType)
     throws NullPointerException, IOException {
   if (verifyNotNull(source)) {
     ImageElement image = new ImageElement();
     image.setBitDepth(
         verifyNotNull(source.getColorModel().getPixelSize())
             ? source.getColorModel().getPixelSize()
             : 0);
     image.setHeight(verifyNotNull(source.getHeight()) ? source.getHeight() : 0);
     image.setWidth(verifyNotNull(source.getWidth()) ? source.getWidth() : 0);
     image.setSizeInBytes(determineSizeOfBufferedImage(source, imageType.toString()));
     image.setCreated(new Date(System.currentTimeMillis()));
     image.setTransparent(
         determineTransparencyType(source.getGraphics().getColor().getTransparency()));
     if (verifyNotNull(modifiedDate)) image.setModified(modifiedDate);
     image.setId((verifyNotNull(id) ? id : ""));
     image.setFontType(
         verifyNotNull(source.getGraphics().getFont())
             ? source.getGraphics().getFont()
             : new Font("Default", 0, 0));
     image.setMediaType(MediaType.Missing);
     return image;
   }
   throw new NullPointerException(E_OBJECT_WAS_NULL);
 }
Example #7
0
 public static void updateMetrics() {
   BufferedImage junkst = TexI.mkbuf(new Coord(10, 10));
   STANDALONE = junkst.getGraphics();
   BufferedImage junk = TexI.mkbuf(new Coord(10, 10));
   CONTEXT = junk.getGraphics();
   CONTEXT.setFont(FONT);
   METRICS = CONTEXT.getFontMetrics();
 }
  /** @return the bitmapFont */
  public Font getBitmapFont() {
    Font bitmapFont = Font.getBitmapFont(lookupFont);
    if (bitmapFont != null) {
      return bitmapFont;
    }

    BufferedImage image = new BufferedImage(5000, 50, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = (Graphics2D) image.getGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHint(
        RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, bitmapAntialiasing);
    g2d.setColor(Color.BLACK);
    g2d.fillRect(0, 0, image.getWidth(), image.getHeight());
    g2d.setColor(new Color(0xff0000));
    g2d.setFont(java.awt.Font.decode(lookupFont.split(";")[0]));
    FontMetrics metrics = g2d.getFontMetrics();
    FontRenderContext context = g2d.getFontRenderContext();
    int height = (int) Math.ceil(metrics.getMaxDescent() + metrics.getMaxAscent());
    int baseline = (int) Math.ceil(metrics.getMaxAscent());
    String charsetStr = bitmapCharset;
    int[] offsets = new int[charsetStr.length()];
    int[] widths = new int[offsets.length];
    int currentOffset = 0;
    for (int iter = 0; iter < charsetStr.length(); iter++) {
      offsets[iter] = currentOffset;
      String currentChar = charsetStr.substring(iter, iter + 1);
      g2d.drawString(currentChar, currentOffset, baseline);
      Rectangle2D rect = g2d.getFont().getStringBounds(currentChar, context);
      widths[iter] = (int) Math.ceil(rect.getWidth());

      // max advance works but it makes a HUGE image in terms of width which
      // occupies more ram
      if (g2d.getFont().isItalic()) {
        currentOffset += metrics.getMaxAdvance();
      } else {
        currentOffset += widths[iter] + 1;
      }
    }

    g2d.dispose();
    BufferedImage shrunk = new BufferedImage(currentOffset, height, BufferedImage.TYPE_INT_RGB);
    g2d = (Graphics2D) shrunk.getGraphics();
    g2d.drawImage(image, 0, 0, null);
    g2d.dispose();

    int[] rgb = new int[shrunk.getWidth() * shrunk.getHeight()];
    shrunk.getRGB(0, 0, shrunk.getWidth(), shrunk.getHeight(), rgb, 0, shrunk.getWidth());
    com.sun.lwuit.Image bitmap =
        com.sun.lwuit.Image.createImage(rgb, shrunk.getWidth(), shrunk.getHeight());

    return com.sun.lwuit.Font.createBitmapFont(lookupFont, bitmap, offsets, widths, charsetStr);
  }
 @SuppressWarnings("UndesirableClassUsage")
 private static void assertImagesSimilar(
     String name, BufferedImage expected, BufferedImage actual, float allowedDifference)
     throws Exception {
   BufferedImage convertedExpected =
       new BufferedImage(expected.getWidth(), expected.getHeight(), BufferedImage.TYPE_INT_ARGB);
   convertedExpected.getGraphics().drawImage(expected, 0, 0, null);
   BufferedImage convertedActual =
       new BufferedImage(actual.getWidth(), actual.getHeight(), BufferedImage.TYPE_INT_ARGB);
   convertedActual.getGraphics().drawImage(actual, 0, 0, null);
   assertImageSimilar(name, convertedExpected, convertedActual, allowedDifference);
 }
Example #10
0
 public void createBuffer() {
   buffer =
       new BufferedImage(
           Orig.getWidth(null), Orig.getHeight(null), BufferedImage.TYPE_4BYTE_ABGR_PRE);
   Graphics temp = buffer.getGraphics();
   temp.drawImage(Orig, 0, 0, null);
   contBuffer =
       new BufferedImage(
           Cont.getWidth(null), Cont.getHeight(null), BufferedImage.TYPE_4BYTE_ABGR_PRE);
   temp = contBuffer.getGraphics();
   temp.drawImage(Cont, 0, 0, null);
 }
Example #11
0
  public static void main(String[] args) throws IOException {
    List<Color> colorlist = new ArrayList<Color>();
    for (int i = 0; i < 9000; i++) {
      if (new Random().nextBoolean()) colorlist.add(Color.red);
      else if (i > 600) colorlist.add(Color.green);
      else colorlist.add(Color.yellow);
    }
    int width = 600;
    int height = 30;
    BufferedImage image = null;
    Graphics2D g2 = null;
    int step = width / colorlist.size();
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    ImageOutputStream imOut = ImageIO.createImageOutputStream(bs);

    if (step >= 1) {
      image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
      g2 = (Graphics2D) image.getGraphics();
      g2.setBackground(Color.WHITE);
      for (int i = 0; i < colorlist.size(); i++) {
        g2.setColor(colorlist.get(i));
        g2.fillRect(i * step, 0, i * step + step, height);
      }
    } else {
      image = new BufferedImage(colorlist.size(), height, BufferedImage.TYPE_INT_RGB);
      g2 = (Graphics2D) image.getGraphics();
      g2.setBackground(Color.WHITE);
      for (int i = 0; i < colorlist.size(); i++) {
        g2.setColor(colorlist.get(i));
        g2.drawLine(i, 0, i, height);
      }
    }
    g2.dispose();

    Image scaleImage = image.getScaledInstance(width, height, Image.SCALE_SMOOTH);

    image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    g2 = (Graphics2D) image.getGraphics();
    g2.drawImage(scaleImage, 0, 0, null);
    g2.dispose();

    ImageIO.write(image, "GIF", imOut);
    byte[] contentByte = bs.toByteArray();
    FileOutputStream f = new FileOutputStream("d:\\test.gif");
    f.write(contentByte);
    f.flush();
    f.close();
    bs.close();
    imOut.close();
  }
  public static ScalingReport scale(byte[] fileData, int width, int height)
      throws ApplicationException {
    ByteArrayInputStream in = new ByteArrayInputStream(fileData);
    ScalingReport imagedata = new ScalingReport();
    try {

      BufferedImage img = ImageIO.read(in);

      if (img.getHeight() > img.getWidth()) {
        if (img.getHeight() > height) {
          width = (height * img.getWidth()) / img.getHeight();
          Image scaledImage = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
          BufferedImage imageBuff = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
          imageBuff.getGraphics().drawImage(scaledImage, 0, 0, new Color(0, 0, 0), null);

          ByteArrayOutputStream buffer = new ByteArrayOutputStream();
          ImageIO.write(imageBuff, "jpg", buffer);
          imagedata.scaledByte = buffer.toByteArray();
          imagedata.width = width;
          imagedata.height = height;
        } else {
          imagedata.scaledByte = fileData;
          imagedata.width = img.getWidth();
          imagedata.height = img.getHeight();
        }
      } else {
        if (img.getWidth() > width) {
          height = (width * img.getHeight()) / img.getWidth();

          Image scaledImage = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
          BufferedImage imageBuff = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
          imageBuff.getGraphics().drawImage(scaledImage, 0, 0, new Color(0, 0, 0), null);

          ByteArrayOutputStream buffer = new ByteArrayOutputStream();

          ImageIO.write(imageBuff, "jpg", buffer);
          imagedata.scaledByte = buffer.toByteArray();
          imagedata.width = width;
          imagedata.height = height;
        } else {
          imagedata.scaledByte = fileData;
          imagedata.width = img.getWidth();
          imagedata.height = img.getHeight();
        }
      }
      return imagedata;
    } catch (IOException e) {
      throw new ApplicationException("IOException in scale", null);
    }
  }
Example #13
0
  /*
   * create QR code with overlay
   */
  public static void createQRCode(
      String qrCodeData,
      String outputFilePath,
      String overlayFilePath,
      String charset,
      Map<EncodeHintType, ErrorCorrectionLevel> hintMap,
      int qrCodeheight,
      int qrCodewidth)
      throws WriterException, IOException {

    // create QR code <BufferedImage>
    QRCodeWriter qrWriter = new QRCodeWriter();
    BitMatrix matrix =
        qrWriter.encode(qrCodeData, BarcodeFormat.QR_CODE, qrCodewidth, qrCodeheight, hintMap);
    BufferedImage image = MatrixToImageWriter.toBufferedImage(matrix);

    // read overlay image
    BufferedImage overlay = ImageIO.read(new File(overlayFilePath));

    // Draw the new image
    int deltaHeight = image.getHeight() - overlay.getHeight();
    int deltaWidth = image.getWidth() - overlay.getWidth();

    BufferedImage combined =
        new BufferedImage(qrCodeheight, qrCodewidth, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = (Graphics2D) combined.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f));
    g.drawImage(overlay, (int) Math.round(deltaWidth / 2), (int) Math.round(deltaHeight / 2), null);

    ImageIO.write(combined, "PNG", new File(outputFilePath));
  }
  public static ImageIcon getBigSystemIcon(Image image) throws Exception {
    if ((image.getWidth(null) < 20) || (image.getHeight(null) < 20)) {
      if (image.getWidth(null) > image.getHeight(null)) {
        width = 24;
        height = (image.getHeight(null) * 24) / image.getWidth(null);
      } else {
        height = 24;
        width = (image.getWidth(null) * 24) / image.getHeight(null);
      }
    } else {
      return new ImageIcon(image);
    }

    dest = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
    dest2 = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);

    g = dest.getGraphics();
    g.setColor(Color.white);
    g.fillRect(0, 0, 22, 22);
    g.drawImage(image, 0, 0, width, height, null);

    g.dispose();

    sharpenOperator.filter(dest, dest2);

    return new ImageIcon(dest);
  }
 public Image getScreenshot() {
   BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
   Graphics g = image.getGraphics();
   paint(g);
   g.dispose();
   return image;
 }
Example #16
0
 /**
  * 插入LOGO
  *
  * @param source 二维码图片
  * @param imgPath LOGO图片地址
  * @param needCompress 是否压缩
  * @throws Exception
  */
 private static void insertImage(BufferedImage source, String imgPath, boolean needCompress)
     throws Exception {
   File file = new File(imgPath);
   if (!file.exists()) {
     System.err.println("" + imgPath + " 该文件不存在!");
     return;
   }
   Image src = ImageIO.read(new File(imgPath));
   int width = src.getWidth(null);
   int height = src.getHeight(null);
   if (needCompress) { // 压缩LOGO
     if (width > WIDTH) {
       width = WIDTH;
     }
     if (height > HEIGHT) {
       height = HEIGHT;
     }
     Image image = src.getScaledInstance(width, height, Image.SCALE_SMOOTH);
     BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     Graphics g = tag.getGraphics();
     g.drawImage(image, 0, 0, null); // 绘制缩小后的图
     g.dispose();
     src = image;
   }
   // 插入LOGO
   Graphics2D graph = source.createGraphics();
   int x = (QRCODE_WIDTH - width) / 2;
   int y = (QRCODE_HEIGHT - height) / 2;
   graph.drawImage(src, x, y, width, height, null);
   Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6);
   graph.setStroke(new BasicStroke(3f));
   graph.draw(shape);
   graph.dispose();
 }
  public static Image getScaledInstance(File file) throws Exception {
    srcBImage = javax.imageio.ImageIO.read(file);

    if (srcBImage.getWidth() > srcBImage.getHeight()) {
      width = 100;
      height = (srcBImage.getHeight() * 100) / srcBImage.getWidth();
    } else {
      height = 100;
      width = (srcBImage.getWidth() * 100) / srcBImage.getHeight();
    }

    dest = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
    dest2 = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);

    g = dest.getGraphics();
    g.setColor(Color.white);
    g.fillRect(0, 0, 100, 100);
    g.drawImage(srcBImage, 0, 0, width, height, null);

    g.dispose();
    srcBImage = null;
    blurOperator.filter(dest, dest2);

    return dest2;
  }
  // TODO currently allows for collisions if same name & different filetype
  public void loadImage(String path) {
    BufferedImage readImage = null;
    try {
      readImage = ImageIO.read(new File("images/" + path));
    } catch (IOException e) {
      e.printStackTrace();
    }
    if (readImage != null) {
      BufferedImage aImages[] = new BufferedImage[8];
      BufferedImage image =
          new BufferedImage(
              readImage.getWidth(), readImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
      Graphics g = image.getGraphics();
      g.drawImage(readImage, 0, 0, null);
      for (int i = 0; i < 8; i++) {
        AffineTransform trans = new AffineTransform();
        trans.translate(image.getWidth() / 2, image.getHeight() / 2);
        trans.rotate(Math.PI * i / 4.0);
        trans.translate(-image.getWidth() / 2, -image.getHeight() / 2);
        AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_BILINEAR);
        aImages[i] =
            new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
        op.filter(image, aImages[i]);
      }

      images.add(
          new Asset(
              path.substring(0, path.length() - 4), aImages)); // assumes standard 3 letter postfix
    }
  }
Example #19
0
 /** Return an RGB image that is the expansion of the given grayscale image. */
 private static BufferedImage expandGrayThumb(BufferedImage thumb) {
   BufferedImage ret =
       new BufferedImage(thumb.getWidth(), thumb.getHeight(), BufferedImage.TYPE_INT_RGB);
   Graphics g = ret.getGraphics();
   g.drawImage(thumb, 0, 0, null);
   return ret;
 }
Example #20
0
  public void drawPixelatedImage(BufferedImage img, int locationX, int locationY) {

    if (isDrawingPixelatedImages()) {
      BufferedImage bi =
          new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
      Graphics2D g2 = (Graphics2D) bi.getGraphics();
      g2.setColor(Color.WHITE);
      g2.fillRect(0, 0, img.getWidth(), img.getHeight());
      g2.drawImage(img, 0, 0, observer);
      g2.dispose();

      for (int x = 0; x < bi.getWidth(observer); x++) {
        for (int y = 0; y < bi.getHeight(observer); y++) {
          int rgb = bi.getRGB(x, y);
          gc.setColor(new Color(rgb));
          gc.setStroke(new BasicStroke(1.0f));
          gc.drawLine(
              locationX + xOffset + x,
              locationY + yOffset + y,
              locationX + xOffset + x,
              locationY + yOffset + y);
          // gc.drawLine(locationX+xOffset+x, locationY+yOffset+y,
          // locationX+xOffset+x+1, locationY+yOffset+y);
          // gc.drawLine(locationX+xOffset+x, locationY+yOffset+y+1,
          // locationX+xOffset+x+1, locationY+yOffset+y+1);
          // gc.fillRect(locationX+xOffset+x, locationY+yOffset+y, 1, 1);
        }
      }
    } else {
      while (!gc.drawImage(img, locationX, locationY, observer)) ;
    }
  }
  private void btImprimirMouseClicked(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_btImprimirMouseClicked
    Dimension size = this.getSize();
    BufferedImage img = new BufferedImage(size.width, size.height, BufferedImage.TYPE_3BYTE_BGR);
    Graphics g = img.getGraphics();
    this.paint(g);
    g.dispose();

    try {
      ImageIO.write(
          img,
          "png",
          new File(
              new JFileChooser().getFileSystemView().getDefaultDirectory().toString()
                  + "/factura"
                  + lbNumeroVenta.getText()
                  + ".png"));

      JOptionPane.showMessageDialog(
          rootPane,
          "La factura ha sido guardada con nombre /factura"
              + lbNumeroVenta.getText()
              + ".png en sus documentos");
    } catch (IOException ex) {
      ex.printStackTrace();
    }
  } // GEN-LAST:event_btImprimirMouseClicked
 private float getComplexity(BufferedImage img) {
   // Uses its own resizing method to remove color in the same step
   BufferedImage sml = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_BYTE_GRAY);
   sml.getGraphics().drawImage(img, 0, 0, SIZE, SIZE, null);
   float ret = 0;
   int w = sml.getWidth();
   int h = sml.getHeight();
   Kernel laplace = new Kernel(3, 3, new float[] {1, 1, 1, 1, -8, 1, 1, 1, 1});
   ConvolveOp filter = new ConvolveOp(laplace);
   BufferedImage dest = filter.createCompatibleDestImage(sml, null);
   filter.filter(sml, dest);
   WritableRaster data = dest.getRaster();
   int[] pixels = data.getPixels(0, 0, w, h, new int[w * h]);
   int sum = 0;
   for (int i = 0; i < w; i++) {
     for (int j = 0; j < h; j++) {
       int temp = pixels[i + j * w];
       sum += temp;
     }
   }
   ret = (float) sum / (w * h * 256);
   if (ret < 0.01) {
     ret = 1;
   }
   return ret;
 }
Example #23
0
  public void loadTexture(IResourceManager resourceManager) throws IOException {
    this.deleteGlTexture();
    BufferedImage bufferedimage = null;

    for (String s : this.layeredTextureNames) {
      IResource iresource = null;

      try {
        if (s != null) {
          iresource = resourceManager.getResource(new ResourceLocation(s));
          BufferedImage bufferedimage1 = TextureUtil.readBufferedImage(iresource.getInputStream());

          if (bufferedimage == null) {
            bufferedimage =
                new BufferedImage(bufferedimage1.getWidth(), bufferedimage1.getHeight(), 2);
          }

          bufferedimage.getGraphics().drawImage(bufferedimage1, 0, 0, (ImageObserver) null);
        }

        continue;
      } catch (IOException ioexception) {
        LOGGER.error((String) "Couldn\'t load layered image", (Throwable) ioexception);
      } finally {
        IOUtils.closeQuietly((Closeable) iresource);
      }

      return;
    }

    TextureUtil.uploadTextureImage(this.getGlTextureId(), bufferedimage);
  }
  /** paints the DrawComponent into the Graphics of the BufferedImage */
  protected void paintDrawComponent() {
    long startTime = 0;
    if (debugPaint) startTime = System.currentTimeMillis();

    if (bufferedImage != null) {
      Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics();
      g2d.setRenderingHints(renderingHintsManager.getRenderingHints());
      g2d.setBackground(bgColor);
      g2d.setPaint(bgColor);
      g2d.translate(-bufferBounds.x, -bufferBounds.y);
      g2d.setClip(bufferBounds);
      g2d.fillRect(bufferBounds.x, bufferBounds.y, bufferBounds.width, bufferBounds.height);

      if (debugPaint) {
        drawRealRectangle(g2d);
        drawBufferRectangle(g2d);
        drawViewRectangle(g2d);
      }

      g2d.scale(scale, scale);
      DrawComponentPaintable.paintDrawComponent(dc, g2d);
    }

    if (debugPaint) {
      long endTime = System.currentTimeMillis() - startTime;
      logger.debug("paintDrawComponent took " + endTime + " ms!"); // $NON-NLS-1$ //$NON-NLS-2$
    }
  }
Example #25
0
 public BufferedImage getBufferedImage() {
   BufferedImage image =
       new BufferedImage(
           Math.max(100, getWidth()), Math.max(100, getHeight()), BufferedImage.TYPE_INT_RGB);
   paint(image.getGraphics());
   return image;
 }
Example #26
0
  public void paintComponent(Graphics comp) {
    if (m_Image == null) {
      Cursor currentCursor = getCursor();
      try {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        Dimension size = m_WorldMap.getMapSize();
        m_Image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = (Graphics2D) m_Image.getGraphics();
        g.setClip(0, 0, size.width, size.height);
        m_WorldMap.draw(g, 0, 0, getDrawMode());
      } finally {
        setCursor(currentCursor);
      }
    }

    Graphics2D g2D = (Graphics2D) comp;
    g2D.drawImage(m_Image, null, 0, 0);

    boolean ShowHexNeighbours = true;
    if (m_CurrentSegment != -1) m_WorldMap.HighlightSegment(comp, m_CurrentSegment, true);
    if (m_CurrentSector != -1)
      m_WorldMap.HighlightSector(g2D, m_CurrentSector, true, ShowHexNeighbours);
    if (m_CurrentPath != null)
      m_WorldMap.HighlightPath(g2D, m_CurrentPath, true, ShowHexNeighbours);
  }
Example #27
0
  @Override
  public void paintComponent(Graphics g) {
    g.setColor(Color.white);
    g.fillRect(0, 0, getWidth(), getHeight());
    int oldHeight = imgHeight;

    imgHeight = getHeight();
    imgHeight -= (imgHeight % av.charHeight);

    if (imgHeight < 1) {
      return;
    }

    if (oldHeight != imgHeight || image.getWidth(this) != getWidth()) {
      image = new BufferedImage(getWidth(), imgHeight, BufferedImage.TYPE_INT_RGB);
    }

    gg = (Graphics2D) image.getGraphics();

    // Fill in the background
    gg.setColor(Color.white);
    gg.fillRect(0, 0, getWidth(), imgHeight);

    drawIds(av.startSeq, av.endSeq);

    g.drawImage(image, 5, 1, this);
  }
Example #28
0
    private BufferedImage toThumbnailImage(BufferedImage contentImage) {
      if (contentImage != null) {
        final int thumbnailSize = 64;
        int width = contentImage.getWidth();
        int height = contentImage.getHeight();
        int maxSize = Math.max(width, height);
        if (maxSize <= thumbnailSize) {
          return contentImage;
        } else {
          double scale = (double) thumbnailSize / (double) maxSize;
          int scaledWidth = (int) (width * scale);
          int scaledHeight = (int) (height * scale);

          Image thumbnailImage =
              contentImage.getScaledInstance(scaledWidth, scaledHeight, Image.SCALE_DEFAULT);

          if (thumbnailImage instanceof BufferedImage) {
            return (BufferedImage) thumbnailImage;
          } else {
            BufferedImage image =
                new BufferedImage(scaledWidth, scaledHeight, BufferedImage.TYPE_INT_RGB);
            image.getGraphics().drawImage(thumbnailImage, 0, 0, null);
            return image;
          }
        }
      }
      return null;
    }
Example #29
0
 /** Clear the framebuffer here. */
 private void beginFrame() {
   zBuffer = new float[width][height];
   mergedDisplayMatrix = new Matrix4f(viewPortMatrix);
   mergedDisplayMatrix.mul(sceneManager.getFrustum().getProjectionMatrix());
   mergedDisplayMatrix.mul(sceneManager.getCamera().getCameraMatrix());
   colorBuffer.getGraphics().clearRect(0, 0, width, height);
 }
Example #30
0
  private PageImage scale(double scaleFactor, int scaledDpi) {

    //	check size
    if (scaleFactor >= 1.0) return this;

    //	scale image
    BufferedImage scaled =
        new BufferedImage(
            ((int) (this.image.getWidth() * scaleFactor)),
            ((int) (this.image.getHeight() * scaleFactor)),
            BufferedImage.TYPE_INT_ARGB);
    Graphics g = scaled.getGraphics();
    g.drawImage(this.image, 0, 0, scaled.getWidth(), scaled.getHeight(), null);
    g.dispose();

    //	wrap and return scaled image
    return new PageImage(
        scaled,
        this.originalWidth,
        this.originalHeight,
        this.originalDpi,
        scaledDpi,
        ((int) Math.round(this.leftEdge * scaleFactor)),
        ((int) Math.round(this.rightEdge * scaleFactor)),
        ((int) Math.round(this.topEdge * scaleFactor)),
        ((int) Math.round(this.bottomEdge * scaleFactor)),
        this.source);
  }