Results 1 to 12 of 12
Thread: Converting image to hexadecimal
- 04-25-2012, 04:49 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
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.
- 04-25-2012, 07:11 AM #2
- 04-25-2012, 11:05 AM #3
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
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.
- 04-25-2012, 12:10 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 04-25-2012, 12:15 PM #5
- 04-25-2012, 12:17 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 04-25-2012, 02:53 PM #7
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
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.
- 04-25-2012, 03:12 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 04-25-2012, 04:03 PM #9
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
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?
- 04-25-2012, 04:16 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 04-25-2012, 04:18 PM #11
Re: Converting image to hexadecimal
That's not a valid statement. Also, go through BB Code List - Java Programming Forum
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-26-2012, 12:02 PM #12
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
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
-
Converting image to Point array
By Aster in forum Java 2DReplies: 1Last Post: 12-10-2011, 02:49 PM -
converting Image to File object !
By ron2794 in forum Advanced JavaReplies: 5Last Post: 07-15-2011, 06:59 PM -
Need conversion mechanism for converting 24 bit image to 16 bit
By jairainbow in forum New To JavaReplies: 2Last Post: 10-04-2010, 02:50 PM -
Converting Image to byte array[] ?
By afflictedd2 in forum CLDC and MIDPReplies: 0Last Post: 04-11-2009, 11:33 PM -
Converting multiple banded image into single banded image... Image enhancement
By archanajathan in forum Advanced JavaReplies: 0Last Post: 01-08-2008, 05:29 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks