Ejemplo n.º 1
0
  public void zoomBestFitOrOne() {
    File file;
    Image image;
    Rectangle visibleRect;

    synchronized (this) {
      file = ImageDisplay.this.file;
      image = ImageDisplay.this.image;
      visibleRect = ImageDisplay.this.visibleRect;
    }

    if (image == null) return;

    if (visibleRect.width != image.getWidth(null) || visibleRect.height != image.getHeight(null)) {
      // The display is not at best fit. => Zoom to best fit
      visibleRect = new Rectangle(0, 0, image.getWidth(null), image.getHeight(null));

    } else {
      // The display is at best fit => zoom to 1:1
      Point center = getCenterImgCoord(visibleRect);
      visibleRect =
          new Rectangle(
              center.x - getWidth() / 2, center.y - getHeight() / 2, getWidth(), getHeight());
      checkVisibleRectPos(image, visibleRect);
    }

    synchronized (this) {
      if (file == this.file) {
        this.visibleRect = visibleRect;
      }
    }
    repaint();
  }
Ejemplo n.º 2
0
 /**
  * 图片水印
  *
  * @param pressImg 水印图片
  * @param targetImg 目标图片
  * @param x 修正值 默认在中间
  * @param y 修正值 默认在中间
  * @param alpha 透明度
  */
 public static final void pressImage(
     String pressImg, String targetImg, int x, int y, float alpha) {
   try {
     File img = new File(targetImg);
     Image src = ImageIO.read(img);
     int wideth = src.getWidth(null);
     int height = src.getHeight(null);
     BufferedImage image = new BufferedImage(wideth, height, BufferedImage.TYPE_INT_RGB);
     Graphics2D g = image.createGraphics();
     g.drawImage(src, 0, 0, wideth, height, null);
     // 水印文件
     Image src_biao = ImageIO.read(new File(pressImg));
     int wideth_biao = src_biao.getWidth(null);
     int height_biao = src_biao.getHeight(null);
     g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
     g.drawImage(
         src_biao,
         (wideth - wideth_biao) / 2,
         (height - height_biao) / 2,
         wideth_biao,
         height_biao,
         null);
     // 水印文件结束
     g.dispose();
     ImageIO.write((BufferedImage) image, "jpg", img);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  public static ImageIcon getSmallSystemIcon(Image img) throws Exception {
    if ((img.getWidth(null) > 20) || (img.getHeight(null) > 20)) {
      if (img.getWidth(null) > img.getHeight(null)) {
        width = 18;
        height = (img.getHeight(null) * 18) / img.getWidth(null);
      } else {
        height = 18;
        width = (img.getWidth(null) * 18) / img.getHeight(null);
      }
    } else {
      return new ImageIcon(img);
    }

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

    g = dest.getGraphics();
    g.drawImage(img, 1, 1, width, height, null);

    g.dispose();

    blurOperator.filter(dest, dest2);

    return new ImageIcon(dest2);
  }
Ejemplo n.º 4
0
  DisplayCanvas() {
    setBackground(Color.white);
    setSize(450, 400);
    addMouseMotionListener(new MouseMotionHandler());

    Image image =
        getToolkit().getImage("D:\\Workspaces\\ADTJunoWorkspace\\Snippets\\images\\qr.png");

    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 1);
    try {
      mt.waitForAll();
    } catch (Exception e) {
      System.out.println("Exception while loading image.");
    }

    if (image.getWidth(this) == -1) {
      System.out.println("no gif file");
      System.exit(0);
    }

    bi =
        new BufferedImage(image.getWidth(this), image.getHeight(this), BufferedImage.TYPE_INT_ARGB);
    Graphics2D big = bi.createGraphics();
    big.drawImage(image, 0, 0, this);
  }
  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);
  }
Ejemplo n.º 6
0
 @Override
 public void paint(Graphics g) {
   // top sky
   Image skytopImage = getImage(SKYTOP_IMAGE);
   if (g.hitClip(0, 0, skytopImage.getWidth(this), skytopImage.getHeight(this)))
     g.drawImage(skytopImage, 0, 0, this);
   // wood area
   Image woodImage = getImage(WOOD_IMAGE);
   int gy = skytopImage.getHeight(this) + AppletConsts.BOARD_EDGE_SIZE + AppletConsts.BOARD_HEIGHT;
   if (g.hitClip(0, gy, woodImage.getWidth(this), woodImage.getHeight(this)))
     g.drawImage(woodImage, 0, gy, this);
   // board stand
   g.setColor(AppletConsts.COLOUR_BOARD_BORDER);
   int by = getHeight() - woodImage.getHeight(this);
   g.fillRect(0, by, getWidth(), AppletConsts.BOARD_STAND_SIZE);
   // board edge
   by = skytopImage.getHeight(this);
   if (g.hitClip(
       0,
       by,
       AppletConsts.BOARD_EDGE_SIZE,
       AppletConsts.BOARD_HEIGHT + AppletConsts.BOARD_EDGE_SIZE)) {
     g.fillRect(
         0,
         by,
         AppletConsts.BOARD_EDGE_SIZE,
         AppletConsts.BOARD_HEIGHT + AppletConsts.BOARD_EDGE_SIZE);
   }
   if (g.hitClip(
       AppletConsts.BOARD_EDGE_SIZE, by, AppletConsts.BOARD_WIDTH, AppletConsts.BOARD_EDGE_SIZE)) {
     g.fillRect(
         AppletConsts.BOARD_EDGE_SIZE, by, AppletConsts.BOARD_WIDTH, AppletConsts.BOARD_EDGE_SIZE);
   }
   super.paint(g);
 }
Ejemplo n.º 7
0
  private Canvas createCanvas(final Graphics graphic, final Rectangle paintArea) {
    final int w = internalDisplaySize.getWidth();
    final int h = internalDisplaySize.getHeight();
    if (doubleBuffering) {
      if ((doubleBuffer == null)
          || (bufferGraphics == null)
          || (doubleBuffer.getWidth(null) < w)
          || (doubleBuffer.getHeight(null) < h)) {
        doubleBuffer = renderingArea.createImage(w, h);
        LOG.debug(
            "buffer sized to " + doubleBuffer.getWidth(null) + "x" + doubleBuffer.getHeight(null));
      }
      bufferGraphics = doubleBuffer.getGraphics().create();
    } else {
      bufferGraphics = graphic;
    }

    bufferGraphics.clearRect(paintArea.x, paintArea.y, paintArea.width, paintArea.height);
    bufferGraphics.clearRect(0, 0, w, h);

    bufferGraphics.setClip(paintArea.x, paintArea.y, paintArea.width, paintArea.height);
    final Canvas c =
        new AwtCanvas(
            bufferGraphics,
            renderingArea,
            paintArea.x,
            paintArea.y,
            paintArea.width,
            paintArea.height);
    // Canvas c = new Canvas(bufferGraphics, 0, 0, w, h);
    return c;
  }
Ejemplo n.º 8
0
  /**
   * 把图片印刷到图片上
   *
   * @param pressImg -- 水印文件
   * @param targetImg -- 目标文件
   * @param x
   * @param y
   */
  public static final void pressImage(String pressImg, String targetImg, int x, int y) {
    try {
      File _file = new File(targetImg);
      Image src = ImageIO.read(_file);
      int wideth = src.getWidth(null);
      int height = src.getHeight(null);
      BufferedImage image = new BufferedImage(wideth, height, BufferedImage.TYPE_INT_RGB);
      Graphics g = image.createGraphics();
      g.drawImage(src, 0, 0, wideth, height, null);

      // 水印文件
      File _filebiao = new File(pressImg);
      Image src_biao = ImageIO.read(_filebiao);
      int wideth_biao = src_biao.getWidth(null);
      int height_biao = src_biao.getHeight(null);
      g.drawImage(
          src_biao,
          wideth - wideth_biao - x,
          height - height_biao - y,
          wideth_biao,
          height_biao,
          null);
      // /
      g.dispose();
      FileOutputStream out = new FileOutputStream(targetImg);
      JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
      encoder.encode(image);
      out.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 9
0
  @Override
  protected void paintComponent(Graphics _g) {

    Graphics2D g = (Graphics2D) _g;

    if (image == null) {

      image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
      Graphics2D gg = (Graphics2D) image.getGraphics();

      gg.drawImage(right, getWidth() - right.getWidth(null), 0, null);
      gg.drawImage(left, 0, 0, null);
      gg.drawImage(
          middle,
          left.getWidth(null),
          0,
          getWidth() - right.getWidth(null) - left.getWidth(null),
          getHeight(),
          null);

      gg.setColor(new Color(207, 207, 207));
      gg.setFont(font);
      gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      int stringWidth = gg.getFontMetrics(font).stringWidth(text);
      gg.drawString(text, (getWidth() - stringWidth) / 2, 20);
      gg.dispose();
    }

    //		g.setColor(new Color(0,0,0,200));
    //		g.fillRect(0, 0, getWidth(), getHeight());

    g.drawImage(image, 0, 0, null);
  }
Ejemplo n.º 10
0
  @Override
  public void update() {

    if (GameData.getphase() == PHASE.TWO || GameData.getphase() == PHASE.THREE) {
      bonus.setActive(true);
      bonus.update();
    }

    if (blinking) {
      long elapsed = (System.nanoTime() - blinkTimer) / 1000000;
      if (elapsed > 1000) {
        blinking = false;
      }
    }

    // set boundaries of the ship (player):
    // on X axis
    if (x <= GamePanel.WIDTH - playerImage.getWidth(null) / 2) {
      x = GamePanel.WIDTH - playerImage.getWidth(null) / 2;
    }

    if (x > GamePanel.PWIDTH + playerImage.getWidth(null) / 2) {
      x = GamePanel.PWIDTH + playerImage.getWidth(null) / 2;
    }

    // on Y axis
    if (y < GamePanel.HEIGHT - playerImage.getHeight(null) / 2) {
      y = GamePanel.HEIGHT - playerImage.getHeight(null) / 2;
    }

    if (y > GamePanel.PHEIGHT - playerImage.getHeight(null) / 2) {
      y = GamePanel.PHEIGHT - playerImage.getHeight(null) / 2;
    }
  }
Ejemplo n.º 11
0
  public void paint(Graphics g) {
    if (scale == 0.0f) getScaledImages();
    double rollRad = roll * Math.PI / 180;
    // Center of Horizon Image
    Point ptRotation = new Point(125, 360);
    // Center of Instrument
    Point ptCenter = new Point(150, 150);
    // Modified Center of Rotation
    Point ptModRot = new Point(ptCenter.x - 2 * ptRotation.x, ptCenter.y - 2 * ptRotation.y);
    Graphics2D g2d = (Graphics2D) g;

    // Set bounds
    g2d.setClip(
        0,
        0,
        (int) (attitudeBackground.getWidth(null)),
        (int) (attitudeBackground.getHeight(null)));
    RotateAndTranslate(g2d, attitudeSky, rollRad, 0.0, ptModRot, 4 * pitch, ptRotation, scale);
    g2d.drawImage(
        attitudeMarker,
        Math.round(
            (float)
                ((0.5 * attitudeBackground.getWidth(null) - 0.5 * attitudeMarker.getWidth(null)))),
        Math.round(
            (float)
                ((0.5 * attitudeBackground.getHeight(null)
                    - 0.5 * attitudeMarker.getHeight(null)))),
        Math.round(attitudeMarker.getWidth(null)),
        Math.round(attitudeMarker.getHeight(null)),
        null);

    g2d.dispose();
    g.dispose();
  }
Ejemplo n.º 12
0
  private void drawWeaponTokenForRoom(
      Graphics g, Board board, Room room, double centreX, double topY, double step) {
    Weapon weapon = _weaponLocations.get(room);

    if (weapon != null) {
      Image weaponTokenImage = weapon.tokenImage();

      double weaponTokenWidth = weaponTokenImage.getWidth(null);
      double weaponTokenHeight = weaponTokenImage.getHeight(null);

      double longestSideLength = step * WeaponTokenRatio;

      // scale so that the longest side is always larger
      if (weaponTokenWidth >= weaponTokenHeight) {
        weaponTokenWidth = longestSideLength;
        double ratio = weaponTokenImage.getWidth(null) / weaponTokenWidth;
        weaponTokenHeight = weaponTokenHeight / ratio;
      } else {
        weaponTokenHeight = longestSideLength;
        double ratio = weaponTokenImage.getHeight(null) / weaponTokenHeight;
        weaponTokenWidth = weaponTokenWidth / ratio;
      }

      g.drawImage(
          weaponTokenImage,
          (int) (centreX - weaponTokenWidth / 2),
          (int) (topY),
          (int) weaponTokenWidth,
          (int) weaponTokenHeight,
          null);
    }
  }
Ejemplo n.º 13
0
  // ///////////////////////////////////////////////////////////////
  // 最临近插值算法----不考虑坐标的小数部分
  // 参数:img:要缩放的Image对象
  // dstW:目标图像宽
  // dstH:目标图像高
  // comp:组件参数,比如Applet
  // ///////////////////////////////////////////////////////////////
  public static Image simpleScale(Image img, int dstW, int dstH) {
    OperateImage OI = new OperateImage();
    int[] scaled, src;
    double widthFactor, heightFactor;
    int srcX = 0, srcY = 0, srcW, srcH;
    src = OI.takeImg(img, img.getWidth(null), img.getHeight(null));
    scaled = new int[dstW * dstH]; // 存放缩放后的图片
    srcW = img.getWidth(null);
    srcH = img.getHeight(null);

    widthFactor = srcW / (dstW + 0.0);
    // System.out.println("widthFactor:"+widthFactor);
    heightFactor = srcH / (dstH + 0.0);
    // System.out.println("heightFactor:"+heightFactor);
    for (int a = 0; a < dstH; a++)
      for (int b = 0; b < dstW; b++) {
        if ((b * widthFactor) % 1 >= 0.5) srcX = (int) (b * widthFactor) + 1;
        else srcX = (int) (b * widthFactor);
        if ((a * heightFactor) % 1 >= 0.5) srcY = (int) (a * heightFactor) + 1;
        else srcY = (int) (a * heightFactor);
        if (srcX > srcW - 1) srcX = srcW - 1;
        if (srcY > srcH - 1) srcY = srcH - 1;
        scaled[a * dstW + b] = src[srcY * srcW + srcX];
      }
    // System.out.println("最临近插值算法完成!");
    return OI.madeImg(scaled, dstW, dstH);
  }
    public VideoTrack(PullSourceStream stream) throws ResourceUnavailableException {
      super();

      this.stream = stream;
      // set format

      // read first frame to determine format
      final Buffer buffer = new Buffer();
      readFrame(buffer);
      if (buffer.isDiscard() || buffer.isEOM())
        throw new ResourceUnavailableException("Unable to read first frame");
      // TODO: catch runtime exception too?

      // parse jpeg
      final java.awt.Image image;
      try {
        image =
            ImageIO.read(
                new ByteArrayInputStream(
                    (byte[]) buffer.getData(), buffer.getOffset(), buffer.getLength()));
      } catch (IOException e) {
        logger.log(Level.WARNING, "" + e, e);
        throw new ResourceUnavailableException("Error reading image: " + e);
      }

      if (image == null) {
        logger.log(Level.WARNING, "Failed to read image (ImageIO.read returned null).");
        throw new ResourceUnavailableException();
      }

      if (frameContentType.equals("image/jpeg"))
        format =
            new JPEGFormat(
                new Dimension(image.getWidth(null), image.getHeight(null)),
                Format.NOT_SPECIFIED,
                Format.byteArray,
                -1.f,
                Format.NOT_SPECIFIED,
                Format.NOT_SPECIFIED);
      else if (frameContentType.equals("image/gif"))
        format =
            new GIFFormat(
                new Dimension(image.getWidth(null), image.getHeight(null)),
                Format.NOT_SPECIFIED,
                Format.byteArray,
                -1.f);
      else if (frameContentType.equals("image/png"))
        format =
            new PNGFormat(
                new Dimension(image.getWidth(null), image.getHeight(null)),
                Format.NOT_SPECIFIED,
                Format.byteArray,
                -1.f);
      else
        throw new ResourceUnavailableException(
            "Unsupported frame content type: " + frameContentType);
      // TODO: this discards first image. save and return first time
      // readFrame is called.

    }
Ejemplo n.º 15
0
 private void checkVisibleRectSize(Image image, Rectangle visibleRect) {
   if (visibleRect.width > image.getWidth(null)) {
     visibleRect.width = image.getWidth(null);
   }
   if (visibleRect.height > image.getHeight(null)) {
     visibleRect.height = image.getHeight(null);
   }
 }
Ejemplo n.º 16
0
 @Override
 protected int getContentWidth() {
   int w = super.getContentWidth();
   if (img_base != null && w < img_base.getWidth(null)) {
     return img_base.getWidth(null);
   }
   return w;
 }
Ejemplo n.º 17
0
 /**
  * Draws the specified image at the given coordinates.
  *
  * @param x X coordinate
  * @param y Y coordinate
  * @param image Image to draw
  */
 public void drawImage(int x, int y, Image image) {
   byte[] bytes = MapPalette.imageToBytes(image);
   int width = image.getWidth(null);
   for (int xx = 0; xx < image.getWidth(null); ++xx) {
     for (int yy = 0; yy < image.getHeight(null); ++yy) {
       setPixel(x + xx, y + yy, bytes[yy * width + xx]);
     }
   }
 }
Ejemplo n.º 18
0
 /**
  * 缩放图像(按高度和宽度缩放)
  *
  * @param srcImageFile 源图像文件地址
  * @param result 缩放后的图像地址
  * @param height 缩放后的高度
  * @param width 缩放后的宽度
  * @param bb 比例不对时是否需要补白:true为补白; false为不补白;
  */
 @SuppressWarnings("static-access")
 public static final void scale2(
     String srcImageFile, String result, int height, int width, boolean bb) {
   try {
     double ratio = 0.0; // 缩放比例
     File f = new File(srcImageFile);
     BufferedImage bi = ImageIO.read(f);
     Image itemp =
         bi.getScaledInstance(
             width, height, bi.SCALE_SMOOTH); // bi.SCALE_SMOOTH  选择图像平滑度比缩放速度具有更高优先级的图像缩放算法。
     // 计算比例
     if ((bi.getHeight() > height) || (bi.getWidth() > width)) {
       if (bi.getHeight() > bi.getWidth()) {
         ratio = (new Integer(height)).doubleValue() / bi.getHeight();
       } else {
         ratio = (new Integer(width)).doubleValue() / bi.getWidth();
       }
       AffineTransformOp op =
           new AffineTransformOp(
               AffineTransform // 仿射转换
                   .getScaleInstance(ratio, ratio),
               null); // 返回表示剪切变换的变换
       itemp = op.filter(bi, null); // 转换源 BufferedImage 并将结果存储在目标 BufferedImage 中。
     }
     if (bb) { // 补白
       BufferedImage image =
           new BufferedImage(
               width, height, BufferedImage.TYPE_INT_RGB); // 构造一个类型为预定义图像类型之一的 BufferedImage。
       Graphics2D g = image.createGraphics(); // 创建一个 Graphics2D,可以将它绘制到此 BufferedImage 中。
       g.setColor(Color.white); // 控制颜色
       g.fillRect(0, 0, width, height); // 使用 Graphics2D 上下文的设置,填充 Shape 的内部区域。
       if (width == itemp.getWidth(null))
         g.drawImage(
             itemp,
             0,
             (height - itemp.getHeight(null)) / 2,
             itemp.getWidth(null),
             itemp.getHeight(null),
             Color.white,
             null);
       else
         g.drawImage(
             itemp,
             (width - itemp.getWidth(null)) / 2,
             0,
             itemp.getWidth(null),
             itemp.getHeight(null),
             Color.white,
             null);
       g.dispose();
       itemp = image;
     }
     ImageIO.write((BufferedImage) itemp, "JPEG", new File(result));
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 19
0
  /**
   * 缩放
   *
   * @param filePath 图片路径
   * @param height 高度
   * @param width 宽度
   * @param bb 比例不对时是否需要补白
   */
  public static void resize(String filePath, int height, int width, boolean bb) {
    try {
      double ratio = 0.0; // 缩放比例
      File f = new File(filePath);
      BufferedImage bi = ImageIO.read(f);
      /*AffineTransform affineTransform = new AffineTransform();
      affineTransform.scale(width, height);
      RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT);

      AffineTransformOp affineTransformOp = new AffineTransformOp(affineTransform, hints);
      BufferedImage image = new BufferedImage(width, height, bi.getType());
      image = affineTransformOp.filter(bi, image);*/
      Image itemp = bi.getScaledInstance(width, height, bi.SCALE_SMOOTH);
      // 计算比例
      if ((bi.getHeight() > height) || (bi.getWidth() > width)) {
        if (bi.getHeight() > bi.getWidth()) {
          ratio = (new Integer(height)).doubleValue() / bi.getHeight();
        } else {
          ratio = (new Integer(width)).doubleValue() / bi.getWidth();
        }
        AffineTransformOp op =
            new AffineTransformOp(AffineTransform.getScaleInstance(ratio, ratio), null);
        itemp = op.filter(bi, null);
      }
      if (bb) {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = image.createGraphics();
        g.setColor(Color.white);
        g.fillRect(0, 0, width, height);
        if (width == itemp.getWidth(null))
          g.drawImage(
              itemp,
              0,
              (height - itemp.getHeight(null)) / 2,
              itemp.getWidth(null),
              itemp.getHeight(null),
              Color.white,
              null);
        else
          g.drawImage(
              itemp,
              (width - itemp.getWidth(null)) / 2,
              0,
              itemp.getWidth(null),
              itemp.getHeight(null),
              Color.white,
              null);
        g.dispose();
        itemp = image;
      }
      ImageIO.write((BufferedImage) itemp, "jpg", f);
      // ImageIO.write(image, "jpg", f);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
 public BufferedImage GetImage() {
   if (m_image.getImage() instanceof BufferedImage) return (BufferedImage) m_image.getImage();
   Image image = m_image.getImage();
   BufferedImage bimage =
       new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
   Graphics m_graphics = bimage.createGraphics();
   m_graphics.drawImage(image, 0, 0, image.getWidth(null), image.getHeight(null), null);
   m_image = new ImageIcon(bimage);
   return bimage;
 }
Ejemplo n.º 21
0
 public Insets getBorderInsets(Component c) {
   if (insets != null) {
     return insets;
   } else {
     return new Insets(
         top_center.getHeight(null),
         left_center.getWidth(null),
         bottom_center.getHeight(null),
         right_center.getWidth(null));
   }
 }
  protected LegendColorSlider(Image image, int sliderPosX, int sliderPosY) {
    Dimension beadDim = new Dimension(image.getWidth(this), image.getHeight(this));

    sliderImage = image;

    sliderPosition = new Point(sliderPosX, sliderPosY);

    sliderSpace = new Rectangle(sliderPosition, beadDim);

    setSize(image.getWidth(null), image.getHeight(null));
  }
Ejemplo n.º 23
0
 public static BufferedImage fetchFromURL(URL url) {
   Image i = new ImageIcon(url).getImage();
   if (i.getWidth(null) <= 0 || i.getHeight(null) <= 0) {
     CrimsonLog.warning("BAD IMAGE! (%s)", url);
     return null;
   }
   BufferedImage bi =
       new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB);
   bi.getGraphics().drawImage(i, 0, 0, null);
   return bi;
 }
Ejemplo n.º 24
0
  // 图片处理
  public Boolean compressPic() {
    try {
      // 获得源文件
      //            file = new File(inputDir);
      //            //System.out.println(inputDir + inputFileName);
      //            if (!file.exists()) {
      //                throw new IllegalArgumentException("文件不存在");
      //            }
      Image img = ImageIO.read(is);
      // 判断图片格式是否正确
      if (img.getWidth(null) == -1) {
        System.out.println(" can't read,retry!" + "<BR>");
        return false;
      } else {
        int newWidth;
        int newHeight;
        // 判断是否是等比缩放
        if (this.proportion == true) {
          // 为等比缩放计算输出的图片宽度及高度
          double rate1 = ((double) img.getWidth(null)) / (double) outputWidth + 0.1;
          double rate2 = ((double) img.getHeight(null)) / (double) outputHeight + 0.1;
          // 根据缩放比率大的进行缩放控制
          double rate = rate1 > rate2 ? rate1 : rate2;
          newWidth = (int) (((double) img.getWidth(null)) / rate);
          newHeight = (int) (((double) img.getHeight(null)) / rate);
        } else {
          newWidth = outputWidth; // 输出的图片宽度
          newHeight = outputHeight; // 输出的图片高度
        }
        BufferedImage tag =
            new BufferedImage((int) newWidth, (int) newHeight, BufferedImage.TYPE_INT_RGB);

        /*
         * Image.SCALE_SMOOTH 的缩略算法 生成缩略图片的平滑度的 优先级比速度高 生成的图片质量比较好 但速度慢
         */
        tag.getGraphics()
            .drawImage(img.getScaledInstance(newWidth, newHeight, Image.SCALE_FAST), 0, 0, null);
        File f = new File(outputDir);
        if (!f.exists()) {
          f.mkdirs();
        }
        FileOutputStream out = new FileOutputStream(outputDir + outputFileName);
        // JPEGImageEncoder可适用于其他图片类型的转换
        ImageIO.write(tag, "jpeg", out);
        //                JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
        //                encoder.encode(tag);
        out.close();
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return true;
  }
Ejemplo n.º 25
0
 public EmulatorButton(Image img, int w, int h, int x, int y, boolean flag, int sizew, int sizeh) {
   if (flag) {
     this.bitmap = GraphicsUtils.drawClipImage(img, w, h, x, y);
   } else {
     this.bitmap = img;
   }
   if (img.getWidth(null) != sizew || img.getHeight(null) != sizeh) {
     this.bitmap = GraphicsUtils.getResize(bitmap, sizew, sizeh);
   }
   this.bitmap1 = ImageFilterFactory.getGray(bitmap);
   this.bounds = new RectBox(0, 0, bitmap.getWidth(null), bitmap.getHeight(null));
 }
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   if (image != null) {
     g.drawImage(
         image,
         (this.getWidth() / 2) - (image.getWidth(this) / 2),
         (this.getHeight() / 2) - (image.getHeight(this) / 2),
         image.getWidth(this),
         image.getHeight(this),
         this);
   }
 }
Ejemplo n.º 27
0
 private FinFase2() {
   im = Lienzo.cargarImagen("imagenes/FinFase2.png");
   Image img = Lienzo.cargarImagen("imagenes/skip.png");
   Image img2 = Lienzo.cargarImagen("imagenes/skip-pulsado.png");
   try {
     skip = new BotonGeneral(img, img2, "skip", 900, 550, img.getWidth(null), img.getHeight(null));
   } catch (Exception e) {
     e.printStackTrace();
   }
   skip = new Boton(img, "skip", 900, 550, img.getWidth(null), img.getHeight(null));
   new ObservadorTransicionFase(skip);
 }
Ejemplo n.º 28
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);
 }
Ejemplo n.º 29
0
  // This method returns a buffered image with the contents of an image
  public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
      return (BufferedImage) image;
    }

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();

    // Determine if the image has transparent pixels;
    // for this method's
    // implementation, see Determining If an Image Has
    // Transparent Pixels
    boolean hasAlpha = hasAlpha(image);

    // Create a buffered image with a format that's compatible
    // with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
      // Determine the type of transparency of the new
      //				 buffered image
      int transparency = Transparency.OPAQUE;
      if (hasAlpha) {
        transparency = Transparency.BITMASK;
      }

      // Create the buffered image
      GraphicsDevice gs = ge.getDefaultScreenDevice();
      GraphicsConfiguration gc = gs.getDefaultConfiguration();
      bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
    } catch (HeadlessException e) {
      // The system does not have a screen
    }

    if (bimage == null) {
      // Create a buffered image using the default color model
      int type = BufferedImage.TYPE_INT_RGB;
      if (hasAlpha) {
        type = BufferedImage.TYPE_INT_ARGB;
      }
      bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
    }

    // Copy image to buffered image
    Graphics g = bimage.createGraphics();

    // Paint the image onto the buffered image
    g.drawImage(image, 0, 0, null);
    g.dispose();

    return bimage;
  }
Ejemplo n.º 30
0
  protected void createComponents() {
    main = new JPanel();
    main.setLayout(null);

    int divY = 42;

    BackgroundPanel div = new BackgroundPanel(hLine);
    div.setBounds(0, divY, 1920, 2);
    div.setStyle(BackgroundPanel.SCALED_X);

    JPanel tools = new JPanel(null);
    tools.setBounds(0, 0, 800, divY);

    bNew = new JButton("");
    bNew.setIcon(new ImageIcon(newButtonImage));
    bNew.setBorderPainted(false);
    bNew.setBounds(10, 10, newButtonImage.getWidth(null), newButtonImage.getHeight(null));

    search = new SearchTextField(searchHint, ElephantWindow.fontMedium);
    search.setBorder(BorderFactory.createEmptyBorder(0, 22, 0, 20));
    search.setBounds(newButtonImage.getWidth(null) + 10, 8, 160, 26);
    search.setFont(ElephantWindow.fontMedium);
    search.setFixedColor(Color.decode("#e9e9e9"));
    search.useV2();
    search.windowFocusGained();

    trash = new JButton("");
    trash.setBorderPainted(false);
    trash.setContentAreaFilled(false);
    trash.setIcon(new ImageIcon(noteToolsTrash));
    trash.setVisible(this instanceof Notebooks);
    trash.setBounds(
        newButtonImage.getWidth(null) + 177,
        10,
        noteToolsTrash.getWidth(null),
        noteToolsTrash.getHeight(null));

    tools.add(bNew);
    tools.add(search);
    tools.add(trash);

    scroll = new JScrollPane(main);
    scroll.setBorder(ElephantWindow.emptyBorder);
    scroll.getHorizontalScrollBar().setUnitIncrement(5);
    scroll.getVerticalScrollBar().setUnitIncrement(5);

    add(tools);
    add(div);
    add(scroll);

    addComponentListeners();
  }