Results 1 to 6 of 6
  1. #1
    gyijhbk is offline Member
    Join Date
    Feb 2012
    Posts
    61
    Rep Power
    0

    Default How to send imagebuffer over socket?

    How to send bufferеdimage over socket?
    Last edited by gyijhbk; 06-18-2012 at 12:15 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: How to send imagebuffer over socket?

    What have you tried? How about writeObject()
    What does the receiving side want? A java object or the bytes of an image?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default Re: How to send imagebuffer over socket?

    I'm not sure BufferedImage is serializable, so writeObject() won't work.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: How to send imagebuffer over socket?

    Good point.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default Re: How to send imagebuffer over socket?

    Send over the RGB data (just an int array) and the type of the BufferedImage and its dimensions (just three single ints) and construct a new BufferedImage on the other side.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Pojahn_M's Avatar
    Pojahn_M is offline Senior Member
    Join Date
    Mar 2011
    Location
    Sweden
    Posts
    197
    Rep Power
    4

    Default Re: How to send imagebuffer over socket?

    Quote Originally Posted by JosAH View Post
    Send over the RGB data (just an int array) and the type of the BufferedImage and its dimensions (just three single ints) and construct a new BufferedImage on the other side.

    kind regards,

    Jos
    yeah, and those could be stored in a object and send it, instead of sending four objects.

    Java Code:
    public class BufferedImageInformation implements java.io.Serializable
    {
    	private static final long serialVersionUID = 1L;
    	private byte[] pixels;
    	private int height;
    	private int width;
    	private int type;
    
    	private BufferedImageInformation () {}
    
    	public static BufferedImageInformation  createInstance (BufferedImage image)
    	{
    		BufferedImageInformation  bii = new BufferedImageInformation ();
    		bii.pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
    		bii.height = image.getHeigth();
    		bii.width
    		...
    		//You get the rest
    	}
    
    	public static BufferedImage decode (BufferedImageInformation bii)
    	{
    		...
    		//Decode it into a BufferedImage
    	}
    }

Similar Threads

  1. How to send a file over socket?
    By ludo0777 in forum Networking
    Replies: 1
    Last Post: 06-06-2012, 05:53 PM
  2. How to send an object over a socket?
    By nousername in forum New To Java
    Replies: 3
    Last Post: 05-31-2011, 06:18 AM
  3. to send float array with TCP socket
    By zeyneqp in forum Networking
    Replies: 6
    Last Post: 08-30-2008, 03:48 AM
  4. Send an array via Socket
    By lene in forum Networking
    Replies: 0
    Last Post: 04-23-2008, 04:29 PM
  5. send files through socket
    By bbq in forum Advanced Java
    Replies: 1
    Last Post: 06-05-2007, 02:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •