tesseract  3.03
com.google.scrollview.ui.SVImageHandler Class Reference

List of all members.

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@google.com

Definition at line 29 of file SVImageHandler.java.


Member Function Documentation

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

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.

                                                              {
    char[] charbuffer = new char[size];
    int numRead = 0;
    while (numRead < size) {
      int newRead = -1;
      try {
        newRead = in.read(charbuffer, numRead, size - numRead);
      } catch (IOException e) {
        System.out.println("Failed to read image data from socket:" + e.getMessage());
        return null;
      }
      if (newRead < 0) {
        return null;
      }
      numRead += newRead;
    }
    if (numRead != size) {
        System.out.println("Failed to read image data from socket");
      return null;
    }
    // Convert the character data to binary.
    byte[] binarydata = DatatypeConverter.parseBase64Binary(new String(charbuffer));
    // Convert the binary data to a byte stream and parse to image.
    ByteArrayInputStream byteStream = new ByteArrayInputStream(binarydata);
    try {
      PImage img = new PImage(ImageIO.read(byteStream));
      return img;
    } catch (IOException e) {
      System.out.println("Failed to decode image data from socket" + e.getMessage());
    }
    return null;
  }

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines