public synchronized void paint(Graphics g) {
      if (needToStartThread) {
        totalDrawTime = 0;
        counter = 0;
        needToStartThread = false;
        startThread(beginAngle, endAngle);
        if (firstImage == null) {
          firstImage = createImageFromComponent(component1);
        }
        if (secondImage == null) {
          secondImage = createImageFromComponent(component2);
        }
      }
      if (firstImage == null || secondImage == null) return;
      Graphics2D g2d = (Graphics2D) g;
      int ww = firstImage.getWidth();
      int hh = firstImage.getHeight();
      {
        BufferedImage currImage = null;
        int[] currPixels = null;
        int w = firstImage.getWidth();
        int offset = (int) (w * angle / 180);
        if (offset < 0) offset = 0;
        if (offset > w) offset = w;

        long beforeDraw = System.currentTimeMillis();
        g2d.drawImage(firstImage, null, 0, 0);
        g2d.drawImage(secondImage, null, w - offset, 0);
        totalDrawTime += (System.currentTimeMillis() - beforeDraw);
        counter++;
      }
    }
Exemplo n.º 2
0
 /**
  * Simple image flipper. Can flip image either vertically, horizontally or both directions
  *
  * @param source _
  * @param flipType _
  * @return BufferedImage
  * @throws NullPointerException _
  * @throws IllegalArgumentException _
  */
 public static <T> BufferedImage flipImage(final T source, final FlipType flipType)
     throws NullPointerException, IllegalArgumentException, IOException {
   if (verifyNotNull(source, flipType)) {
     BufferedImage sourceImage = convertToBufferedImage(source);
     BufferedImage target =
         new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), sourceImage.getType());
     AffineTransform affineTransform;
     AffineTransformOp affineTransformOp;
     if (flipType.equals(FlipType.HORIZONTAL) || flipType.equals(FlipType.BOTH)) {
       affineTransform = AffineTransform.getScaleInstance(1, -1);
       affineTransform.translate(-sourceImage.getWidth(), 0);
       affineTransformOp =
           new AffineTransformOp(affineTransform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
       target = affineTransformOp.filter(sourceImage, target);
     }
     if (flipType.equals(FlipType.VERTICAL) || flipType.equals(FlipType.BOTH)) {
       affineTransform = AffineTransform.getScaleInstance(1, -1);
       affineTransformOp =
           new AffineTransformOp(affineTransform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
       affineTransform.translate(0, -sourceImage.getHeight());
       target = affineTransformOp.filter(sourceImage, target);
     }
     return target;
   }
   throw new NullPointerException(E_OBJECT_WAS_NULL);
 }
Exemplo n.º 3
0
  @Override
  protected void paintComponent(Graphics graphics) {
    // Fill in the background:
    Graphics2D g = (Graphics2D) graphics;
    Shape clip = g.getClip();
    g.setColor(LightZoneSkin.Colors.NeutralGray);
    g.fill(clip);

    if (preview == null) {
      PlanarImage image = currentImage.get();
      if (image == null) {
        engine.update(null, false);
      } else if (visibleRect != null && getHeight() > 1 && getWidth() > 1) {
        preview = cropScaleGrayscale(visibleRect, image);
      }
    }
    if (preview != null) {
      int dx, dy;
      AffineTransform transform = new AffineTransform();
      if (getSize().width > preview.getWidth()) dx = (getSize().width - preview.getWidth()) / 2;
      else dx = 0;
      if (getSize().height > preview.getHeight()) dy = (getSize().height - preview.getHeight()) / 2;
      else dy = 0;
      transform.setToTranslation(dx, dy);
      try {
        g.drawRenderedImage(preview, transform);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
0
 public TransparentWindow(BufferedImage img, int x, int y) {
   image = img;
   try {
     Robot robot = new Robot();
     Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
     screen = robot.createScreenCapture(new Rectangle(0, 0, d.width, d.height));
   } catch (AWTException e) {
     throw new Error(e);
   }
   setBounds(x, y, img.getWidth(), img.getHeight());
   setVisible(true);
   buffer = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
   graphics = (Graphics2D) buffer.getGraphics();
 }
Exemplo n.º 6
0
  /**
   * Synchronize the textLayout and the shape (=frame box, by calling syncFrame) with the model When
   * <code>TextLayout</code> is used, this delegates to <code>getRotation()</code> where computing
   * rotation angle is concerned, and updates the AffineTransform returned by <code>
   * getTextToModelTransform()</code>.
   */
  protected void syncShape() {
    PicText te = (PicText) element;

    //			textLayout = new TextLayout(te.getText().length()==0 ? " " : te.getText(),
    //			    textFont,
    //			    new FontRenderContext(null,false,false));

    text2ModelTr.setToIdentity(); // reset
    PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf);
    text2ModelTr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR !
    // the reference point of an image is the top-left one, but the refpoint of a text layout is on
    // the baseline
    if (image != null) {
      text2ModelTr.translate(te.getLeftX(), te.getTopY());
      if (te.getWidth() != 0
          && image.getWidth() != 0
          && (te.getDepth() + te.getHeight()) != 0
          && image.getHeight() != 0)
        text2ModelTr.scale(
            te.getWidth() / image.getWidth(),
            -(te.getHeight() + te.getDepth()) / image.getHeight());
    } else {
      // Hack ? Just cheating a little bit ? Ou juste ruse ?
      // we want here to use the dimensions of the textLayout instead of latex dimensions if
      // areDimensionsComputed
      // sinon on va aligner le textlayout en fonction des parametres latex, et l'Utilisateur (qui
      // est bien bete) ne va rien comprendre.
      double latexH = 0;
      double latexD = 0;
      double latexW = 0;
      if (areDimensionsComputed) { // store latex dimensions, and setDimensions to textLayout ones
        latexH = te.getHeight();
        latexD = te.getDepth();
        latexW = te.getWidth();
        te.setDimensions(
            textLayout.getBounds().getWidth(), textLayout.getAscent(), textLayout.getDescent());
      }
      text2ModelTr.translate(te.getLeftX(), te.getBaseLineY());
      if (areDimensionsComputed) { // restore latex dimensions
        te.setDimensions(latexW, latexH, latexD);
      }
      // Autre possibilite= comprimer le texte pour qu'il rentre dans la boite (evite le hack
      // ci-dessus):
      // text2ModelTr.scale(te.getWidth()/textLayout.getWidth(),-(te.getHeight()+te.getDepth())/textLayout.getHeight());
      text2ModelTr.scale(1.0, -1.0);
    }
    syncFrame();
  }
Exemplo n.º 7
0
 /**
  * Scale the given BufferedImage to width and height that are powers of two. Return the new scaled
  * BufferedImage.
  */
 public static BufferedImage convertToPowerOf2(BufferedImage bsrc) {
   // find powers of 2 equal to or greater than current dimensions
   int newW = GLApp.getPowerOfTwoBiggerThan(bsrc.getWidth());
   int newH = GLApp.getPowerOfTwoBiggerThan(bsrc.getHeight());
   if (newW == bsrc.getWidth() && newH == bsrc.getHeight()) {
     return bsrc; // no change necessary
   } else {
     AffineTransform at =
         AffineTransform.getScaleInstance(
             (double) newW / bsrc.getWidth(), (double) newH / bsrc.getHeight());
     BufferedImage bdest = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_ARGB);
     Graphics2D g = bdest.createGraphics();
     g.drawRenderedImage(bsrc, at);
     return bdest;
   }
 }
 /**
  * Adds next GIF frame. The frame is not written immediately, but is actually deferred until the
  * next frame is received so that timing data can be inserted. Invoking <code>finish()</code>
  * flushes all frames. If <code>setSize</code> was not invoked, the size of the first image is
  * used for all subsequent frames.
  *
  * @param im BufferedImage containing frame to write.
  * @throws IOException if there was an IOException writing the GIF data
  * @throws IllegalArgumentException if this encoder has not been started
  */
 public void addFrame(BufferedImage im) throws IOException {
   if (!started) {
     throw new IllegalStateException("AnimatedGifEncoder not started");
   }
   if (!sizeSet) {
     // use first frame's size
     setSize(im.getWidth(), im.getHeight());
   }
   image = im;
   getImagePixels(); // convert to correct format if necessary
   analyzePixels(); // build color table & map pixels
   if (firstFrame) {
     writeLSD(); // logical screen descriptior
     writePalette(); // global color table
     if (repeat >= 0) {
       // use NS app extension to indicate reps
       writeNetscapeExt();
     }
   }
   writeGraphicCtrlExt(); // write graphic control extension
   writeImageDesc(); // image descriptor
   if (!firstFrame) {
     writePalette(); // local color table
   }
   writePixels(); // encode and write pixel data
   firstFrame = false;
 }
Exemplo n.º 9
0
  /**
   * Adds next GIF frame. The frame is not written immediately, but is actually deferred until the
   * next frame is received so that timing data can be inserted. Invoking <code>finish()</code>
   * flushes all frames. If <code>setSize</code> was not invoked, the size of the first image is
   * used for all subsequent frames.
   *
   * @param im BufferedImage containing frame to write.
   * @return true if successful.
   */
  public boolean addFrame(BufferedImage im) {
    if ((im == null) || !started) {
      return false;
    }
    boolean ok = true;
    try {
      if (!sizeSet) {
        // use first frame's size
        setSize(im.getWidth(), im.getHeight());
      }
      image = im;
      getImagePixels(); // convert to correct format if necessary
      analyzePixels(); // build color table & map pixels
      if (firstFrame) {
        writeLSD(); // logical screen descriptior
        writePalette(); // global color table
        if (repeat >= 0) {
          // use NS app extension to indicate reps
          writeNetscapeExt();
        }
      }
      writeGraphicCtrlExt(); // write graphic control extension
      writeImageDesc(); // image descriptor
      if (!firstFrame) {
        writePalette(); // local color table
      }
      writePixels(); // encode and write pixel data
      firstFrame = false;
    } catch (IOException e) {
      ok = false;
    }

    return ok;
  }
Exemplo n.º 10
0
 public BufferedImage filter(BufferedImage src, BufferedImage dst) {
   icentreX = src.getWidth() * centreX;
   icentreY = src.getHeight() * centreY;
   if (radius == 0) radius = Math.min(icentreX, icentreY);
   radius2 = radius * radius;
   return super.filter(src, dst);
 }
Exemplo n.º 11
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    int width = src.getWidth();
    int height = src.getHeight();
    int type = src.getType();
    WritableRaster srcRaster = src.getRaster();

    originalSpace = new Rectangle(0, 0, width, height);
    transformedSpace = new Rectangle(0, 0, width, height);
    transformSpace(transformedSpace);

    if (dst == null) {
      ColorModel dstCM = src.getColorModel();
      dst =
          new BufferedImage(
              dstCM,
              dstCM.createCompatibleWritableRaster(transformedSpace.width, transformedSpace.height),
              dstCM.isAlphaPremultiplied(),
              null);
    }
    WritableRaster dstRaster = dst.getRaster();

    int[] inPixels = getRGB(src, 0, 0, width, height, null);
    inPixels = filterPixels(width, height, inPixels, transformedSpace);
    setRGB(dst, 0, 0, transformedSpace.width, transformedSpace.height, inPixels);

    return dst;
  }
Exemplo n.º 12
0
 protected void computeGeometry() {
   pictHalfWidth = Width.getInt() / 2;
   pictWidth = pictHalfWidth + pictHalfWidth - 1;
   pictHeight = Height.getInt();
   xLoc = -pictHalfWidth;
   yLoc = -pictHeight / 2;
   setFramesPerCycle(pictWidth - 1);
   setFrameIncrement(FrameIncrement.getInt());
   // System.out.println("width = " + pictWidth);
   // System.out.println("    x = " + xLoc);
   // System.out.println("    y = " + yLoc);
   PxlColor[] ramp = AColor.getPxlColor().sinusoidalRampTo(BColor.getPxlColor(), pictHalfWidth);
   // System.out.println("w=" + (4*pictHalfWidth-1) + ", h=" + pictHeight);
   int ibWidth = 4 * pictHalfWidth - 1;
   if ((imageBuffer == null)
       || (imageBuffer.getWidth() != ibWidth)
       || (imageBuffer.getHeight() != pictHeight)) {
     imageBuffer = new BufferedImage(ibWidth, pictHeight, BufferedImage.TYPE_INT_RGB);
   }
   Graphics g = imageBuffer.getGraphics();
   for (int x = 0; x < pictHalfWidth; x++) {
     g.setColor(ramp[x].dev());
     g.drawLine(x, 0, x, pictHeight - 1);
     if (x < (pictHalfWidth - 1))
       g.drawLine(pictWidth - x - 1, 0, pictWidth - x - 1, pictHeight - 1);
     if (x > 0) g.drawLine(pictWidth + x - 1, 0, pictWidth + x - 1, pictHeight - 1);
     if ((x > 0) && (x < (pictHalfWidth - 1)))
       g.drawLine(4 * pictHalfWidth - 4 - x, 0, 4 * pictHalfWidth - 4 - x, pictHeight - 1);
   }
   g.dispose();
   BitMapElement p = (BitMapElement) getDisplayElement(pictElement);
   p.setImage(imageBuffer);
   p.setLocation(xLoc, yLoc);
   p.setClipRect(xLoc, yLoc, pictWidth, pictHeight);
 }
  protected void drawPointLegend(
      VPFSymbolAttributes attr, Graphics2D g2, int width, int height, int margin) {
    if (attr.getIconImageSource() == null) return;

    BufferedImage icon = getImage(attr.getIconImageSource());
    if (icon != null) {
      // icon width / height
      int iw = icon.getWidth();
      int ih = icon.getHeight();
      // draw area width / height
      int dw = width - margin * 2;
      int dh = height - margin * 2;
      // draw scale to fit icon inside draw area
      float sx = iw > dw ? (float) dw / iw : 1f; // shrink only
      float sy = ih > dh ? (float) dh / ih : 1f;
      float scale = Math.min(sx, sy);
      iw = (int) ((float) iw * scale);
      ih = (int) ((float) ih * scale);
      // Center image and draw
      int x1 = iw < dw ? margin + (dw - iw) / 2 : margin;
      int y1 = ih < dh ? margin + (dh - ih) / 2 : margin;
      g2.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      g2.drawImage(icon, x1, y1, iw, ih, null);
    }
  }
Exemplo n.º 14
0
  private void stuffWithLeastSignificantBit(BufferedImage image, byte[] message) {
    int[] pixelValues = getImagePixels(image);
    if (message.length * 8 > pixelValues.length * 3) {
      System.out.printf("Cannot stuff message in least significant bit\n");
    }

    int messageIndex = 0;
    int currentByteOffset = -1;

    pixls:
    for (int i = 0; i < pixelValues.length; i++) {
      for (int offset = 0; offset < 17; offset += 8) {
        currentByteOffset++;
        if (currentByteOffset > 7) {
          currentByteOffset = 0;
          messageIndex++;
        }
        if (messageIndex >= message.length) break pixls;
        int bitToEncode = (message[messageIndex] >> currentByteOffset) & 1;
        // color = (byte) ((color & 0xfe) | bitToEncode);
        // zero
        pixelValues[i] &= ~(0x1 << offset);
        // fill
        pixelValues[i] |= bitToEncode << offset;
      }
    }

    // put pixel ints back into BufferedImage
    for (int i = 0; i < pixelValues.length; i++) {
      int x = i % image.getWidth();
      int y = i / image.getWidth();
      image.setRGB(x, y, pixelValues[i]);
    }
  }
Exemplo n.º 15
0
  private <T> T scaleImageUsingAffineTransformation(final BufferedImage bufferedImage, T target) {
    BufferedImage destinationImage = generateDestinationImage();
    Graphics2D graphics2D = destinationImage.createGraphics();
    AffineTransform transformation =
        AffineTransform.getScaleInstance(
            ((double) getQualifiedWidth() / bufferedImage.getWidth()),
            ((double) getQualifiedHeight() / bufferedImage.getHeight()));
    graphics2D.drawRenderedImage(bufferedImage, transformation);
    graphics2D.addRenderingHints(retrieveRenderingHints());
    try {
      if (target instanceof File) {
        LOGGER.info(String.format(M_TARGET_TYPE_OF, "File"));
        ImageIO.write(destinationImage, imageType.toString(), (File) target);
      } else if (target instanceof ImageOutputStream) {
        LOGGER.info(String.format(M_TARGET_TYPE_OF, "ImageOutputStream"));
        ImageIO.write(destinationImage, imageType.toString(), (ImageOutputStream) target);
      } else if (target instanceof OutputStream) {
        LOGGER.info(String.format(M_TARGET_TYPE_OF, "OutputStream"));
        ImageIO.write(destinationImage, imageType.toString(), (OutputStream) target);
      } else {
        target = null;
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    return target;
  }
 public SimpleWhiteboardPanel(int width, int height) {
   this.image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
   Graphics g = this.image.getGraphics();
   g.setColor(Color.WHITE);
   g.fillRect(0, 0, image.getWidth(), image.getHeight());
   this.setFocusable(true);
 }
Exemplo n.º 17
0
  private void gameRender() {
    if (dbImage == null) {
      dbImage = createImage(PWIDTH, PHEIGHT);
      if (dbImage == null) {
        System.out.println("dbImage is null");
        return;
      } else dbg = dbImage.getGraphics();
    }

    // draw a white background
    dbg.setColor(Color.white);
    dbg.fillRect(0, 0, PWIDTH, PHEIGHT);

    // draw the game elements: order is important
    ribsMan.display(dbg); // the background ribbons
    bricksMan.display(dbg); // the bricks
    jack.drawSprite(dbg); // the sprites
    fireball.drawSprite(dbg);

    if (showExplosion) // draw the explosion (in front of jack)
    dbg.drawImage(explosionPlayer.getCurrentImage(), xExpl, yExpl, null);

    reportStats(dbg);

    if (gameOver) gameOverMessage(dbg);

    if (showHelp) // draw the help at the very front (if switched on)
    dbg.drawImage(
          helpIm, (PWIDTH - helpIm.getWidth()) / 2, (PHEIGHT - helpIm.getHeight()) / 2, null);
  } // end of gameRender()
Exemplo n.º 18
0
  public static DataRaster wrap(BufferedImage image, AVList params) {
    if (null == image) {
      String message = Logging.getMessage("nullValue.ImageIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    if (null == params) {
      String msg = Logging.getMessage("nullValue.AVListIsNull");
      Logging.logger().finest(msg);
      throw new IllegalArgumentException(msg);
    }

    if (params.hasKey(AVKey.WIDTH)) {
      int width = (Integer) params.getValue(AVKey.WIDTH);
      if (width != image.getWidth()) {
        String msg =
            Logging.getMessage("generic.InvalidWidth", "" + width + "!=" + image.getWidth());
        Logging.logger().finest(msg);
        throw new IllegalArgumentException(msg);
      }
    } else {
      params.setValue(AVKey.WIDTH, image.getWidth());
    }

    if (params.hasKey(AVKey.HEIGHT)) {
      int height = (Integer) params.getValue(AVKey.HEIGHT);
      if (height != image.getHeight()) {
        String msg =
            Logging.getMessage("generic.InvalidHeight", "" + height + "!=" + image.getHeight());
        Logging.logger().finest(msg);
        throw new IllegalArgumentException(msg);
      }
    } else {
      params.setValue(AVKey.HEIGHT, image.getHeight());
    }

    Sector sector = null;
    if (params.hasKey(AVKey.SECTOR)) {
      Object o = params.getValue(AVKey.SECTOR);
      if (o instanceof Sector) {
        sector = (Sector) o;
      }
    }

    return new BufferedImageRaster(sector, image, params);
  }
  private void internalPaintTabBackground(
      Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) {
    BufferedImage leftImg = null;
    BufferedImage middleImg = null;
    BufferedImage rightImg = null;

    Graphics2D g2 = (Graphics2D) g;

    AntialiasingManager.activateAntialiasing(g2);

    int tabOverlap = 0;

    if (isSelected) {
      if (tabPane.isEnabledAt(tabIndex)) {
        leftImg = DesktopUtilActivator.getImage(SELECTED_TAB_LEFT_BG);
        middleImg = DesktopUtilActivator.getImage(SELECTED_TAB_MIDDLE_BG);
        rightImg = DesktopUtilActivator.getImage(SELECTED_TAB_RIGHT_BG);

        tabOverlap = TAB_OVERLAP;
      } else {
        leftImg = DesktopUtilActivator.getImage(TAB_LEFT_BG);
        middleImg = DesktopUtilActivator.getImage(TAB_MIDDLE_BG);
        rightImg = DesktopUtilActivator.getImage(TAB_RIGHT_BG);
      }
    } else {
      leftImg = DesktopUtilActivator.getImage(TAB_LEFT_BG);
      middleImg = DesktopUtilActivator.getImage(TAB_MIDDLE_BG);
      rightImg = DesktopUtilActivator.getImage(TAB_RIGHT_BG);
    }

    // Remove the existing gap between the tabs and the panel, which is due
    // to the removal of the tabbed pane border.
    y++;
    // If the current tab is not the selected tab we paint it 2 more pixels
    // to the bottom in order to create the disabled look.
    if (!isSelected) y += 2;

    g2.drawImage(leftImg, x, y, null);
    g2.drawImage(
        middleImg,
        x + leftImg.getWidth(),
        y,
        w - leftImg.getWidth() - rightImg.getWidth() + tabOverlap,
        leftImg.getHeight(),
        null);
    g2.drawImage(rightImg, x + w - rightImg.getWidth() + tabOverlap, y, null);
  }
Exemplo n.º 20
0
  public synchronized void paint(Graphics gin) {
    Graphics2D g = (Graphics2D) gin;

    if (im == null) return;

    int height = getHeight();
    int width = getWidth();

    if (fit) {
      t = new AffineTransform();
      double scale = Math.min(((double) width) / im.getWidth(), ((double) height) / im.getHeight());
      // we'll re-center the transform in a moment.
      t.scale(scale, scale);
    }

    // if the image (in either X or Y) is smaller than the view port, then center
    // the image with respect to that axis.
    double mwidth = im.getWidth() * t.getScaleX();
    double mheight = im.getHeight() * t.getScaleY();
    if (mwidth < width)
      t.preConcatenate(
          AffineTransform.getTranslateInstance((width - mwidth) / 2.0 - t.getTranslateX(), 0));
    if (mheight < height)
      t.preConcatenate(
          AffineTransform.getTranslateInstance(0, (height - mheight) / 2.0 - t.getTranslateY()));

    // if we're allowing panning (because only a portion of the image is visible),
    // don't allow translations that show less information that is possible.
    Point2D topleft = t.transform(new Point2D.Double(0, 0), null);
    Point2D bottomright = t.transform(new Point2D.Double(im.getWidth(), im.getHeight()), null);

    if (mwidth > width) {
      if (topleft.getX() > 0)
        t.preConcatenate(AffineTransform.getTranslateInstance(-topleft.getX(), 0));
      if (bottomright.getX() < width)
        t.preConcatenate(AffineTransform.getTranslateInstance(width - bottomright.getX(), 0));
      //		    t.translate(width-bottomright.getX(), 0);
    }
    if (mheight > height) {
      if (topleft.getY() > 0)
        t.preConcatenate(AffineTransform.getTranslateInstance(0, -topleft.getY()));
      if (bottomright.getY() < height)
        t.preConcatenate(AffineTransform.getTranslateInstance(0, height - bottomright.getY()));
    }

    g.drawImage(im, t, null);
  }
Exemplo n.º 21
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    if (dst == null) dst = createCompatibleDestImage(src, null);

    int width = src.getWidth();
    int height = src.getHeight();
    int numScratches = (int) (density * width * height / 100);
    ArrayList<Line2D> lines = new ArrayList<Line2D>();
    {
      float l = length * width;
      Random random = new Random(seed);
      Graphics2D g = dst.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setColor(new Color(color));
      g.setStroke(new BasicStroke(this.width));
      for (int i = 0; i < numScratches; i++) {
        float x = width * random.nextFloat();
        float y = height * random.nextFloat();
        float a = angle + ImageMath.TWO_PI * (angleVariation * (random.nextFloat() - 0.5f));
        float s = (float) Math.sin(a) * l;
        float c = (float) Math.cos(a) * l;
        float x1 = x - c;
        float y1 = y - s;
        float x2 = x + c;
        float y2 = y + s;
        g.drawLine((int) x1, (int) y1, (int) x2, (int) y2);
        lines.add(new Line2D.Float(x1, y1, x2, y2));
      }
      g.dispose();
    }

    if (false) {
      //		int[] inPixels = getRGB( src, 0, 0, width, height, null );
      int[] inPixels = new int[width * height];
      int index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float sx = x, sy = y;
          for (int i = 0; i < numScratches; i++) {
            Line2D.Float l = (Line2D.Float) lines.get(i);
            float dot = (l.x2 - l.x1) * (sx - l.x1) + (l.y2 - l.y1) * (sy - l.y1);
            if (dot > 0) inPixels[index] |= (1 << i);
          }
          index++;
        }
      }

      Colormap colormap = new LinearColormap();
      index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float f = (float) (inPixels[index] & 0x7fffffff) / 0x7fffffff;
          inPixels[index] = colormap.getColor(f);
          index++;
        }
      }
      setRGB(dst, 0, 0, width, height, inPixels);
    }
    return dst;
  }
Exemplo n.º 22
0
 public static BufferedImage convertToARGB(BufferedImage image) {
   BufferedImage newImage =
       new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics2D g = newImage.createGraphics();
   g.drawImage(image, 0, 0, null);
   g.dispose();
   return newImage;
 }
Exemplo n.º 23
0
 public static BufferedImage copyImage(BufferedImage source) {
   BufferedImage b =
       new BufferedImage(source.getWidth(), source.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
   Graphics g = b.getGraphics();
   g.drawImage(source, 0, 0, null);
   g.dispose();
   return b;
 }
Exemplo n.º 24
0
 public void drawScaledImage(BufferedImage im, int x, int y, int w, int h) {
   float scaleX = w * 1.0f / im.getWidth();
   float scaleY = h * 1.0f / im.getHeight();
   AffineTransform tx = new AffineTransform();
   tx.scale(scaleX, scaleY);
   BufferedImageOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
   drawImage(im, op, x, y);
 }
 public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel dstCM) {
   if (dstCM == null) dstCM = src.getColorModel();
   return new BufferedImage(
       dstCM,
       dstCM.createCompatibleWritableRaster(src.getWidth(), src.getHeight()),
       dstCM.isAlphaPremultiplied(),
       null);
 }
Exemplo n.º 26
0
 /**
  * Basic nonparametric usage of canny edge detector. No thresholding is used.
  *
  * @param original input image
  */
 public CCannyEdgeDetector(BufferedImage original) {
   size = new Dimension(original.getWidth(), original.getHeight());
   input = original.getData();
   image =
       new BufferedImage(
           (int) size.getWidth(), (int) size.getHeight(), BufferedImage.TYPE_INT_RGB);
   bands = original.getSampleModel().getNumBands();
 }
Exemplo n.º 27
0
 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();
 }
Exemplo n.º 28
0
 /**
  * Scale the given BufferedImage to the given width and height. Return the new scaled
  * BufferedImage.
  */
 public static BufferedImage scale(BufferedImage bsrc, int width, int height) {
   AffineTransform at =
       AffineTransform.getScaleInstance(
           (double) width / bsrc.getWidth(), (double) height / bsrc.getHeight());
   BufferedImage bdest = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
   Graphics2D g = bdest.createGraphics();
   g.drawRenderedImage(bsrc, at);
   return bdest;
 }
Exemplo n.º 29
0
  public JackPanel(JumpingJack jj, long period) {
    jackTop = jj;
    this.period = period;

    setDoubleBuffered(false);
    setBackground(Color.white);
    setPreferredSize(new Dimension(PWIDTH, PHEIGHT));

    setFocusable(true);
    requestFocus(); // the JPanel now has focus, so receives key events

    addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            processKey(e);
          }
        });

    // initialise the loaders
    ImagesLoader imsLoader = new ImagesLoader(IMS_INFO);
    clipsLoader = new ClipsLoader(SNDS_FILE);

    // initialise the game entities
    bricksMan = new BricksManager(PWIDTH, PHEIGHT, BRICKS_INFO, imsLoader);
    int brickMoveSize = bricksMan.getMoveSize();

    ribsMan = new RibbonsManager(PWIDTH, PHEIGHT, brickMoveSize, imsLoader);

    jack =
        new JumperSprite(
            PWIDTH,
            PHEIGHT,
            brickMoveSize,
            bricksMan,
            imsLoader,
            (int) (period / 1000000L)); // in ms

    fireball = new FireBallSprite(PWIDTH, PHEIGHT, imsLoader, this, jack);

    // prepare the explosion animation
    explosionPlayer =
        new ImagesPlayer("explosion", (int) (period / 1000000L), 0.5, false, imsLoader);
    BufferedImage explosionIm = imsLoader.getImage("explosion");
    explWidth = explosionIm.getWidth();
    explHeight = explosionIm.getHeight();
    explosionPlayer.setWatcher(this); // report animation's end back here

    // prepare title/help screen
    helpIm = imsLoader.getImage("title");
    showHelp = true; // show at start-up
    isPaused = true;

    // set up message font
    msgsFont = new Font("SansSerif", Font.BOLD, 24);
    metrics = this.getFontMetrics(msgsFont);
  } // end of JackPanel()
Exemplo n.º 30
0
  public void paint(Graphics g) {

    // image=tool.getImage(imageName);
    int h = image2.getHeight(this) / 2;
    int w = image2.getWidth(this) / 2;
    g.drawImage(image2, 150, 100, this);
    //  g.drawImage(this.image2, 150+w+30, 100,w,h,this);
    // g.drawString(imageName, 170, 50);

  }