![]() |
| ||
| How get Image byte size & transfer Image over Socket? I am trying to transmit an Image object through a Socket connection in Java. The only thing I may be missing is how to get an image size in bytes so I know how many bytes are being transferred over the Socket. I have the ServerSocket and Client working transferring data, and I have a cut-paste image working from a client Applet, and I have a Java program that saves Images to disk as JPEG/PNG. How do you get the byte size of an Image object in Java?... or do you know of source code to a program that transferes images through Sockets? Thanks, Jon |
| ||
| Re: How get Image byte size & transfer Image over Socket? ı couldn't understand why you wanna get image byte size. as a result images are also files. so you can trnsfer you images as a byte streams. just read image file with an inputstream and write it to socket outputstream. InputStream input=new FileInputStream("image.png"); byte[] buffer=new byte[1024]; int readData; while((readData=input.read(buffer))!=-1){ socketOutput.write(buffer,0,readData); } |
| ||
| Re: How get Image byte size & transfer Image over Socket? I cant read from a file stream, because the client application is an Applet (browser applet) in this client/server image transrfer program. You can't access files from an Applet in Java. I can paste an Image into the Applet and cast it to a BufferedImage object, but I don't know how to send the BufferedImage object over a Socket. I need the size of the BufferedImage object so I can notify the server Java application of how many bytes it is to expect on the receiving end. Jon |
| ||
| Re: How get Image byte size & transfer Image over Socket? I've had the same problem as you, and finally my solution was the next one: BufferedImage bIResult = null; // Fill your bufferedImage ByteArrayOutputStream bos = new ByteArrayOutputStream(); boolean resultWrite = ImageIO.write(bIResult, "PNG", bos); byte[] imageInBytes = bos.toByteArray(); int length = imageInBytes.length; Sincerily, Isabel |
| ||
| Re: How get Image byte size & transfer Image over Socket? In client applet i have a code import java.applet.*; I dont know how to get the image data in server side( servlet) and store as jpg pr png file. please help me regarding this. i need server side code. Thanks in advance for helping me |
| ||
| Re: How get Image byte size & transfer Image over Socket? anyone is available to help me:( |
| ||
| Re: How get Image byte size & transfer Image over Socket? Why don't you Google "Java File Upload" and send a normal file upload requesst. |
| ||
| Re: How get Image byte size & transfer Image over Socket? In client side I couldnt have image file. Only I have Byte Array. I need to send to server( servlet) then i ll store it to jpeg file. I tried the servlet code like this InputStream in = req.getInputStream(); But i didnt find any file name as new.jpg in my server. Please help me |
| ||
| Re: How get Image byte size & transfer Image over Socket? Do what I suggested in the post. On a fileupload the server gets an inputstream. How that inputstream originates doesn't matter. Investigate "File Upload" streams. Both how to receive one in a Servlet, and how to initiate one using an HttpUrlConnection, and your problem is solved. |
| ||
| Re: How get Image byte size & transfer Image over Socket? Thanks for ur reply. I am new java and servlet. If u know abt how to store image into server. Please help me. thanks |
| All times are GMT -4. The time now is 10:46 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC