• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 932
  • Last Modified:

byte array from image source

Hi..

When executing this code in debig mode, im looking on the byte array:
byte[] inputBuffer = File.ReadAllBytes("c:\\env\\bla.jpg");

[0] 255
[1] 216
[2] 255
[3] 224
[4] 0
&
&
&
In ASCII stream is obvious: each byte represent character, but what happened with image? It should contain binary data. No?
10x
0
eladr
Asked:
eladr
1 Solution
 
imladrisCommented:
In what way are you figuring that this isn't binary data?

Everything is stored in bits. Meaning is in the eye of the beholder. The first four values you have there would be represented in hex as:

0xff 0xd8 0xff 0xe0 0x00

The first byte could represent a character (though it is blank in standard PC extended ASCII), it could represent the value 255, if it is a one byte signed value it would be -1, it could be the first byte in the four byte value 0xffd8ffe0 (which is -255936), it could be just a bunch of 1 bits (flags for something or other), or it could be part of an image. If it were a black and white image, 0xff might represent 8 pixels in a row all being on, the fourth byte would be 8 pixels off.

Images are usually in colour these days which means that each pixel needs more than one bit to represent it in a bitmap. A jpg is additionally compressed to one degree or another. So the first bytes are probably a header of some sort, and the subsequent bytes are compressed image data.

So, looking at a series of byte values, there is no definitive way to determine what they represent. The meaning is something that is imposed on it.
0
 
photowhizCommented:
imladris is right in general, but if you know that "bls.jpg" is indeed a JPEG file, then the bytes should be interpreted as JPEG; you can find a copy of the file spec at http://www.digicamsoft.com/itu/itu-t81-1.html.

Note that JPEG is a very complex format; if you are trying to do image manipulation on a JPEG file you would be much be much better off rendering it to a graphics buffer and doing your manipulation on the buffer.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now