Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to convert image into Hex 2 Dimensional Array?

Reply
Thread Tools

How to convert image into Hex 2 Dimensional Array?

 
 
Arne Vajhøj
Guest
Posts: n/a
 
      05-13-2013
On 5/11/2013 10:00 AM, lipska the kat wrote:
> On 11/05/13 13:50, Arne Vajhøj wrote:
>> On 5/11/2013 4:28 AM, lipska the kat wrote:
>>> On 08/05/13 19:54, Joshua Cranmer 🐧 wrote:
>>>> On 5/8/2013 12:40 PM, lipska the kat wrote:
>>>>> On 08/05/13 17:52, Joshua Cranmer 🐧 wrote:
>>>>>> On 5/8/2013 1:30 AM, sout saret wrote:
>>>>>>> Dear Community!
>>>>>>>
>>>>>>> May you help me how to write code in java to convert image to Hex 2
>>>>>>> dimensional array. I want to show format as below:
>>>>>>
>>>>>> What format is this two-dimensional array? Looking from your code,
>>>>>> you
>>>>>> appear to want it to be some sort of 256-byte pixel value, but are
>>>>>> you
>>>>>> desiring:
>>>>>> 1. 8-bit ARGB
>>>>>> 2. 5-6-5 RGB
>>>>>> 3. 8-bit grayscale
>>>>>> 4. 32-bit ARGB
>>>>>> 5. 24-bit RGB
>>>>>> 6. Binary version of any widely-used image format, including but not
>>>>>> limited to PNG, BMP, GIF, JPG, XBM, TIF, and ICO.
>>>>>
>>>>> I think he wants a byte for byte copy so the first byte gets copied
>>>>> into
>>>>> [0][0] the next into [1][0] the next [2][0] etc until [width-1][0]
>>>>> then start again at [0][1], [1][1], [2][1] etc etc
>>>>
>>>> A byte for byte copy of what? I'm guessing the answer is the "pixel
>>>> matrix", but that's underdefined since pixels can take on many
>>>> different
>>>> formats, which is what I was trying to get at--what encoding of a pixel
>>>> is desired?
>>>
>>> I've been thinking about this and actually, in a byte for byte copy
>>> the 'encoding' of a pixel is irrelevant.
>>>
>>> If I open a (for example) jpg image in a hex viewer(ghex) all I see is
>>> a bunch of bytes. As far as ghex is concerned that's all it is.
>>> The bunch of bytes is only an image if it is interpreted as an image by
>>> software that knows how to interpret the data *as an image*.
>>>
>>> So, as far as reading the data goes, all we have is a stream of bytes.
>>>
>>> If we want to store these bytes in a matrix(for whatever reason) we may
>>> have an immediate problem. It may be the case that the byte count is not
>>> a 'perfect square', what this means is that there may eventually be a
>>> number matrix cells that will not contain data that is relevant to the
>>> byte stream we are reading.
>>>
>>> So, how do we determine where in the matrix our data ends and the
>>> default values used to populate the arrays on creation begin?
>>>
>>> If we use byte[][] we have a problem.
>>> All byte values from 0x00 - 0xFF *could* be valid data,
>>> byte arrays have each cell initialized to 0 (0x00)
>>>
>>> Byte arrays however have each cell initialized to null.
>>>
>>> It will therefore be very easy to determine the end of data in a
>>> Byte[][] matrix. In a byte[][] matrix we would have to add some
>>> information somewhere outside of the matrix.
>>>
>>> This situation only really applies if we wish to store our bytes in a
>>> matrix. Obviously this is *not* a problem if we store the bytes in a
>>> single dimension array.
>>>
>>> So, I'm not so sure that the original advice was as bad as all that, it
>>> depends on the end usage of the stored data.
>>>
>>> As ever I'd be interested in any comments.

>>
>> Java 2D arrays are not necessarily square, so the second dimension
>> can be different for each element of the first dimension. So it
>> is also an option to use that instead of Byte[] with null fill
>> to end.

>
> Now *that's* interesting.
>
> I can't say I've done much with byte matrices or any other matrix for
> that matter, or come to that, arrays, I generally tend to use dynamic
> storage components, like LinkedList<> for example. this seems to compile.
>
> byte[][] bytes = new byte[2][];
> bytes[0] = new byte[10];
> bytes[1] = new byte[7];
>
> I didn't know you could do that.


Java only has this "array of array" or "jagged array".

The:

X[][] o = new X[m][n];

construct makes it looks different, but it is just syntactic sugar.

C# has both this type of array and a real 2D array (that is always
square).

Y[][] o = new Y[n][];
....

vs:

Y[,] o = new Y[n,m];

Arne


 
Reply With Quote
 
 
 
 
Arne Vajhj
Guest
Posts: n/a
 
      05-13-2013
On 5/11/2013 4:33 PM, Roedy Green wrote:
> On Tue, 7 May 2013 23:30:25 -0700 (PDT), sout saret
> <(E-Mail Removed)> wrote, quoted or indirectly quoted someone who
> said :
>
>> May you help me how to write code in java to convert image to Hex 2 dimensional array. I want to show format as below:

>
> I think your problem may be that you don't realize that internally the
> image will be a matrix of ints or shorts. The hexness comes when you
> display it or write it to text file.
>
> see http://mindprod.com/jgloss/hex.html


What does that have to do with the discussion??

Arne


 
Reply With Quote
 
 
 
 
markspace
Guest
Posts: n/a
 
      05-13-2013
On 5/12/2013 6:48 PM, Arne Vajhj wrote:
> On 5/11/2013 4:33 PM, Roedy Green wrote:
>> On Tue, 7 May 2013 23:30:25 -0700 (PDT), sout saret
>> <(E-Mail Removed)> wrote, quoted or indirectly quoted someone who
>> said :
>>
>>> May you help me how to write code in java to convert image to Hex 2
>>> dimensional array. I want to show format as below:

>>
>> I think your problem may be that you don't realize that internally the
>> image will be a matrix of ints or shorts. The hexness comes when you
>> display it or write it to text file.
>>
>> see http://mindprod.com/jgloss/hex.html

>
> What does that have to do with the discussion??



What discussion on cljp would be complete without random off-topic
interjaculations from Roedy?



 
Reply With Quote
 
Arne Vajhj
Guest
Posts: n/a
 
      05-13-2013
On 5/12/2013 11:49 PM, markspace wrote:
> On 5/12/2013 6:48 PM, Arne Vajhj wrote:
>> On 5/11/2013 4:33 PM, Roedy Green wrote:
>>> On Tue, 7 May 2013 23:30:25 -0700 (PDT), sout saret
>>> <(E-Mail Removed)> wrote, quoted or indirectly quoted someone who
>>> said :
>>>
>>>> May you help me how to write code in java to convert image to Hex 2
>>>> dimensional array. I want to show format as below:
>>>
>>> I think your problem may be that you don't realize that internally the
>>> image will be a matrix of ints or shorts. The hexness comes when you
>>> display it or write it to text file.
>>>
>>> see http://mindprod.com/jgloss/hex.html

>>
>> What does that have to do with the discussion??

>
>
> What discussion on cljp would be complete without random off-topic
> interjaculations from Roedy?


I guess you are right ....



Arne


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      05-15-2013
1On Sun, 12 May 2013 20:49:04 -0700, markspace
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone
who said :

>
>What discussion on cljp would be complete without random off-topic
>interjaculations from Roedy?


It may be off topic from what you have been saying, but it is
perfectly on topic looking at the original post. Because of topic
drift I generally do not read threads before posting, just the
original.
--
Roedy Green Canadian Mind Products http://mindprod.com
Nothing is so good as it seems beforehand.
~ George Eliot (born: 1819-11-22 died: 1880-12-22 at age: 61) (Mary Ann Evans)
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      05-15-2013
On Sun, 12 May 2013 20:49:04 -0700, markspace
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone
who said :

>
>What discussion on cljp would be complete without random off-topic
>interjaculations from Roedy?


You are beginning to sound like Lew. There are fewer and fewer people
participating simply because they don't want to deal with gratuitous
rudeness like that.
--
Roedy Green Canadian Mind Products http://mindprod.com
Nothing is so good as it seems beforehand.
~ George Eliot (born: 1819-11-22 died: 1880-12-22 at age: 61) (Mary Ann Evans)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
To convert a one dimensional array into a two dimensional array using C amrutha0303 Software 0 08-03-2010 10:02 PM
Hex Color Codes - Hex 6 <=> Hex 3 lucanos@gmail.com HTML 10 08-18-2005 11:21 PM
How to convert an hex string to a Hex number chirs Javascript 3 12-01-2003 10:06 PM
hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? Bengt Richter Python 6 08-19-2003 07:33 AM



Advertisments