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.
Re: Converting image to hexadecimal
Quote:
Originally Posted by
abdique63
Here is the array;
unsigned char DFrobot_bmp[]=
That's not Java. You're in the wrong forum.
db
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.
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.
Re: Converting image to hexadecimal
Quote:
Originally Posted by
abdique63
... but contain same values (hexadecimal) ...
Numerid values are just values. String representations of numeric values may be binary, decimal, hexadecimal, octal etc.
db
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.
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.
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.
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?
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().
Re: Converting image to hexadecimal
Quote:
Originally Posted by
abdique63
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
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.