1 Reply Latest reply on Oct 6, 2010 4:05 AM by Maxideon

    Convert BufferedImage to java awt Point Array

      I need to convert BufferedImage to java.awt.Point array. Am receiving Image as base64 string, then converting it to Byte[] and this array in converted to BufferedImage.

      To do this I need to convert this to a java.awt.Point array. Am following the below steps. However the BufferedImage.getWriteableIndices seems to return 1 tile all the time.

                     String image = "image in base64 string"; // **** I can provide value for this if it helps, its a base64 string
                     byte[] buf = new sun.misc.BASE64Decoder().decodeBuffer(image);

                     InputStream in = new ByteArrayInputStream(buf,0,buf.length);
                     java.awt.Image buffImage = ImageIO.read(in);

      int width = buffImage.getWidth(null);

      int height = buffImage.getHeight(null);
      int type = BufferedImage.TYPE_BYTE_GRAY; // you can experiment with this one

      BufferedImage bi = new BufferedImage(width, height, type);
      Graphics2D g2d = bi.createGraphics();

      g2d.drawImage(buffImage, 0, 0, null);
      bi.flush() ;

      java.awt.Point [] myPoints = bi.getWritableTileIndices() ;
      System.out.println("My Points size is "+myPoints.length); // This is always returning 1

      Any kinda suggestion / direction would greatly help.