This discussion is archived
1 Reply Latest reply: Oct 5, 2010 9:05 PM by Maxideon RSS

Convert BufferedImage to java awt Point Array

801087 Newbie
Currently Being Moderated
Hi,
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);
               in.close();

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);
g2d.dispose();
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.

Thanks,
Scott

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points