// ///////////////////////////////////////////////////////////////
  // 最临近插值算法----不考虑坐标的小数部分
  // 参数: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);
  }
  // This method returns a buffered image with the contents of an image
  // Source: http://www.exampledepot.com/egs/java.awt.image/Image2Buf.html
  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;
  }
Beispiel #3
0
  /**
   * Returns the specified image as icon.
   *
   * @param name name of icon
   * @return icon
   */
  public static ImageIcon icon(final String name) {
    ImageIcon ii = ICONS.get(name);
    if (ii != null) return ii;

    Image img;
    if (GUIConstants.scale > 1) {
      // choose large image or none
      final URL url =
          GUIConstants.large() ? BaseXImages.class.getResource("/img/" + name + "_32.png") : null;

      if (url == null) {
        // resize low-res image if no hi-res image exists
        img = get(url(name));
        final int w = (int) (img.getWidth(null) * GUIConstants.scale);
        final int h = (int) (img.getHeight(null) * GUIConstants.scale);
        final BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        final Graphics2D g2 = tmp.createGraphics();
        g2.setRenderingHint(
            RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2.drawImage(img, 0, 0, w, h, null);
        g2.dispose();
        img = tmp;
      } else {
        img = get(url);
      }
    } else {
      img = get(name);
    }
    ii = new ImageIcon(img);
    ICONS.put(name, ii);
    return ii;
  }
  public BufferedImage createCrystalCase(Image cover) {
    BufferedImage crystal =
        new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = crystal.createGraphics();
    g2.setRenderingHint(
        RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

    int width = cover.getWidth(null);
    int height = cover.getHeight(null);

    float scale;

    if (width > height) {
      scale = (float) IMAGE_WIDTH / (float) width;
    } else {
      scale = (float) IMAGE_HEIGHT / (float) height;
    }

    int scaledWidth = (int) ((float) width * scale);
    int scaledHeight = (int) ((float) height * scale);

    int x = (IMAGE_WIDTH - scaledWidth) / 2;
    int y = (IMAGE_HEIGHT - scaledHeight) / 2;

    g2.drawImage(cover, x, y, scaledWidth, scaledHeight, null);

    g2.dispose();

    return crystal;
  }
Beispiel #5
0
 // buffered images are just better.
 protected static BufferedImage imageToBufferedImage(Image img) {
   BufferedImage bi =
       new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = bi.createGraphics();
   g2.drawImage(img, null, null);
   return bi;
 }
  public void zoomIn() {
    Dimension asz = this.getSize();
    int maxzf = 3;
    int coef = 1;
    int r;

    cmdline =
        "/bin/sh get.sh "
            + j2kfilename
            + " "
            + iw
            + " "
            + ih
            + " "
            + rect.x
            + " "
            + rect.y
            + " "
            + rect.width
            + " "
            + rect.height;
    Exec.execPrint(cmdline);

    rect.x = rect.y = rect.width = rect.height = 0;

    img = pgm.open("out.pgm");

    iw = img.getWidth(this);
    ih = img.getHeight(this);
    bi = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
    big = bi.createGraphics();
    selected = 0;
    fullRefresh = true;
    repaint();
  }
Beispiel #7
0
  /**
   * Construct a GIFEncoder. The constructor will convert the image to an indexed color array.
   * <B>This may take some time.</B>
   *
   * <p>
   *
   * @param image The image to encode. The image <B>must</B> be completely loaded.
   * @exception AWTException Will be thrown if the pixel grab fails. This can happen if Java runs
   *     out of memory. It may also indicate that the image contains more than 256 colors.
   */
  public GIFEncoder(Image image) throws AWTException {
    width_ = (short) image.getWidth(null);
    height_ = (short) image.getHeight(null);

    int values[] = new int[width_ * height_];
    PixelGrabber grabber = new PixelGrabber(image, 0, 0, width_, height_, values, 0, width_);

    try {
      if (grabber.grabPixels() != true)
        throw new AWTException("Grabber returned false: " + grabber.status());
    } catch (InterruptedException e) {;
    }

    byte r[][] = new byte[width_][height_];
    byte g[][] = new byte[width_][height_];
    byte b[][] = new byte[width_][height_];
    int index = 0;
    for (int y = 0; y < height_; ++y)
      for (int x = 0; x < width_; ++x) {
        r[x][y] = (byte) ((values[index] >> 16) & 0xFF);
        g[x][y] = (byte) ((values[index] >> 8) & 0xFF);
        b[x][y] = (byte) ((values[index]) & 0xFF);
        ++index;
      }
    ToIndexedColor(r, g, b);
  }
  public static void saveJPG(Image img, String s) {
    BufferedImage bi =
        new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = bi.createGraphics();
    g2.drawImage(img, null, null);

    FileOutputStream out = null;
    try {
      out = new FileOutputStream(s);
    } catch (java.io.FileNotFoundException io) {
      System.out.println("File Not Found");
    }

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

    try {
      encoder.encode(bi);
      out.close();
    } catch (java.io.IOException io) {
      System.out.println("IOException");
    }
  }
Beispiel #9
0
    // This is used to create a CImage from a Image
    public CImage createFromImage(final Image image) {
      if (image == null) return null;

      MediaTracker mt = new MediaTracker(new Label());
      final int id = 0;
      mt.addImage(image, id);

      try {
        mt.waitForID(id);
      } catch (InterruptedException e) {
      }

      if (mt.isErrorID(id)) {
        return null;
      }

      int w = image.getWidth(null);
      int h = image.getHeight(null);
      BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
      Graphics2D g2 = bimg.createGraphics();
      g2.setComposite(AlphaComposite.Src);
      g2.drawImage(image, 0, 0, null);
      g2.dispose();
      int[] buffer = ((DataBufferInt) bimg.getRaster().getDataBuffer()).getData();
      return new CImage(nativeCreateNSImageFromArray(buffer, w, h));
    }
 public static BufferedImage toBufferedImage(Image image) {
   int width = image.getWidth(null), height = image.getHeight(null);
   if (width <= 0) width = 1;
   if (height <= 0) height = 1;
   BufferedImage ret = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
   ret.getGraphics().drawImage(image, 0, 0, null);
   return ret;
 }
 private void scaleImage() {
   Image img =
       back.getScaledInstance(scx(back.getWidth()), scy(back.getHeight()), Image.SCALE_SMOOTH);
   back =
       new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
   Graphics g = back.getGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
 }
Beispiel #12
0
 private static ImageIcon makeGrayImageIcon1(Image img) {
   BufferedImage source =
       new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
   Graphics g = source.createGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
   ColorConvertOp colorConvert =
       new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
   BufferedImage destination = colorConvert.filter(source, null);
   return new ImageIcon(destination);
 }
Beispiel #13
0
 private static ImageIcon makeGrayImageIcon2(Image img) {
   int w = img.getWidth(null);
   int h = img.getHeight(null);
   BufferedImage destination = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY);
   Graphics g = destination.createGraphics();
   //// g.setColor(Color.WHITE);
   // https://community.oracle.com/thread/1373262 Color to Grayscale to Binary
   // g.fillRect(0, 0, w, h); // need to pre-fill(alpha?)
   g.drawImage(img, 0, 0, null);
   g.dispose();
   return new ImageIcon(destination);
 }
Beispiel #14
0
  /**
   * Draw picture (gif, jpg, or png) centered on (x, y).
   *
   * @param x the center x-coordinate of the image
   * @param y the center y-coordinate of the image
   * @param s the name of the image/picture, e.g., "ball.gif"
   * @throws RuntimeException if the image is corrupt
   */
  public static void picture(double x, double y, String s) {
    Image image = getImage(s);
    double xs = scaleX(x);
    double ys = scaleY(y);
    int ws = image.getWidth(null);
    int hs = image.getHeight(null);
    if (ws < 0 || hs < 0) throw new RuntimeException("image " + s + " is corrupt");

    offscreen.drawImage(
        image, (int) Math.round(xs - ws / 2.0), (int) Math.round(ys - hs / 2.0), null);
    draw();
  }
Beispiel #15
0
 /**
  * Creates a new JpegInfo object.
  *
  * @param image DOCUMENT ME!
  */
 public JpegInfo(Image image) {
   Components = new Object[NumberOfComponents];
   compWidth = new int[NumberOfComponents];
   compHeight = new int[NumberOfComponents];
   BlockWidth = new int[NumberOfComponents];
   BlockHeight = new int[NumberOfComponents];
   imageobj = image;
   imageWidth = image.getWidth(null);
   imageHeight = image.getHeight(null);
   Comment = "JPEG Encoder Copyright 1998, James R. Weeks and BioElectroMech.  ";
   getYCCArray();
 }
  // ///////////////////////////////////////////////////////////////
  // 双线性内插值算法
  // 参数:img:要缩放的Image对象
  // dstW:目标图像宽
  // dstH:目标图像高
  // comp:组件参数,比如Applet
  //
  // 公式:f(i+u,j+v) = (1-u)(1-v)f(i,j) + (1-u)vf(i,j+1) + u(1-v)f(i+1,j) +
  // uvf(i+1,j+1)
  //
  // ///////////////////////////////////////////////////////////////
  public static Image doubleLinearScale(Image img, int dstW, int dstH) {
    OperateImage OI = new OperateImage();
    Image imgTemp;
    int[] scaled, src;
    int srcW, srcH;
    int R, G, B;
    double widthFactor, heightFactor, tempX, tempY;
    // double srcX_float = 0.0, srcY_float = 0.0;// 坐标的小数部分
    // int srcX_int = 0, srcY_int = 0;// 坐标的整数部分
    src = OI.takeImg(img, img.getWidth(null), img.getHeight(null));
    ColorModel cm = ColorModel.getRGBdefault();
    for (int j = 0; j < src.length; j++) {
      R = cm.getRed(src[j]);
      G = cm.getGreen(src[j]);
      B = cm.getBlue(src[j]);
      if (R >= 200 && G >= 200 && B >= 200) src[j] = 0xffffffff;
      else src[j] = 0xff000000;
    }
    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++) {
        tempX = b * widthFactor;
        tempY = a * heightFactor;
        scaled[a * dstW + b] = getDestPixle(src, srcW, srcH, tempX, tempY);
      }
    // System.out.println("双线性内插值算法完成!");
    imgTemp = OI.madeImg(scaled, dstW, dstH);
    ImageFilter filter = new BWFilter();
    return Toolkit.getDefaultToolkit()
        .createImage(new FilteredImageSource(imgTemp.getSource(), filter));
    // return imgTemp;
  }
Beispiel #17
0
  /**
   * Draw picture (gif, jpg, or png) centered on (x, y), rotated given number of degrees
   *
   * @param x the center x-coordinate of the image
   * @param y the center y-coordinate of the image
   * @param s the name of the image/picture, e.g., "ball.gif"
   * @param degrees is the number of degrees to rotate counterclockwise
   * @throws IllegalArgumentException if the image is corrupt
   */
  public static void picture(double x, double y, String s, double degrees) {
    Image image = getImage(s);
    double xs = scaleX(x);
    double ys = scaleY(y);
    int ws = image.getWidth(null);
    int hs = image.getHeight(null);
    if (ws < 0 || hs < 0) throw new IllegalArgumentException("image " + s + " is corrupt");

    offscreen.rotate(Math.toRadians(-degrees), xs, ys);
    offscreen.drawImage(
        image, (int) Math.round(xs - ws / 2.0), (int) Math.round(ys - hs / 2.0), null);
    offscreen.rotate(Math.toRadians(+degrees), xs, ys);

    draw();
  }
 /** Scales an image. To be used for tiles. Probably not the most efficient scaling method. */
 public static Image scaleImage(Image orig, int scale) {
   Image result;
   if (scale != 1) {
     int width = orig.getWidth(null);
     int height = orig.getHeight(null);
     // Scale cropped image to proper size
     result = new BufferedImage(width * scale, height * scale, BufferedImage.TYPE_INT_ARGB);
     Graphics g = ((BufferedImage) result).createGraphics();
     g.drawImage(orig, 0, 0, width * scale, height * scale, 0, 0, width - 1, height - 1, null);
     g.dispose();
   } else {
     return orig;
   }
   return result;
 }
Beispiel #19
0
 /**
  * Return the Image pixels in default Java int ARGB format.
  *
  * @return
  */
 public static int[] getImagePixels(Image image) {
   int[] pixelsARGB = null;
   if (image != null) {
     int imgw = image.getWidth(null);
     int imgh = image.getHeight(null);
     pixelsARGB = new int[imgw * imgh];
     PixelGrabber pg = new PixelGrabber(image, 0, 0, imgw, imgh, pixelsARGB, 0, imgw);
     try {
       pg.grabPixels();
     } catch (Exception e) {
       GLApp.err("Pixel Grabbing interrupted!");
       return null;
     }
   }
   return pixelsARGB;
 }
  public void init() {
    String str;
    int port;

    imgId = 4;
    if (isApplet && (((hostname = this.getParameter("hostname")) == null) || hostname.equals("")))
      hostname = "localhost";
    if (!isApplet || ((str = this.getParameter("cmdPort")) == null)) {
      port = 3000;
    } else {
      port = new Integer(str).intValue();
    }

    this.setSize(512, 512);
    Dimension asz = this.getSize();
    zl.x2 = asz.width;
    zl.y2 = asz.height;

    cmdline =
        "/bin/sh get.sh "
            + j2kfilename
            + " "
            + asz.width
            + " "
            + asz.height
            + " "
            + zl.x1
            + " "
            + zl.y1
            + " "
            + zl.x2
            + " "
            + zl.y2;
    Exec.execPrint(cmdline);
    img = pgm.open("out.pgm");

    iw = img.getWidth(this);
    ih = img.getHeight(this);

    setBackground(Color.black);
    bi = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
    big = bi.createGraphics();
    myMML = new MML(this);
    addMouseListener(myMML);
    addMouseMotionListener(myMML);
  }
  private BufferedImage readImageFile(File imageFile) {
    ImageIcon icon = null;
    try {
      icon = new ImageIcon(imageFile.toURI().toURL());
    } catch (Exception e) {
      Cheshire.exit("Could not read image file %s", imageFile.toString());
    }
    Image image = icon.getImage();

    BufferedImage buffImage =
        new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);

    Graphics g = buffImage.getGraphics();
    g.drawImage(image, 0, 0, null);

    return buffImage;
  }
  /** Open a file and load the image. */
  public void openFile() {
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("."));
    String[] extensions = ImageIO.getReaderFileSuffixes();
    chooser.setFileFilter(new FileNameExtensionFilter("Image files", extensions));
    int r = chooser.showOpenDialog(this);
    if (r != JFileChooser.APPROVE_OPTION) return;

    try {
      Image img = ImageIO.read(chooser.getSelectedFile());
      image =
          new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
      image.getGraphics().drawImage(img, 0, 0, null);
    } catch (IOException e) {
      JOptionPane.showMessageDialog(this, e);
    }
    repaint();
  }
 public ImageOps() {
   setBackground(Color.white);
   for (int i = 0; i < imgName.length; i++) {
     Image image = getImage(imgName[i]);
     int iw = image.getWidth(this);
     int ih = image.getHeight(this);
     img[i] = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
     img[i].createGraphics().drawImage(image, 0, 0, null);
   }
   slider1 = new JSlider(JSlider.VERTICAL, 0, 255, low);
   slider1.setPreferredSize(new Dimension(15, 100));
   slider1.addChangeListener(this);
   slider2 = new JSlider(JSlider.VERTICAL, 0, 255, high);
   slider2.setPreferredSize(new Dimension(15, 100));
   slider2.addChangeListener(this);
   setControls(new Component[] {new DemoControls(this), slider1, slider2});
   setConstraints(new String[] {BorderLayout.NORTH, BorderLayout.WEST, BorderLayout.EAST});
 }
  private static BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
      return (BufferedImage) image;

    } else {
      MediaTracker tracker = new MediaTracker(null /*not sure how this is used*/);
      tracker.addImage(image, 0);
      try {
        tracker.waitForAll();
      } catch (InterruptedException e) {
        throw new IOException(e.getMessage());
      }
      BufferedImage bufImage =
          new BufferedImage(
              image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);

      Graphics g = bufImage.createGraphics();
      g.drawImage(image, 0, 0, null);
      return bufImage;
    }
  }
Beispiel #25
0
 public Sprite(byte abyte0[], Component component) {
   try {
     // Image image = Toolkit.getDefaultToolkit().getImage(location+"mopar.jpg");
     Image image = Toolkit.getDefaultToolkit().createImage(abyte0);
     MediaTracker mediatracker = new MediaTracker(component);
     mediatracker.addImage(image, 0);
     mediatracker.waitForAll();
     myWidth = image.getWidth(component);
     myHeight = image.getHeight(component);
     anInt1444 = myWidth;
     anInt1445 = myHeight;
     anInt1442 = 0;
     anInt1443 = 0;
     myPixels = new int[myWidth * myHeight];
     PixelGrabber pixelgrabber =
         new PixelGrabber(image, 0, 0, myWidth, myHeight, myPixels, 0, myWidth);
     pixelgrabber.grabPixels();
   } catch (Exception _ex) {
     System.out.println("Error converting jpg");
   }
 }
Beispiel #26
0
  /** ****************** Open & Read an Image ********************** */
  void OpenImage2() {
    int returnVal = jfc.showOpenDialog(IPToolKit.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      file1 = jfc.getSelectedFile();
      String path = file.getAbsolutePath();
      //	image = Toolkit.getDefaultToolkit().getImage(path);

      try {
        try {
          inImage1 = new FileImageInputStream(file1);
          len1 = (int) inImage1.length();
          byteArray1 = new byte[len1];
          // System.out.println(len);
          inImage1.read(byteArray1, 0, len1);
          image1 = Toolkit.getDefaultToolkit().createImage(byteArray1);
          MediaTracker t = new MediaTracker(this);
          t.addImage(image1, 0);

          try {
            t.waitForID(1);
          } catch (Exception eeee) {
            System.out.println(eeee);
          }

          w1 = image1.getWidth(null);
          h1 = image1.getHeight(null);

          // System.out.println(w+"\t"+h);

        } catch (Exception fnfe) {
          JOptionPane.showMessageDialog(this, "File: Not Found");
        }
      } catch (Exception ice) {

        JOptionPane.showMessageDialog(this, "File I/O Error");
      }
    }
  }
 private void writeToFile(File selectedFile, ImageWriterSpiFileFilter ff) {
   try {
     ImageOutputStream ios = ImageIO.createImageOutputStream(selectedFile);
     ImageWriter iw = ff.getImageWriterSpi().createWriterInstance();
     iw.setOutput(ios);
     ImageWriteParam iwp = iw.getDefaultWriteParam();
     if (iwp.canWriteCompressed()) {
       iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
       // set maximum image quality
       iwp.setCompressionQuality(1.f);
     }
     Image image = viewerPanel.getImage();
     BufferedImage bufferedImage;
     if (viewerPanel.getImage() instanceof BufferedImage)
       bufferedImage = (BufferedImage) viewerPanel.getImage();
     else {
       bufferedImage =
           new BufferedImage(
               image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
       bufferedImage.createGraphics().drawImage(image, 0, 0, null);
     }
     iw.write(null, new IIOImage(bufferedImage, null, null), iwp);
     iw.dispose();
     ios.close();
   } catch (IOException ioe) {
     JOptionPane.showMessageDialog(
         viewerPanel,
         messagesBundle.getString(
             "ImageViewerPanelSaveAction." + "Error_during_image_saving_message_7"),
         //$NON-NLS-1$
         messagesBundle.getString("ImageViewerPanelSaveAction." + "Error_dialog_title_8"),
         //$NON-NLS-1$
         JOptionPane.ERROR_MESSAGE);
     ioe.printStackTrace();
   }
 }
 public ImageSizer(Image a_image) {
   m_size.width = a_image.getWidth(m_observer);
   m_size.height = a_image.getHeight(m_observer);
 }
Beispiel #29
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    // g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);

    Graphics2D canvas = (Graphics2D) g;

    if (panelBackground != null) {
      canvas.drawImage(panelBackground, 0, 0, getPanelWidth(), getPanelHeight(), null);
    }

    if (dalekDamageImage != null) {
      // int w = 100;
      // int h = (int)  (dalekImage.getHeight(null) * w / dalekImage.getWidth(null)  );

      int h = 200;
      // int w = dalekDamageImage.scaleWidth(h);

      int w = h * dalekDamageImage.getWidth(null) / dalekDamageImage.getHeight(null);

      BufferedImage thumbImage = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
      Graphics2D graphics2D = thumbImage.createGraphics();
      graphics2D.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      graphics2D.drawImage(dalekDamageImage, 0, 0, w, h, null);

      canvas.drawImage(thumbImage, getPanelWidth() / 2 - (w / 2), getPanelHeight() - h - 16, null);

      //	g.drawImage(thumbImage,getPanelWidth()/2 - (w/2), 32 ,null);

    }
    if (dalekTacticalImage != null) {

      // int h = 400;
      // int w = dalekTacticalImage.scaleWidth(h);

      BufferedImage thumbImage =
          new BufferedImage(
              dalekTacticalImage.getWidth(),
              dalekTacticalImage.getHeight(),
              BufferedImage.TYPE_4BYTE_ABGR);
      Graphics2D graphics2D = thumbImage.createGraphics();
      graphics2D.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      graphics2D.drawImage(dalekTacticalImage, 0, 0, null);

      // g.drawImage(thumbImage,getPanelWidth()/2 - (w/2), getPanelHeight() - h - 16 ,null);

      canvas.drawImage(thumbImage, 0, 32, null);

      /*
      Iterator<WeaponUI> it = dalekTacticalImage.iterator();
      int y = 32;
      while (it.hasNext()) {
      	g.drawImage(it.next(),0, y ,null);
      	y += 40; // really want height of WeaponUI.
      }
       */

    }

    // Move to Buffered Image
    if (this.getEngineRun() > 0) {
      this.drawEngineAt(
          canvas, 16, 256, this.getEngineWalk(), this.getEngineRun(), this.getEngineCurrent());
    }
    if (this.name != null) {
      canvas.setFont(techFont);
      canvas.drawString(this.name, 16, 24);
    }
  }
Beispiel #30
0
 public JGPoint getSize() {
   return new JGPoint(img.getWidth(observer), img.getHeight(observer));
 }