开发者

Why Images are represented by byte array?

开发者 https://www.devze.com 2023-02-02 06:39 出处:网络
I was reading Scott Guthrie blog and i have encounter a sample. You can find it in Here It is used byte array for represent Picture in that sample. I have no idea why it is represented by byte array.

I was reading Scott Guthrie blog and i have encounter a sample. You can find it in Here

It is used byte array for represent Picture in that sample. I have no idea why it is represented by byte array. I also remember that some of files are processed as byte array in .NET Framework too.

Can someone explain to me why byte 开发者_如何学JAVAarray instead of string or even a class which holds picture ?


Images are binary data - this is easily represented as byte arrays.

The image in the sample is stored in the database as a BLOB - not a string or location, that is, it is binary data.


A collection of bytes is the simplest way to represent an image file as data. A string would not be suitable as it contains character codes, and an image file does not consist of characters. There is no special class for holding the data of an image file, as a byte array works just fine for that.

Any file can be treated as a collection of bytes, so a byte array is the result of reading a file as binary data. A file can also be decoded as a specific format, like a text file which results in a string, or a compressed image format (JPEG, GIF, PNG et.c.) which results in a Bitmap object containing the decompressed image.


One handles a bitmap as an array of RGB value. Fear each pixel, for example, each value R, G and B is coded in one byte. You could also have a fourth value which is transparency.

Playing with the colour/transparency index, the x coordinate of the pixel, and the image width for the getting the pixels at y coordinate... thus one has quick access to the whole image, at the cheap price of some multiplication and a array operator[] call.

Nowadays, efficiency may still be an issue when dealing with images (lots and lots of working on each and every pixel, which means lots and lots of loops all over the content of the image ).

That could explain that images are still handled through arrays of bytes.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号