/** constructor */
 public DanceQueuePanel() {
   //	flow layout
   setLayout(new FlowLayout());
   //	uses buffer	to	draw arrows	based	on	queues in an array
   myImage = new BufferedImage(600, 600, BufferedImage.TYPE_INT_RGB);
   myBuffer = myImage.getGraphics();
   // uses timer to queue buffer changes
   time = 0;
   timer = new Timer(5, new Listener());
   timer.start();
   setFocusable(true);
   // picks instructions	based	on	song & level
   if (Danceoff.getSong() == -1 && Danceoff.getDifficulty() == 0) {
     arrows = new Arrow[] {new UpArrow(1000), new DownArrow(2000), new LeftArrow(3000)};
   }
   // setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK, 3),
   //	"DanceQueuePanel"));
   // load images for arrows
   rightArrowImg = null;
   leftArrowImg = null;
   upArrowImg = null;
   downArrowImg = null;
   try {
     rightArrowImg = ImageIO.read(new File("arrowB right.png"));
     leftArrowImg = ImageIO.read(new File("arrowB left.png"));
     upArrowImg = ImageIO.read(new File("arrowB up copy.png"));
     downArrowImg = ImageIO.read(new File("arrowB down.png"));
   } catch (IOException e) {
     warn("YOU FAIL", e);
     System.exit(2);
   }
 }
Example #2
0
  public static ArthurImage add(ArthurImage one, ArthurColor two) {
    BufferedImage image = JavaImageMath.clone(one.bf);

    double r = two.r.val;
    double g = two.g.val;
    double b = two.g.val;

    WritableRaster raster = image.getRaster();
    int[] pixelArray = new int[3];
    for (int y = 0; y < raster.getHeight(); y++) {
      for (int x = 0; x < raster.getWidth(); x++) {
        pixelArray = raster.getPixel(x, y, pixelArray);
        pixelArray[0] = (int) (3 * pixelArray[0] + r) / 4;
        pixelArray[1] = (int) (3 * pixelArray[1] + g) / 4;
        pixelArray[2] = (int) (3 * pixelArray[2] + b) / 4;
        raster.setPixel(x, y, pixelArray);
      }
    }

    // save image
    String outputFn =
        one.filename.substring(0, one.filename.indexOf(".jpg"))
            + "+"
            + // filename can't contain the / or *characters; decide later
            r
            + g
            + b
            + counter
            + ".jpg";
    counter++;

    return new ArthurImage(image, outputFn);
  }
Example #3
0
  public static ArthurImage multiply(
      ArthurImage one, ArthurNumber two) { // change to ArthurNumber later
    double f = Math.abs(two.val);
    // get image
    BufferedImage image = JavaImageMath.clone(one.bf);

    // manipulate image
    WritableRaster raster = image.getRaster();
    int width = (int) (raster.getWidth() * f);
    int height = (int) (raster.getHeight() * f);

    BufferedImage collage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = collage.createGraphics();
    g2d.drawImage(image, 0, 0, width, height, null);
    g2d.dispose();

    // save image
    String outputFn =
        one.filename.substring(0, one.filename.indexOf(".jpg"))
            + "X"
            + // filename can't contain the / or *characters; decide later
            f
            + counter
            + ".jpg";
    counter++;

    return new ArthurImage(collage, outputFn);
  }
Example #4
0
  public static ArthurImage add(ArthurImage one, ArthurNumber two) {
    BufferedImage image = JavaImageMath.clone(one.bf);
    int num = two.val.intValue();

    WritableRaster raster = image.getRaster();
    int[] pixelArray = new int[3];
    for (int y = 0; y < raster.getHeight(); y++) {
      for (int x = 0; x < raster.getWidth(); x++) {
        pixelArray = raster.getPixel(x, y, pixelArray);
        pixelArray[0] = pixelArray[0] + num;
        pixelArray[1] = pixelArray[1] + num;
        pixelArray[2] = pixelArray[2] + num;
        for (int i = 0; i < 3; i++) {
          if (pixelArray[i] > 255) {
            pixelArray[i] = 255;
          }
        }
        raster.setPixel(x, y, pixelArray);
      }
    }

    // save image
    String outputFn =
        one.filename.substring(0, one.filename.indexOf(".jpg"))
            + "+"
            + // filename can't contain the / or *characters; decide later
            num
            + counter
            + ".jpg";
    counter++;

    return new ArthurImage(image, outputFn);
  }
  /** Creates a new instance of IDEJRManFramebufferImpl */
  public IDEJRManFramebufferImpl(String name, BufferedImage image) {
    super("JRMan rendered: " + name, true, true, true, true);
    this.name = name;

    save.setEnabled(false);

    imagePanel.setImage(image);
    imagePanel.addToolbarAction(save);
    if (image.getType() == BufferedImage.TYPE_INT_ARGB
        || image.getType() == BufferedImage.TYPE_INT_ARGB_PRE) {
      imagePanel.setShowTransparencyPattern(true);
    }

    getRootPane().setDoubleBuffered(false);
    getContentPane().add(imagePanel);
    pack();

    ImageResource images = ImageResource.getInstance();

    // set the frame icon
    setFrameIcon(images.getJrMan());

    // add this to the IDE desktop
    MainMenuEventHandlers.getInstance(null)
        .getIdeInstance()
        .getWorkspaceDesktop()
        .addInternalFrame(this, true);
  }
  public static int[] decodeImage(BufferedImage img) {
    /* finds the hidden values in the text file */

    int[] a_b, a, b;
    a = new int[8];
    b = new int[8];
    a_b = new int[2];
    int i;

    for (i = 0; i < a.length; i++) {
      int p = img.getRGB(i, i);
      int[] bin = convertToBinary(p, 32);
      a[i] = bin[0];
    }

    for (; i < (a.length + b.length); i++) {
      int p = img.getRGB(i, i);
      int[] bin = convertToBinary(p, 32);
      b[i - b.length] = bin[0];
    }

    a_b[0] = convertToDigit(a, 8);
    a_b[1] = convertToDigit(b, 8);

    return a_b;
  }
Example #7
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 static BufferedImage encodeImage(String filename, int[] primes) {
    /* encodes a and b in the image using a sequence.
     * We are assuming that the image would be big enough
     * to hold the 16 bits
     */

    BufferedImage img, newimg = null;
    int[] a = convertToBinary(primes[0], 8);
    int[] b = convertToBinary(primes[1], 8);
    int[] a_b = copyBits(a, b); // copy all bits into one array

    try {
      img = ImageIO.read(new File(imagePath + filename));
      for (int i = 0; i < a_b.length; i++) {
        int p = img.getRGB(i, i);
        int[] bin = convertToBinary(p, 32);
        bin[0] = a_b[i];
        int d = convertToDigit(bin, 32);
        img.setRGB(i, i, d);
      }
      ImageIO.write(img, "png", new File(imagePath + "new_" + filename));
      newimg = ImageIO.read(new File(imagePath + "new_" + filename));
    } catch (IOException e) {
      System.out.println("ERROR WRITING IMAGE...\n" + e.toString());
      System.exit(1);
    }

    return newimg;
  }
Example #9
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;
 }
Example #10
0
 public static BufferedImage clone(BufferedImage original) {
   WritableRaster raster = original.getRaster();
   BufferedImage clone =
       new BufferedImage(raster.getWidth(), raster.getHeight(), BufferedImage.TYPE_INT_RGB);
   Graphics2D g2d = clone.createGraphics();
   g2d.drawImage(original, 0, 0, null);
   g2d.dispose();
   return clone;
 }
Example #11
0
 // initialize default image
 private BufferedImage getDefaultImage(int w, int h) {
   BufferedImage defaultImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
   Graphics2D graphics2D = defaultImage.createGraphics();
   graphics2D.setColor(new Color(200, 200, 200));
   graphics2D.fillRect(0, 0, w, h);
   graphics2D.setColor(new Color(130, 130, 130));
   graphics2D.drawRect(0, 0, w - 1, h - 1);
   return defaultImage;
 }
Example #12
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;
 }
 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();
 }
 public static BufferedImage resize(BufferedImage image, int width, int height) {
   BufferedImage bi = new BufferedImage(width, height, BufferedImage.TRANSLUCENT);
   Graphics2D g2d = (Graphics2D) bi.createGraphics();
   g2d.addRenderingHints(
       new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
   g2d.drawImage(image, 0, 0, width, height, null);
   g2d.dispose();
   return bi;
 }
Example #15
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);

  }
Example #16
0
 static BufferedImage addMagnitudes(BufferedImage img1, BufferedImage img2) {
   BufferedImage dst = new BufferedImage(img1.getWidth(), img1.getHeight(), img1.getType());
   for (int y = 0; y < img1.getHeight(); ++y) {
     for (int x = 0; x < img1.getWidth(); ++x) {
       int rgb1 = img1.getRGB(x, y);
       int rgb2 = img2.getRGB(x, y);
       int r1 = (rgb1 & 0x00FF0000) >> 16;
       int r2 = (rgb2 & 0x00FF0000) >> 16;
       int r = (int) (Math.sqrt(r1 * r1 + r2 * r2) / Math.sqrt(2.0));
       if (r > 255) r = 255;
       if (r < 0) r = 0;
       int g1 = (rgb1 & 0x0000FF00) >> 8;
       int g2 = (rgb2 & 0x0000FF00) >> 8;
       int g = (int) (Math.sqrt(g1 * g1 + g2 * g2) / Math.sqrt(2.0));
       if (g > 255) g = 255;
       if (g < 0) g = 0;
       int b1 = rgb1 & 0x000000FF;
       int b2 = rgb2 & 0x000000FF;
       int b = (int) (Math.sqrt(b1 * b1 + b2 * b2) / Math.sqrt(2.0));
       if (b > 255) b = 255;
       if (b < 0) b = 0;
       int rgb = b + (g << 8) + (r << 16);
       dst.setRGB(x, y, rgb);
     }
   }
   return dst;
 }
Example #17
0
 public void drawTileNumC(int tileNum, int x, int y, Color c, Graphics g) {
   BufferedImage coloredTile = tiles[tileNum];
   for (int i = 0; i < this.tW; i++) {
     for (int j = 0; j < this.tH; j++) {
       Color originalColor = new Color(coloredTile.getRGB(i, j), true);
       Color nc = new Color(c.getRed(), c.getGreen(), c.getBlue(), originalColor.getAlpha());
       coloredTile.setRGB(i, j, nc.getRGB());
     }
   }
   g.drawImage(tiles[tileNum], x, y, null);
 }
  /**
   * do damage to character
   *
   * @param Dmg Amount of Damage
   */
  public void Damage(int Dmg, int Type) {
    // If character is already dead then dont do damage
    if (ISDEAD) return;

    // Do damage
    if (Type == 1) {
      // DAMAGE FROM PHYSICAL ATTACK
      if (STATS.ARMOR > Dmg) return;
      HEALTH = HEALTH - Dmg + STATS.ARMOR;
    } else if (Type == 2) {
      // DAMAGE FROM MAGIC ATTACK
      if (STATS.MAGIC_RESIST > Dmg) return;
      HEALTH = HEALTH - Dmg + STATS.MAGIC_RESIST;
    }
    // If an Npc then run and hide
    if (NAI != null) {
      NAI.State = "alarmed";
    }

    // Death condition
    if (HEALTH <= 0) {
      // If player is dead
      if (this.CLASS.equals("Player")) {

        HEALTH = 0;

        // Quit game
        JOptionPane.showMessageDialog(null, "You are dead");
        X = 100;
        Y = 100;
        Opify(50);
        HEALTH = (int) MAX_HEALTH;

      } else {
        // If other character
        // set Death stats
        ISDEAD = true;
        HEALTH = 0;
        // display death
        CLASS = Cl + " (Dead)";

        // Rot effect
        for (int i = 0; i < imgCHARAC.getWidth(); i++) {
          for (int j = 0; j < imgCHARAC.getHeight(); j++) {
            imgCHARAC.setRGB(i, j, imgCHARAC.getRGB(i, j) * (int) Math.pow(3, 3));
          }
        }

        // Make inventory open to looting
        INVENTORY.OPEN_INVEN = true;
      }
    }
  }
Example #19
0
 /*
  *  Create a BufferedImage for Swing components.
  *  All or part of the component can be captured to an image.
  *
  *  @param	 component Swing component to create image from
  *  @param	 region The region of the component to be captured to an image
  *  @param	 fileName name of file to be created or null
  *  @return	image the image for the given region
  *  @exception IOException if an error occurs during writing
  */
 public static BufferedImage createImage(JComponent component, Rectangle region, String fileName)
     throws IOException {
   boolean opaqueValue = component.isOpaque();
   component.setOpaque(true);
   BufferedImage image =
       new BufferedImage(region.width, region.height, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2d = image.createGraphics();
   g2d.setClip(region);
   component.paint(g2d);
   g2d.dispose();
   component.setOpaque(opaqueValue);
   ScreenCapture.writeImage(image, fileName);
   return image;
 }
  /** loads the sprites to be used for the bots */
  public static void loadSprites() {

    try {

      mainImageEast = ImageIO.read(new File("char/archer_east.png"));
      mainImageWest = ImageIO.read(new File("char/archer_west.png"));

      north = new BufferedImage[frameCount];
      south = new BufferedImage[frameCount];
      east = new BufferedImage[frameCount];
      west = new BufferedImage[frameCount];
      north_east = new BufferedImage[frameCount];
      north_west = new BufferedImage[frameCount];
      south_east = new BufferedImage[frameCount];
      south_west = new BufferedImage[frameCount];

      for (int i = 0; i < frameCount; i++) {
        north[i] = mainImageEast.getSubimage(0 * width, height * i, width, height);
        north_east[i] = mainImageEast.getSubimage(1 * width, height * i, width, height);
        east[i] = mainImageEast.getSubimage(2 * width, height * i, width, height);
        south_east[i] = mainImageEast.getSubimage(3 * width, height * i, width, height);
        south[i] = mainImageEast.getSubimage(4 * width, height * i, width, height);

        north_west[i] = mainImageWest.getSubimage(3 * width, height * i, width, height);
        west[i] = mainImageWest.getSubimage(2 * width, height * i, width, height);
        south_west[i] = mainImageWest.getSubimage(1 * width, height * i, width, height);
      }

    } catch (Exception e) {
      System.out.println("Spritesheet Not Found!");
    }
  }
Example #21
0
 public Button(String filename, String filenameHov, int x, int y) {
   File normal = new File(filename);
   File hovered = new File(filenameHov);
   try {
     imageNormal = ImageIO.read(normal);
     imageHovered = ImageIO.read(hovered);
   } catch (Exception e) {
     System.out.println("Picture not working");
   }
   width = imageNormal.getWidth();
   height = imageNormal.getHeight();
   this.x = x;
   this.y = y;
 }
    Sidebar() {
      super(BoxLayout.Y_AXIS);

      try {
        back =
            ImageIO.read(
                ClassLoader.getSystemClassLoader()
                    .getResource("org/madeirahs/editor/ui/help_sidebar.png"));
        scaleImage();
        setPreferredSize(new Dimension(back.getWidth(), back.getHeight()));
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
Example #23
0
  /*
   * Method takes a parameter of a BufferedImage
   * and returns a 2d array
   */
  public static int[][] readIntoArray(BufferedImage x) {
    int width = x.getWidth();
    int height = x.getHeight();

    // initialize the 2d array to the size of the picture
    int[][] imagePixels = new int[width][height];

    for (int i = 0; i < width; i++) {
      for (int j = 0; j < height; j++) {
        imagePixels[i][j] = x.getRGB(i, j); // store RGB value in array
        //     printPixelARGB(x.getRGB(i,j));
      }
    }
    return imagePixels;
  }
Example #24
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();
  }
Example #25
0
  /** Scale this GLImage so width and height are powers of 2. Recreate pixels and pixelBuffer. */
  public void convertToPowerOf2() {
    // make BufferedImage from original pixels
    BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    image.setRGB(0, 0, w, h, pixels, 0, w);

    // scale into new image
    BufferedImage scaledImg = convertToPowerOf2(image);

    // resample pixel data
    w = scaledImg.getWidth(null);
    h = scaledImg.getHeight(null);
    pixels = getImagePixels(scaledImg); // pixels in default Java ARGB format
    pixelBuffer = convertImagePixelsRGBA(pixels, w, h, false); // convert to bytes in RGBA format
    textureW = GLApp.getPowerOfTwoBiggerThan(w); // the texture size big enough to hold this image
    textureH = GLApp.getPowerOfTwoBiggerThan(h); // the texture size big enough to hold this image
  }
Example #26
0
  public static void main(String[] args) {
    try {
      if (args.length != 2) {
        System.err.println("USAGE: java RenderMap map.txt image.png");
        System.exit(1);
      }
      Game game = new Game(args[0], 100, 0);
      if (game.Init() == 0) {
        System.err.println("Error while loading map " + args[0]);
        System.exit(1);
      }

      ArrayList<Color> colors = new ArrayList<Color>();
      colors.add(new Color(106, 74, 60));
      colors.add(new Color(74, 166, 60));
      colors.add(new Color(204, 51, 63));
      colors.add(new Color(235, 104, 65));
      colors.add(new Color(237, 201, 81));
      Color bgColor = new Color(188, 189, 172);
      Color textColor = Color.BLACK;
      Font planetFont = new Font("Sans Serif", Font.BOLD, 11);
      Font fleetFont = new Font("Sans serif", Font.PLAIN, 7);

      GraphicsConfiguration gc =
          GraphicsEnvironment.getLocalGraphicsEnvironment()
              .getDefaultScreenDevice()
              .getDefaultConfiguration();

      BufferedImage image = gc.createCompatibleImage(640, 480);

      Graphics2D _g = (Graphics2D) image.createGraphics();

      // Turn on AA/Speed
      _g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      _g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
      _g.setRenderingHint(
          RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

      game.Render(640, 480, 0.0, null, colors, bgColor, textColor, planetFont, fleetFont, _g);

      File file = new File(args[1]);
      ImageIO.write(image, "png", file);
    } catch (Exception e) {
      System.err.println(e);
    }
  }
  public Color getColorAt(int x, int y) {
    int col = img.getRGB(x, y);
    int r = col >> 16 & 0xff;
    int g = col >> 8 & 0xff;
    int b = col & 0xff;

    return new Color(r, g, b);
  }
Example #28
0
 /**
  * Save an array of ARGB pixels to a PNG file. If flipY is true, flip the pixels on the Y axis
  * before saving.
  */
 public static void savePixelsToPNG(
     int[] pixels, int width, int height, String imageFilename, boolean flipY) {
   if (pixels != null && imageFilename != null) {
     if (flipY) {
       // flip the pixels vertically (opengl has 0,0 at lower left, java is upper left)
       pixels = GLImage.flipPixels(pixels, width, height);
     }
     try {
       // Create a BufferedImage with the RGB pixels then save as PNG
       BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
       image.setRGB(0, 0, width, height, pixels, 0, width);
       javax.imageio.ImageIO.write(image, "png", new File(imageFilename));
     } catch (Exception e) {
       GLApp.err("GLImage.savePixelsToPNG(" + imageFilename + "): exception " + e);
     }
   }
 }
Example #29
0
 public void plot(Color c, int x0, int y0, int z0) {
   Graphics2D g = bi.createGraphics();
   g.setColor(c);
   if (x0 >= XRES || y0 >= YRES || x0 < 0 || y0 < 0) return;
   if (z0 > zbuffer[x0][y0]) {
     g.drawLine(x0, y0, x0, y0);
     zbuffer[x0][y0] = z0;
   }
 }
 /**
  * Converts <code>BufferedImage</code> to <code>ByteBuffer</code>.
  *
  * @param bi Input image
  * @return
  */
 public static ByteBuffer convertImageData(BufferedImage bi) {
   byte[] pixelData = ((DataBufferByte) bi.getRaster().getDataBuffer()).getData();
   //        return ByteBuffer.wrap(pixelData);
   ByteBuffer buf = ByteBuffer.allocateDirect(pixelData.length);
   buf.order(ByteOrder.nativeOrder());
   buf.put(pixelData);
   buf.flip();
   return buf;
 }