sending jpg image from pc to android using sockets

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • povs937
    New Member
    • Jun 2009
    • 4

    #1

    sending jpg image from pc to android using sockets

    I am trying to send the screenshots of the pc(java server) to android(client) using sockets. I am not able to do this task.

    Well, also I have successfully send the screenshots from pc(java server) to pc(java client) using sockets. Server is using ImageIO which converts the image into byte array which i sent using sockets and the the client is again using the ImageIO to convert that fetched byte array into a bufferedImage.

    But unfortunately Android does not support ImageIO. It supports some BitmapFactory class. I am not able to work it out. And hence i am not able to transfer image from java server to android client. Need help..plz.
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Never having done this myself, I have to guess about a few points; in general however, the BitmapFactory class looks promising. There are two ways I would try to accomplish this task:
    1. Get the network stream and hand it to the decodeStream function with something like this:
    Code:
    InputStream myInput = ...;
    Bitmap screenshot = BitmapFactory.decodeStream(myInput);
    2. Save the bytes into an array and hand that to BitmapFactory.d ecodeByteArray( ), a bit like the following:
    Code:
    byte[] myInputArray = ...;
    Bitmap screenshot = BitmapFactory.decodeByteArray(myInputArray, 0, myInputArray.length());
    Does that help? If not, can you show us what you've tried so far and tell us, what exactly doesn't work about those attempts?

    Comment

    Working...