Results 1 to 4 of 4
  1. #1
    fiqueudrue's Avatar
    fiqueudrue is offline Member
    Join Date
    Dec 2008
    Location
    Singapore
    Posts
    55
    Rep Power
    0

    Default convert binary to images

    hey guys ..
    just need the code or courses or link that will teach or guide me for converting binary into images and show through the web site ....

    i manage to convert images to binary, right now i wan to retrieve the pictures ... so i assume i need to convert it back ..
    thanks
    VTEC may be long gone... but the power of MZR is coming...

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    what do you mean "convert image to binary", or the other way around. Images are binary, all data is, even text. You will need to show what you are actually doing. To show an image in a web page, you need simply to link to it, or, use the image tag to link to servlet that does nothing but set the proper content type and feed the read image to the outputstream.

  3. #3
    fiqueudrue's Avatar
    fiqueudrue is offline Member
    Join Date
    Dec 2008
    Location
    Singapore
    Posts
    55
    Rep Power
    0

    Default

    thanks for the reply ..

    currently, im doing a web service and a web service client.
    on the web service, i manage to convert an image from a file and make it in a binary form. i test the web service(not using client as yet) .... the result will be like this.

    Method returned

    java.awt.Image : "BufferedImage@18fa26: type = 0 ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1cef8be transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 128 height = 93 #numDataElements 3 dataOff[0] = 0"



    so on the web client ... i need to retrieve it back and display as a picture form..
    hmmm sorry but i think u can get plus minus wat i trying to say here .. haha
    VTEC may be long gone... but the power of MZR is coming...

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    From what I can glean from that post, you are not "converting" anything, you are simply loading an Image, but, if it is an image that is to be displayed in a web page, that is completely unnecessary.

    As a simple example
    Java Code:
    package image;
    
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class ImageServlet extends HttpServlet {
    
    	@Override
    	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    			throws ServletException, IOException {
    		String imageName = req.getParameter("Name");
    		FileInputStream fis = new FileInputStream(imageName);
    		byte[] buffer = new byte[8192];
    		resp.setContentType("image/jpeg");
    		OutputStream os = resp.getOutputStream();
    		try {
    			int read = 0;
    			while ((read = fis.read(buffer, 0, buffer.length)) != -1) {
    				os.write(buffer, 0, read);
    				os.flush();
    			}
    		} finally {
    			try { os.close(); } catch (Exception e) {}
    			try { fis.close(); } catch (Exception e) {}
    		}
    	}
    }
    and called in the image tag
    <IMG SRC="http://server/mapping/to/servlet?Name=/path/to/image">

Similar Threads

  1. Convert decimal to binary..pls help..newbie here
    By mephisto772 in forum New To Java
    Replies: 5
    Last Post: 02-12-2009, 08:17 AM
  2. convert a java binary/executable to a intermediate language
    By sumit_400461 in forum Advanced Java
    Replies: 1
    Last Post: 07-13-2008, 07:04 PM
  3. get binary value
    By rushenas in forum New To Java
    Replies: 2
    Last Post: 06-14-2008, 01:51 PM
  4. Use recursion to convert binary to...
    By coco in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 07:46 AM
  5. convert a lot of images into a single one
    By leonard in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 04:47 PM

Posting Permissions

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