All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
com.google.scrollview.ui.SVImageHandler Class Reference

Static Public Member Functions

static PImage readImage (int size, BufferedReader in)
 

Detailed Description

The ScrollViewImageHandler is a helper class which takes care of image processing. It is used to construct an Image from the message-stream and basically consists of a number of utility functions to process the input stream.

Author
wanke.nosp@m.@goo.nosp@m.gle.c.nosp@m.om

Definition at line 29 of file SVImageHandler.java.

Member Function Documentation

static PImage com.google.scrollview.ui.SVImageHandler.readImage ( int  size,
BufferedReader  in 
)
inlinestatic

Reads size bytes from the stream in and interprets it as an image file, encoded as png, and then text-encoded as base 64, returning the decoded bitmap.

Parameters
sizeThe size of the image file.
inThe input stream from which to read the bytes.

Definition at line 42 of file SVImageHandler.java.

42  {
43  char[] charbuffer = new char[size];
44  int numRead = 0;
45  while (numRead < size) {
46  int newRead = -1;
47  try {
48  newRead = in.read(charbuffer, numRead, size - numRead);
49  } catch (IOException e) {
50  System.out.println("Failed to read image data from socket:" + e.getMessage());
51  return null;
52  }
53  if (newRead < 0) {
54  return null;
55  }
56  numRead += newRead;
57  }
58  if (numRead != size) {
59  System.out.println("Failed to read image data from socket");
60  return null;
61  }
62  // Convert the character data to binary.
63  byte[] binarydata = DatatypeConverter.parseBase64Binary(new String(charbuffer));
64  // Convert the binary data to a byte stream and parse to image.
65  ByteArrayInputStream byteStream = new ByteArrayInputStream(binarydata);
66  try {
67  PImage img = new PImage(ImageIO.read(byteStream));
68  return img;
69  } catch (IOException e) {
70  System.out.println("Failed to decode image data from socket" + e.getMessage());
71  }
72  return null;
73  }

The documentation for this class was generated from the following file: