Results 1 to 5 of 5
  1. #1
    nupurashi is offline Member
    Join Date
    Jan 2009
    Posts
    5
    Rep Power
    0

    Default converting image to binary code n vice versa

    hello
    please help me out
    i am getting the bit stream from a device n want to convert the binary data to the image file

    if some one can tell me hw to convert the image to binary
    plz help me

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Use javax.imageio.ImageIO to read/write images. To create an image from raw data, first create a java.awt.image.BufferedImage of the desired size, then call it's getRaster method to get a WritableRaster. Then call one of the setPixels methods on the WritableRaster with your data. Now you can persist the BufferedImage to a jpeg, or png, or whatever using ImageIO.

    There are other ways to do it as well, but this is probably the easiest.

  3. #3
    nupurashi is offline Member
    Join Date
    Jan 2009
    Posts
    5
    Rep Power
    0

    Default

    hello
    thanks 4 reply
    plz if u can mail me the simple code to do the same
    and i have the byte stream coming from a hardware device and the byte stream are as following


    0B01010101
    0B00000000
    0B00000000
    0B00000000
    0B00000000
    0B00000000
    0B00000000
    0B00000000
    0B00000000
    upto 65 times
    then again
    0B01010101
    again 65 readings
    when any change then
    0B00000100

    now to explain
    0B01010101 ------ marks starting of one frame
    we have 65 readings in a frame
    0B ---is header
    now each 0 stands for a section of frame
    0 stands for black and 1 stands for white

    now the problem is convert it into an image

    plz help me out

  4. #4
    geminius is offline Member
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Default converting a colored image to a binary image

    hello,
    i am an engineering student
    I need to convert the colored image to its binary image so as to apply Euclidean distance transform on the binary image...
    i would be grateful if someone could tell me the code for conversion of a colored image to binary image.

  5. #5
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Germinius - Please don't hijack other people's threads. You probably want to take the average of the RGB values and apply a simple threshold (127 for example).

    Nupurashi - If there are only 3 options then just detect which one it is and show whichever image you want. Otherwise, create a binary format BufferedImage of the correct size (8x8) and draw directly onto it, or cut off the 01010101 header and pass the trimmed array to the BufferedImage constructor.

Similar Threads

  1. Replies: 5
    Last Post: 10-04-2008, 12:13 PM
  2. Converting to ASCII and vice-versa
    By pheonix in forum New To Java
    Replies: 2
    Last Post: 09-09-2008, 05:43 AM
  3. Replies: 0
    Last Post: 04-07-2008, 08:44 AM
  4. Replies: 0
    Last Post: 01-08-2008, 06:29 PM
  5. Document conversion PDF to MS doc and vice versa
    By abintoms in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 01:45 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
  •