Results 1 to 12 of 12
  1. #1
    abdique63 is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Converting image to hexadecimal

    Hi everyone.

    I am on the middle of a project requiring sending of data from computer (created a GUI using java) to a microcontroller (to be displayed on an LCD) wirelessly using Wi-Fi. I have been successful in sending textual data but want to move one step ahead by sending images (this time I will b using a graphical lcd 48 by 84 display). The problem is that the graphic lcd displays the image when it is in the form of an array (hexadecimal values - an example for this is shown below). So I thought of converting the image before sending it to the microcontroller.

    I want to update the same GUI i used to send the textual data to be able to accept the image file then convert before sending. Since the maximum display size is 48 by 64 and can only display black and white images therefore i have to place a restriction where the accepted file should be in bmp file format before loading it to the GUI. My knowledge on image processing is very limited and I was hoping to get some ideas over here on how to solve this problem.

    Here is the array;

    unsigned char DFrobot_bmp[]=

    {
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x01,0x01, 0x39,0x39,0x39,0x39,0x39,0x39,
    0x01,0x01,0xFF,0xFF,0x01,0x01,0xC9,0xC9,0xC9,0xC9, 0xC9,0xC9,0xFF,0xFF,0xFF,0xFF,
    0xFF,0x19,0x19,0x19,0x19,0xFF,0xE6,0x00,0x7C,0xFE, 0xFF,0xFF,0x83,0x01,0x01,0x01,
    0x83,0xC6,0x7C,0x00,0x00,0xFF,0xFF,0xFF,0x19,0x19, 0x19,0x99,0xFF,0xFE,0x00,0x38,
    0xFE,0xFF,0xFF,0xC3,0x81,0x01,0x01,0x83,0x87,0xFE, 0x3C,0x00,0x01,0x01,0xFF,0xFF,
    0xFF,0xFF,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00, 0x00,0x03,0x02,0x02,0x02,0x02,
    0x02,0x02,0x02,0x02,0x02,0x03,0x03,0x03,0x02,0x02, 0x03,0x03,0x03,0x03,0x03,0x03,
    0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x01, 0x01,0x00,0x00,0x00,0x01,0x01,
    0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00, 0x01,0x01,0x01,0x01,0x01,0x01,
    0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01, 0x01,0x01,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00, 0x00,0x00
    };


    Thanks.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,239
    Rep Power
    19

    Default Re: Converting image to hexadecimal

    Quote Originally Posted by abdique63 View Post
    Here is the array;

    unsigned char DFrobot_bmp[]=
    That's not Java. You're in the wrong forum.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    abdique63 is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: Converting image to hexadecimal

    I get your point but the array displayed above is the one used at the other end of the system ( micro-controller side) to display the image. I want to create a similar one with java type value but contain same values (hexadecimal) by converting the bmp format image before sending it across the network.
    Last edited by abdique63; 04-25-2012 at 11:08 AM.

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,013
    Rep Power
    20

    Default Re: Converting image to hexadecimal

    You want a byte[] then.
    Read the image in using a standard BufferedInputStream, then simply send that to your LCD in whatever way it expects for an image.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,239
    Rep Power
    19

    Default Re: Converting image to hexadecimal

    Quote Originally Posted by abdique63 View Post
    ... but contain same values (hexadecimal) ...
    Numerid values are just values. String representations of numeric values may be binary, decimal, hexadecimal, octal etc.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,013
    Rep Power
    20

    Default Re: Converting image to hexadecimal

    As a note, since I just thought of it, simply create a byte[] like the above char[] using those values and try and send that.
    Forget about reading in from a file until you get that working.
    Note that since byte is signed you'll probably have to cast some of the above.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    abdique63 is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: Converting image to hexadecimal

    Thanks Tolls,

    This is what I have done so far after perusing through the Java API (image part)

    private byte loadImage(File source);
    {
    ImageInputStream in = new FileImageInputStream(source);
    in.readFully(b); // Reads b.length bytes from the stream, and stores them into b starting at index 0
    return b;
    }

    private void SendButtonActionPerformed(java.awt.event.ActionEve nt evt) {

    byte b;
    File f = new File("myImage.bmp");
    b = loadImage(f);
    try {

    TCPClient cl = new TCPClient("WiFly-GSX", 2000);
    cl.sendMessage(b);

    System.out.println("Message sent"); // for debugging purpose
    }
    catch (UnknownHostException e) {
    System.err.println("Don't know about host: WiFly-GSX");
    //System.exit(1);

    }
    }

    I don't have the LCD with me right now, so I will get back to you on the sending part later on.

    Thanks.

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,013
    Rep Power
    20

    Default Re: Converting image to hexadecimal

    All that you've written there seems to involve a single byte.
    No arrays.
    And I doubt it'll compile.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    abdique63 is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: Converting image to hexadecimal

    Sorry for that, I forgot to declare the array, here it is
    byte b [1024];

    Apart from this, how do you read the image into the byte array?

  10. #10
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,013
    Rep Power
    20

    Default Re: Converting image to hexadecimal

    You don't know how big it is, so that's the first thing.
    Unless you know your image is only 1k.
    You might need to get the File first, then use the length() method to get the number of bytes.
    From that you can create a suitably sized byte[], then do the readFully().
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,239
    Rep Power
    19

    Default Re: Converting image to hexadecimal

    Quote Originally Posted by abdique63 View Post
    Sorry for that, I forgot to declare the array, here it is
    byte b [1024];
    That's not a valid statement. Also, go through BB Code List - Java Programming Forum

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  12. #12
    abdique63 is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: Converting image to hexadecimal

    I know there is something wrong with the code but was just checking if the logic was correct. I need to go through primitive type declarations like the one I used above. What's the above link for?

    I tested the sending part without caring about the converting the image first. I just created an array of bytes containing the values of the DFrobot_bmp and sent it across the network and there was no problem. I stored the received values back to char DFrobot_bmp[] and used it to print out the image on the LCD. Now have to work on the first part.

    Thanks.
    Last edited by abdique63; 04-26-2012 at 12:30 PM.

Similar Threads

  1. Converting image to Point array
    By Aster in forum Java 2D
    Replies: 1
    Last Post: 12-10-2011, 02:49 PM
  2. converting Image to File object !
    By ron2794 in forum Advanced Java
    Replies: 5
    Last Post: 07-15-2011, 06:59 PM
  3. Replies: 2
    Last Post: 10-04-2010, 02:50 PM
  4. Converting Image to byte array[] ?
    By afflictedd2 in forum CLDC and MIDP
    Replies: 0
    Last Post: 04-11-2009, 11:33 PM
  5. Replies: 0
    Last Post: 01-08-2008, 05:29 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
  •