public BufferedImage createGraphImage(
     long nowInSeconds, SourceIdentifier sourceIdentifier, BufferedImage result, boolean showMax) {
   RrdGraphDef graphDef = getGraphDef(nowInSeconds, sourceIdentifier, showMax);
   //noinspection SynchronizationOnLocalVariableOrMethodParameter
   synchronized (graphDef) {
     RrdGraph graph;
     try {
       graph = new RrdGraph(graphDef);
       RrdGraphInfo graphInfo = graph.getRrdGraphInfo();
       int width = graphInfo.getWidth();
       int height = graphInfo.getHeight();
       if (result != null && (result.getWidth() != width || result.getHeight() != height)) {
         if (logger.isInfoEnabled()) logger.info("Flushing previous image because of wrong size.");
         result.flush();
         result = null;
       }
       if (result == null) {
         result = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
         if (logger.isInfoEnabled()) logger.info("Created new image.");
       }
       graph.render(result.getGraphics());
     } catch (IOException ex) {
       if (logger.isWarnEnabled()) logger.warn("Exception while creating graph!", ex);
       if (result != null) {
         result.flush();
         result = null;
       }
     }
   }
   return result;
 }
Example #2
0
  /**
   * Generates a PDF file with the text 'Hello World'
   *
   * @param args no arguments needed here
   */
  public static byte[] getDashboardPDFAsByteArray() {

    String localProviderURL = "t3://localhost:7001";
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    System.setProperty(Context.PROVIDER_URL, localProviderURL);

    System.out.println("Generating VINSight DashBoard Reports");

    // step 1: creation of a document-object
    Document document = new Document();

    ByteArrayOutputStream baos = new ByteArrayOutputStream(100000);

    try {
      // step 2
      PdfWriter writer;
      writer = PdfWriter.getInstance(document, baos);
      // step 3
      document.open();
      // step 4: we add a paragraph to the document
      document.add(new Paragraph("VINSight Health Check"));
      document.add(new Paragraph("Report 1"));

      // create the chart1 image
      JFreeChart chart1 = VINSightDashboardReport.createVINSightDashBoardChart1();
      BufferedImage image1 = chart1.createBufferedImage(350, 350);
      image1.flush();

      document.add(com.lowagie.text.Image.getInstance(image1, null));
      document.add(new Paragraph("Report 2"));
      JFreeChart chart2 = VINSightDashboardReport.createVINSightDashBoardChart2();
      BufferedImage image2 = chart2.createBufferedImage(350, 350);
      image2.flush();

      document.add(com.lowagie.text.Image.getInstance(image2, null));

    } catch (DocumentException de) {
      de.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      // step 5
      document.close();
      try {
        baos.close();
      } catch (IOException ioe) {
        /*ignore*/
      }
    }

    return baos.toByteArray();
  }
Example #3
0
    @Override
    public void actionPerformed(ActionEvent e) {
      Preferences pref = Preferences.userNodeForPackage(FSFrame.class);
      String saveDirName = pref.get(SAVE_IMAGE_DIR, System.getProperty("user.dir"));

      JFileChooser fileChooser = new JFileChooser(saveDirName);
      int result = fileChooser.showSaveDialog(FSFrame.this);
      if (result != JFileChooser.APPROVE_OPTION) {
        return;
      }
      File file = fileChooser.getSelectedFile();
      if (!file.getName().toLowerCase().endsWith(".png")) {
        file = new File(file.getAbsolutePath() + ".png");
      }
      if (file.exists()) {
        result =
            JOptionPane.showConfirmDialog(
                FSFrame.this, FSResource.getString("file_exists"), "", JOptionPane.YES_NO_OPTION);
        if (result != JOptionPane.YES_OPTION) {
          return;
        }
      }
      pref.put(SAVE_IMAGE_DIR, file.getAbsolutePath());

      BufferedImage image = panel.toImage(drawPmCode);

      try {
        if (drawPmCode) {
          BufferedImage pmCode = createPMCode();
          Graphics g = image.getGraphics();
          Point p =
              panel
                  .getModel()
                  .getPmCodePosition()
                  .getPoint(panel.getSize(), new Dimension(pmCode.getWidth(), pmCode.getHeight()));
          g.drawImage(pmCode, p.x, p.y, image.getHeight() / 2, image.getHeight() / 2, FSFrame.this);
          pmCode.flush();
        }

        ImageIO.write(image, "png", file);
      } catch (IOException ex) {
        JOptionPane.showConfirmDialog(
            FSFrame.this, FSResource.resourceBundle.getString("failed_to_output_file"));
        ex.printStackTrace();
      } finally {
        image.flush();
      }
    }
  @Override
  public void update() {
    // Draw the component
    graphics.drawImage(componentImage, 0, 0, null);

    // Draw the reflection
    int width = componentImage.getWidth();
    int height = componentImage.getHeight();

    GradientPaint mask =
        new GradientPaint(
            0,
            height / 4f,
            new Color(1.0f, 1.0f, 1.0f, 0.0f),
            0,
            height,
            new Color(1.0f, 1.0f, 1.0f, 0.5f));
    componentImageGraphics.setPaint(mask);

    componentImageGraphics.setComposite(AlphaComposite.DstIn);
    componentImageGraphics.fillRect(0, 0, width, height);

    componentImageGraphics.dispose();
    componentImageGraphics = null;

    componentImage.flush();

    graphics.transform(getTransform(component));

    graphics.drawImage(componentImage, 0, 0, null);

    componentImage = null;
    component = null;
    graphics = null;
  }
Example #5
0
 private static void saveToJPG(BufferedImage image, File file) throws IOException {
   BufferedImage newImage =
       new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
   newImage.createGraphics().drawImage(image, 0, 0, Color.WHITE, null);
   ImageIO.write(newImage, "jpg", file);
   newImage.flush();
 }
Example #6
0
 /**
  * 复制指定的BufferedImage图像区域
  *
  * @param image
  * @param g
  * @param x
  * @param y
  * @param width
  * @param height
  * @param dx
  * @param dy
  */
 public static void copyArea(
     BufferedImage image, Graphics2D g, int x, int y, int width, int height, int dx, int dy) {
   BufferedImage tmp = image.getSubimage(x, y, width, height);
   g.drawImage(tmp, x + dx, y + dy, null);
   tmp.flush();
   tmp = null;
 }
 // Renders image from canon DSLR
 private static void canonSLR(final CanonCamera camera) {
   renderCanon = new JLabel();
   if (canon = true) {
     while (canon = true) {
       try {
         Thread.sleep(50);
         BufferedImage canonimage = camera.downloadLiveView();
         if (canonimage != null) {
           renderCanon.setIcon(new ImageIcon(canonimage));
           renderCanon.setBounds((width / 2) - 528, 10, 1056, 704);
           renderCanon.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 3));
           renderCanon.setToolTipText("Live Canon DSLR feed");
           renderCanon.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
           window.add(renderCanon);
           webcam = false;
           nikon = false;
           System.out.println("Battery: " + camera.getProperty(kEdsPropID_BatteryLevel));
           canonimage.flush();
         }
       } catch (InterruptedException ex) {
         Logger.getLogger(Controls.class.getName()).log(Level.SEVERE, null, ex);
       }
     }
   }
 }
Example #8
0
  private void createImage(OutputStream out) {
    int width = 100;
    int height = 100;

    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g = bi.createGraphics();

    // set background color
    g.setBackground(Color.BLUE);
    g.clearRect(0, 0, width, height);

    // set  color
    g.setColor(Color.RED);

    g.drawLine(0, 0, 99, 99);
    g.dispose();
    bi.flush();

    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
    param.setQuality(1.0f, false);
    encoder.setJPEGEncodeParam(param);

    try {
      encoder.encode(bi);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Example #9
0
  public QRCodeEncoderTest() throws Exception {
    Qrcode qrcode = new Qrcode();
    qrcode.setQrcodeErrorCorrect('M');
    qrcode.setQrcodeEncodeMode('B');
    qrcode.setQrcodeVersion(7);
    String encodeddata = "{id:10022,name:wandern}";
    byte[] d = encodeddata.getBytes("GBK");
    BufferedImage bi = new BufferedImage(139, 139, BufferedImage.TYPE_INT_RGB);
    // createGraphics
    Graphics2D g = bi.createGraphics();
    // set background
    g.setBackground(Color.WHITE);
    g.clearRect(0, 0, 139, 139);
    g.setColor(Color.BLACK);

    if (d.length > 0 && d.length < 123) {
      boolean[][] b = qrcode.calQrcode(d);
      for (int i = 0; i < b.length; i++) {
        for (int j = 0; j < b.length; j++) {
          if (b[j][i]) {
            g.fillRect(j * 3 + 2, i * 3 + 2, 3, 3);
          }
        }
      }
    }

    g.dispose();
    bi.flush();
    String FilePath = "C:\\QRCode.png";
    File f = new File(FilePath);

    ImageIO.write(bi, "png", f);
    System.out.println("Input Encoded data is" + encodeddata);
  }
Example #10
0
 private void writeImage(File imageFile) throws IOException {
   BufferedImage resultImage = null;
   if (selectedGraph >= 0 && selectedGraph < graphImageFactories.length) {
     resultImage =
         graphImageFactories[selectedGraph].createGraphImage(
             Util.getTime(), sourceIdentifier, null, showMaxCheckBox.isSelected());
   }
   if (resultImage != null) {
     final String format = "png";
     BufferedOutputStream imageOutput = null;
     try {
       imageOutput = new BufferedOutputStream(new FileOutputStream(imageFile));
       boolean writerFound = ImageIO.write(resultImage, format, imageOutput);
       if (!writerFound) {
         String msg = "Couldn't write image! No writer found for format '" + format + "'!";
         if (logger.isErrorEnabled()) logger.error(msg);
         throw new IOException(msg);
       }
     } finally {
       // close output stream no matter what. shouldn't be necessary...
       IOUtilities.closeQuietly(imageOutput);
       resultImage.flush();
     }
   }
 }
Example #11
0
 public static void EncoderQrCode(String content) throws IOException {
   Qrcode qrcode = new Qrcode();
   qrcode.setQrcodeErrorCorrect('M');
   qrcode.setQrcodeEncodeMode('B');
   qrcode.setQrcodeVersion(7);
   //        if(content == null || !content.equals("")){
   //        	content = "DHCC";
   //        }
   String servicePassword = PropertiesBean.getInstance().getProperty("confg.serviceKey");
   content = AESCoder.aesCbcEncrypt(content, servicePassword);
   byte[] bstr = content.getBytes("UTF-8");
   BufferedImage bi = new BufferedImage(139, 139, BufferedImage.TYPE_INT_RGB);
   Graphics2D g = bi.createGraphics();
   g.setBackground(Color.WHITE); //
   g.clearRect(0, 0, 139, 139);
   g.setColor(Color.BLACK); //
   if (bstr.length > 0 && bstr.length < 123) {
     boolean[][] b = qrcode.calQrcode(bstr);
     for (int i = 0; i < b.length; i++) {
       for (int j = 0; j < b.length; j++) {
         if (b[j][i]) {
           g.fillRect(j * 3 + 2, i * 3 + 2, 3, 3);
         }
       }
     }
   }
   g.dispose();
   bi.flush();
   WebContextHolder.getContext().getResponse().setContentType("image/png");
   ImageIO.write(bi, "png", WebContextHolder.getContext().getResponse().getOutputStream());
 }
Example #12
0
 public static boolean gifCaptcha(String randomStr, int width, int height, String file) {
   char[] rands = randomStr.toCharArray();
   int len = rands.length;
   try (OutputStream out = new FileOutputStream(file)) {
     // gif编码类,这个利用了洋人写的编码类,所有类都在附件中
     GifEncoder gifEncoder = new GifEncoder();
     // 生成字符
     gifEncoder.start(out);
     gifEncoder.setQuality(180);
     gifEncoder.setDelay(100);
     gifEncoder.setRepeat(0);
     BufferedImage frame;
     Color fontcolor[] = new Color[len];
     for (int i = 0; i < len; i++) {
       fontcolor[i] = new Color(20 + num(110), 20 + num(110), 20 + num(110));
     }
     for (int i = 0; i < len; i++) {
       frame = graphicsImage(fontcolor, rands, i, width, height, len);
       gifEncoder.addFrame(frame);
       frame.flush();
     }
     gifEncoder.finish();
     return true;
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   return false;
 }
Example #13
0
  private void drawBubbles(final java.awt.Graphics2D G2) {
    counter = 0;
    for (java.awt.image.BufferedImage bubbleImage : bubbleList) {
      // Set the alpha value for the current BUBBLE image
      G2.setComposite(
          java.awt.AlphaComposite.getInstance(
              java.awt.AlphaComposite.SRC_OVER, alphaList.get(counter)));

      // Recalculate the new position of the BUBBLE with their specific speed
      x = positionList.get(counter).x;
      y = positionList.get(counter).y;
      x -= xSpeedList.get(counter);
      y -= ySpeedList.get(counter);

      // Draw the BUBBLE without a blur effect
      G2.drawImage(bubbleImage, x, y, null);

      bubbleImage.flush();

      // Check if BUBBLE is outside the panel and create a new BUBBLE if needed
      if (x < -MAX_BUBBLE_RADIUS
          || x > (getWidth() + MAX_BUBBLE_RADIUS)
          || y < -MAX_BUBBLE_RADIUS
          || y > (getHeight() + MAX_BUBBLE_RADIUS)) {
        positionList.set(counter, new java.awt.Point(RANDOM.nextInt(getWidth()), getHeight()));
        final java.awt.image.BufferedImage IMAGE;
        // Draw smileys if the form was completed, else draw bubbles
        if (validated) {
          IMAGE = createSmileyImage(5 + RANDOM.nextInt(MAX_BUBBLE_RADIUS));
          bubbleList.set(counter, IMAGE);
          IMAGE.flush();
        } else {
          IMAGE = createBubbleImage(5 + RANDOM.nextInt(MAX_BUBBLE_RADIUS));
          bubbleList.set(counter, IMAGE);
          IMAGE.flush();
        }
      } else {
        positionList.set(counter, new java.awt.Point(x, y));
      }
      counter++;
    }

    // Reset the alpha value for additional drawings to 1.0f
    G2.setComposite(java.awt.AlphaComposite.getInstance(java.awt.AlphaComposite.SRC_OVER, 1.0f));

    G2.dispose();
  }
Example #14
0
 public void formatAsset(Resource asset, ImageType type, OutputStream output) throws IOException {
   BufferedImage image = extractImage(asset);
   if (image == null) {
     throw new IOException("Could not extract image from asset: " + asset);
   }
   writeImage(image, type, output);
   image.flush();
 }
Example #15
0
  /** Creates the images composing the grid when the color model is <code>GreyScale</code>. */
  private void createGridImagesForGreyScale() {
    int maxC = parent.getMaxC();
    List l = parent.getActiveChannelsInGrid();
    int n = l.size();
    clearList(gridImages);
    if (combinedImage != null) combinedImage.flush();
    switch (n) {
      case 0:
        for (int i = 0; i < maxC; i++) gridImages.add(null);
        combinedImage = null;
        break;
      case 1:
      case 2:
      case 3:
        if (isImageMappedRGB(l)) {
          BufferedImage image = parent.getCombinedGridImage();
          if (image == null) {
            for (int i = 0; i < maxC; i++) gridImages.add(null);
            break;
          }
          combinedImage = Factory.magnifyImage(gridRatio, image);

          int w = combinedImage.getWidth();
          int h = combinedImage.getHeight();

          DataBuffer buf = combinedImage.getRaster().getDataBuffer();
          List<ChannelData> list = parent.getSortedChannelData();
          Iterator<ChannelData> i = list.iterator();
          int index;
          while (i.hasNext()) {
            index = i.next().getIndex();
            if (l.contains(index)) {
              if (parent.isChannelRed(index)) {
                gridImages.add(
                    Factory.createBandImage(
                        buf, w, h, Factory.RED_MASK, Factory.RED_MASK, Factory.RED_MASK));
              } else if (parent.isChannelGreen(index)) {
                gridImages.add(
                    Factory.createBandImage(
                        buf, w, h, Factory.GREEN_MASK, Factory.GREEN_MASK, Factory.GREEN_MASK));
              } else if (parent.isChannelBlue(index)) {
                gridImages.add(
                    Factory.createBandImage(
                        buf, w, h, Factory.BLUE_MASK, Factory.BLUE_MASK, Factory.BLUE_MASK));
              }
            } else {
              gridImages.add(null);
            }
          }
        } else {
          retrieveGridImagesForGreyScale(l);
        }
        break;

      default:
        retrieveGridImagesForGreyScale(l);
    }
  }
  public static void imageConverter() {
    System.out.println("…ffene Datei...");
    File file = new File("./PDFFile/01 Access2010 EinfŸhrung.pdf");
    RandomAccessFile raf;

    try {

      raf = new RandomAccessFile(file, "r");

      FileChannel channel = raf.getChannel();
      ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
      PDFFile pdfFile = new PDFFile(buf);

      // konvertiere erste seite in ein bild
      int num = pdfFile.getNumPages();
      for (int i = 0; i < num; i++) {
        PDFPage page = pdfFile.getPage(i);

        // ermittle Hoehe und Breite
        int width = (int) page.getBBox().getWidth();
        int height = (int) page.getBBox().getHeight();

        // AWT
        Rectangle rect = new Rectangle(0, 0, width, height);
        int rotation = page.getRotation();
        Rectangle rectl = rect;

        if (rotation == 90 || rotation == 270) {
          rectl = new Rectangle(0, 0, rect.height, rect.width);
        }

        // generiere Bild
        BufferedImage img =
            (BufferedImage)
                page.getImage(
                    rect.width,
                    rect.height, // Breite Hoehe
                    rectl,
                    null,
                    true, // Fuelle Hintergrund weiss aus
                    true);

        ImageIO.write(img, "png", new File("./PDFImages/" + i + ".png"));
        System.out.println("Bild {" + i + " }erzeugt");
        img.flush();
      }
      System.out.println("Bilder erzeugt!");
    }

    // Catcher
    catch (FileNotFoundException e1) {
      System.err.println(e1.getLocalizedMessage());
    } catch (IOException e2) {
      System.err.println(e2.getLocalizedMessage());
    }
  }
Example #17
0
  private void replaceSurfaceData(
      int newBackBufferCount, BufferCapabilities newBackBufferCaps, boolean blit) {
    synchronized (surfaceDataLock) {
      final SurfaceData oldData = getSurfaceData();
      surfaceData = platformWindow.replaceSurfaceData();
      // TODO: volatile image
      //        VolatileImage oldBB = backBuffer;
      BufferedImage oldBB = backBuffer;
      backBufferCount = newBackBufferCount;
      backBufferCaps = newBackBufferCaps;
      final Rectangle size = getSize();
      if (getSurfaceData() != null && oldData != getSurfaceData()) {
        clearBackground(size.width, size.height);
      }

      if (blit) {
        blitSurfaceData(oldData, getSurfaceData());
      }

      if (oldData != null && oldData != getSurfaceData()) {
        // TODO: drop oldData for D3D/WGL pipelines
        // This can only happen when this peer is being created
        oldData.flush();
      }

      // TODO: volatile image
      //        backBuffer = (VolatileImage)delegate.createBackBuffer();
      backBuffer = (BufferedImage) platformWindow.createBackBuffer();
      if (backBuffer != null) {
        Graphics g = backBuffer.getGraphics();
        try {
          Rectangle r = getBounds();
          if (g instanceof Graphics2D) {
            ((Graphics2D) g).setComposite(AlphaComposite.Src);
          }
          g.setColor(nonOpaqueBackground);
          g.fillRect(0, 0, r.width, r.height);
          if (g instanceof SunGraphics2D) {
            ((SunGraphics2D) g).constrain(0, 0, r.width, r.height, getRegion());
          }
          if (!isTextured()) {
            g.setColor(getBackground());
            g.fillRect(0, 0, r.width, r.height);
          }
          if (oldBB != null) {
            // Draw the old back buffer to the new one
            g.drawImage(oldBB, 0, 0, null);
            oldBB.flush();
          }
        } finally {
          g.dispose();
        }
      }
    }
    flushOnscreenGraphics();
  }
  /**
   * This method creates a new Image, from the current picture. The resulting width and height will
   * be less or equal than the given maximum width and height. The scale is maintained. Thus the
   * width or height may be inferior than the given values.
   *
   * @param canvas The canvas on which the picture will be displayed.
   * @param shadow True if the pictureFileData should store this picture. False if the
   *     pictureFileData instance should not store this picture. Store this picture avoid
   *     calculating the image each time the user selects it in the file panel.
   * @return The rescaled image.
   * @throws JUploadException Encapsulation of the Exception, if any would occurs.
   */
  public Image getImage(Canvas canvas, boolean shadow) throws JUploadException {
    Image localImage = null;

    if (canvas == null) {
      throw new JUploadException("canvas null in PictureFileData.getImage");
    }

    int canvasWidth = canvas.getWidth();
    int canvasHeight = canvas.getHeight();
    if (canvasWidth <= 0 || canvasHeight <= 0) {
      this.uploadPolicy.displayDebug(
          "canvas width and/or height null in PictureFileData.getImage()", 1);
    } else if (shadow && this.offscreenImage != null) {
      // We take and return the previous calculated image for this
      // PictureFileData.
      localImage = this.offscreenImage;
    } else if (this.isPicture) {
      try {
        // First: load the picture.
        ImageReaderWriterHelper irwh =
            new ImageReaderWriterHelper((PictureUploadPolicy) uploadPolicy, this);
        BufferedImage sourceImage = irwh.readImage(0);
        irwh.dispose();
        irwh = null;
        ImageHelper ih =
            new ImageHelper(
                (PictureUploadPolicy) this.uploadPolicy,
                this,
                canvasWidth,
                canvasHeight,
                this.quarterRotation);
        localImage =
            ih.getBufferedImage(
                ((PictureUploadPolicy) this.uploadPolicy).getHighQualityPreview(), sourceImage);
        // We free memory ASAP.
        sourceImage.flush();
        sourceImage = null;
      } catch (OutOfMemoryError e) {
        // Too bad
        localImage = null;
        tooBigPicture();
      }
    } // If isPicture

    // We store it, if asked to.
    if (shadow) {
      this.offscreenImage = localImage;
    }

    freeMemory("end of " + this.getClass().getName() + ".getImage()");

    // The picture is now loaded. We clear the progressBar
    this.uploadPolicy.getApplet().getUploadPanel().getProgressBar().setValue(0);

    return localImage;
  } // getImage
  /**
   * checks if the View is still in the Buffer, if not a new BufferedImage is created and
   * paintDrawComponent is painted into the Graphics of the new BufferedImage.
   */
  protected void checkBuffer() {
    if (!isViewInBuffer()) {
      if (bufferedImage != null) bufferedImage.flush();
      bufferedImage = null;
      createOffScreenImage();
      notifyChange();

      if (debugBounds) logger.debug("Buffer updated!"); // $NON-NLS-1$
    }
  }
  // <editor-fold defaultstate="collapsed" desc="Initialization">
  public final void init(final int WIDTH, final int HEIGHT) {
    if (WIDTH <= 1 || HEIGHT <= 1) {
      return;
    }

    if (lcdImage != null) {
      lcdImage.flush();
    }
    lcdImage = create_LCD_Image(WIDTH, HEIGHT);

    if (glowImageOn != null) {
      glowImageOn.flush();
    }
    glowImageOn = GlowImageFactory.INSTANCE.createLcdGlow(WIDTH, HEIGHT, glowColor, true);

    final double CORNER_RADIUS = WIDTH > HEIGHT ? (HEIGHT * 0.095) : (WIDTH * 0.095);
    disabledShape = new RoundRectangle2D.Double(0, 0, WIDTH, HEIGHT, CORNER_RADIUS, CORNER_RADIUS);
    if (isDigitalFont()) {
      lcdValueFont = LCD_DIGITAL_FONT.deriveFont(0.5f * getInnerBounds().height);
      lcdFormerValueFont = LCD_DIGITAL_FONT.deriveFont(0.2f * getInnerBounds().height);
      if (useCustomLcdUnitFont) {
        lcdUnitFont = customLcdUnitFont.deriveFont(0.1875f * getInnerBounds().height);
      } else {
        lcdUnitFont = LCD_STANDARD_FONT.deriveFont(0.1875f * getInnerBounds().height);
      }
    } else {
      lcdValueFont = LCD_STANDARD_FONT.deriveFont(0.46875f * getInnerBounds().height);
      lcdFormerValueFont = LCD_STANDARD_FONT.deriveFont(0.1875f * getInnerBounds().height);
      if (useCustomLcdUnitFont) {
        lcdUnitFont = customLcdUnitFont.deriveFont(0.1875f * getInnerBounds().height);
      } else {
        lcdUnitFont = LCD_STANDARD_FONT.deriveFont(0.1875f * getInnerBounds().height);
      }
    }
    lcdInfoFont = LCD_STANDARD_FONT.deriveFont(0.15f * getInnerBounds().height);

    if (lcdThresholdImage != null) {
      lcdThresholdImage.flush();
    }
    lcdThresholdImage =
        create_LCD_THRESHOLD_Image(
            (int) (HEIGHT * 0.2045454545), (int) (HEIGHT * 0.2045454545), lcdColor.TEXT_COLOR);
  }
Example #21
0
  // <editor-fold defaultstate="collapsed" desc="Initialization">
  private void init(final int WIDTH, final int HEIGHT) {
    if (WIDTH <= 0 || HEIGHT <= 0) {
      return;
    }

    if (backgroundImage != null) {
      backgroundImage.flush();
    }
    backgroundImage = createBackgroundImage(WIDTH, HEIGHT);
  }
 /**
  * Generates a barcode as bitmap image.
  *
  * @param bargen the BarcodeGenerator to use
  * @param msg the message to encode
  * @param resolution the desired image resolution (dots per inch)
  * @return the requested BufferedImage
  */
 public static BufferedImage getImage(BarcodeGenerator bargen, String msg, int resolution) {
   BarcodeDimension dim = bargen.calcDimensions(msg);
   BufferedImage bi = prepareImage(dim, resolution, BufferedImage.TYPE_BYTE_GRAY);
   int orientation = 0;
   Graphics2D g2d = prepareGraphics2D(bi, dim, orientation, true);
   Java2DCanvasProvider provider = new Java2DCanvasProvider(g2d, orientation);
   bargen.generateBarcode(provider, msg);
   bi.flush();
   return bi;
 }
Example #23
0
 public void dispose() {
   super.dispose();
   if (graphics != null) {
     graphics.dispose();
     graphics = null;
   }
   if (buffer != null) {
     buffer.flush();
     buffer = null;
   }
 }
Example #24
0
 private void generateBubbleList() {
   java.awt.image.BufferedImage image;
   for (int i = 0; i < AMOUNT_OF_BUBBLES; i++) {
     // final java.awt.image.BufferedImage BUBBLE_IMAGE = createBubbleImage((5 +
     // RANDOM.nextInt(MAX_BUBBLE_RADIUS)));
     image = createBubbleImage(5 + RANDOM.nextInt(MAX_BUBBLE_RADIUS));
     bubbleList.add(image);
     image.flush();
     // BUBBLE_IMAGE.flush();
   }
 }
Example #25
0
 public static void resize(File file, int width, int height) throws FileOperationException {
   BufferedImage image;
   try {
     image = ImageIO.read(file);
     image = Scalr.resize(image, Scalr.Method.ULTRA_QUALITY, Scalr.Mode.FIT_EXACT, width, height);
     saveToJPG(image, file);
     image.flush();
   } catch (IOException | IllegalArgumentException e) {
     logger.error(e.getMessage(), e);
     throw new FileOperationException("Resizing failed");
   }
 }
Example #26
0
 public Viewer() {
   image = new BufferedImage(600, 600, 1); // TYPE_INT_RGB
   image.flush();
   addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           System.exit(0);
         }
       });
   setSize(image.getWidth(null), image.getHeight(null) + 30);
   setTitle("Picture");
 }
Example #27
0
  public synchronized void outputNewImage(String filename) {
    switch (layoutPolicy) {
      case COMPUTED_IN_LAYOUT_RUNNER:
        layoutPipeIn.pump();
        break;
      case COMPUTED_ONCE_AT_NEW_IMAGE:
        if (layout != null) layout.compute();
        break;
      case COMPUTED_FULLY_AT_NEW_IMAGE:
        stabilizeLayout(layout.getStabilizationLimit());
        break;
      default:
        break;
    }

    if (resolution.getWidth() != image.getWidth() || resolution.getHeight() != image.getHeight())
      initImage();

    if (clearImageBeforeOutput) {
      for (int x = 0; x < resolution.getWidth(); x++)
        for (int y = 0; y < resolution.getHeight(); y++) image.setRGB(x, y, 0x00000000);
    }

    if (gg.getNodeCount() > 0) {
      if (autofit) {
        gg.computeBounds();

        Point3 lo = gg.getMinPos();
        Point3 hi = gg.getMaxPos();

        renderer.getCamera().setBounds(lo.x, lo.y, lo.z, hi.x, hi.y, hi.z);
      }

      renderer.render(g2d, 0, 0, resolution.getWidth(), resolution.getHeight());
    }

    for (PostRenderer action : postRenderers) action.render(g2d);

    image.flush();

    try {
      File out = new File(filename);

      if (out.getParent() != null && !out.getParentFile().exists()) out.getParentFile().mkdirs();

      ImageIO.write(image, outputType.name(), out);

      printProgress();
    } catch (IOException e) {
      // ?
    }
  }
Example #28
0
 public static void crop(File file, int x, int y, int width, int height)
     throws FileOperationException {
   BufferedImage image;
   try {
     image = ImageIO.read(file);
     image = Scalr.crop(image, x, y, width, height);
     saveToJPG(image, file);
     image.flush();
   } catch (IOException | IllegalArgumentException e) {
     logger.error(e.getMessage(), e);
     throw new FileOperationException("Cropping failed");
   }
 }
Example #29
0
 /**
  * 生成二维码本地文件
  *
  * @param content
  * @param size
  * @param filePath
  */
 public static void createImage(String content, int size, String filePath) {
   try {
     File file = new File(filePath);
     if (!file.exists()) {
       file.createNewFile();
     }
     BufferedImage bufImg = createImage(content, size);
     bufImg.flush();
     ImageIO.write(bufImg, "jpg", file);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  private void saveZoomedTile(
      final KzedZoomedMapTile zmtile,
      final File zoomFile,
      final DynmapBufferedImage zimg,
      int ox,
      int oy,
      String subkey) {
    BufferedImage zIm = null;
    DynmapBufferedImage kzIm = null;
    try {
      zIm = ImageIO.read(zoomFile);
    } catch (IOException e) {
    } catch (IndexOutOfBoundsException e) {
    }

    boolean zIm_allocated = false;
    if (zIm == null) {
      /* create new one */
      kzIm = DynmapBufferedImage.allocateBufferedImage(KzedMap.tileWidth, KzedMap.tileHeight);
      zIm = kzIm.buf_img;
      zIm_allocated = true;
      Debug.debug("New zoom-out tile created " + zmtile.getFilename());
    } else {
      Debug.debug("Loaded zoom-out tile from " + zmtile.getFilename());
    }

    /* blit scaled rendered tile onto zoom-out tile */
    zIm.setRGB(
        ox,
        oy,
        KzedMap.tileWidth / 2,
        KzedMap.tileHeight / 2,
        zimg.argb_buf,
        0,
        KzedMap.tileWidth / 2);

    /* save zoom-out tile */
    if (!zoomFile.getParentFile().exists()) zoomFile.getParentFile().mkdirs();

    try {
      FileLockManager.imageIOWrite(zIm, ImageFormat.FORMAT_PNG, zoomFile);
      Debug.debug("Saved zoom-out tile at " + zoomFile.getName());
    } catch (IOException e) {
      Debug.error("Failed to save zoom-out tile: " + zoomFile.getName(), e);
    } catch (java.lang.NullPointerException e) {
      Debug.error("Failed to save zoom-out tile (NullPointerException): " + zoomFile.getName(), e);
    }

    if (zIm_allocated) DynmapBufferedImage.freeBufferedImage(kzIm);
    else zIm.flush();
  }