tesseract
3.03
|
Static Public Member Functions | |
static PImage | readImage (int size, BufferedReader in) |
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.
Definition at line 29 of file SVImageHandler.java.
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.
size | The size of the image file. |
in | The 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; }