byte array from image source

Posted on 2007-07-25
Last Modified: 2008-01-09

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?
Question by:eladr
    LVL 16

    Accepted Solution

    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.
    LVL 7

    Expert Comment

    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

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now