0

i have 2 applications. One application act as server and it is created in java and sends continuously screen shot of desktop by using the following code.

public void screenCap() throws IOException, AWTException{

        Rectangle captureSize = new Rectangle(lastXpos, lastYpos, 500, 500);
        img = robot.createScreenCapture(captureSize);
        Robot robot=new Robot();
        OutputStream os = null;
        BufferedImage image = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
        ImageIO.write(image, "jpg", os);
    }

The second application is Android application acts a client application and has to read continuously the above image stream from inputstream.

Could please help me to read the images from inputstream in the client application.

Nikhil
  • 16,194
  • 20
  • 64
  • 81

2 Answers2

0

Use Bitmap decodeStream() method of BitmapFactory Class.

public static Bitmap decodeStream (InputStream is)
Since: API Level 1

Decode an input stream into a bitmap. If the input stream is null, or cannot be used to decode a bitmap, the function returns null. The stream's position will be where ever it was after the encoded data was read.

Example:

    String urlOfBitmap = ""; // Url of inputstream
    Bitmap bitmap = null;
    try {
        InputStream in = new java.net.URL(urlOfBitmap).openStream();
        bitmap = BitmapFactory.decodeStream(in);
    } catch (Exception e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
    }
user370305
  • 108,599
  • 23
  • 164
  • 151
0
FileInputStream in;                       
in = ...;
bitmap  = BitmapFactory.decodeStream(in);
Orabîg
  • 11,718
  • 6
  • 38
  • 58