为什么图像用字节数组表示?

发布于 2024-10-09 17:09:45 字数 309 浏览 0 评论 0原文

我正在阅读 Scott Guthrie 博客,并且遇到了一个示例。您可以在 这里

它使用字节数组来表示该示例中的图片。我不知道为什么它用字节数组表示。我还记得一些文件在 .NET Framework 中也被处理为字节数组。

有人可以向我解释为什么字节数组而不是字符串,甚至是保存图片的类吗?

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 array instead of string or even a class which holds picture ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

掌心的温暖 2024-10-16 17:09:45

图像是二进制数据 - 这很容易表示为字节数组。

示例中的图像以 BLOB 形式存储在数据库中,而不是字符串或位置,也就是说,它是二进制数据。

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.

玻璃人 2024-10-16 17:09:45

字节集合是将图像文件表示为数据的最简单方法。字符串不适合,因为它包含字符代码,而图像文件不包含字符。没有特殊的类来保存图像文件的数据,因为字节数组就可以很好地工作。

任何文件都可以被视为字节的集合,因此字节数组是将文件作为二进制数据读取的结果。文件还可以解码为特定格式,例如生成字符串的文本文件,或生成 Bitmap 对象的压缩图像格式(JPEG、GIF、PNG 等)包含解压后的图像。

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.

夜深人未静 2024-10-16 17:09:45

将位图作为 RGB 值数组进行处理。担心每个像素,例如,每个值R、G和B都编码在一个字节中。您还可以有第四个值,即透明度。

使用颜色/透明度索引、像素的 x 坐标和图像宽度来获取 y 坐标处的像素...因此,人们可以以低廉的乘法和数组的价格快速访问整个图像运算符[]调用。

如今,在处理图像时,效率可能仍然是一个问题(对每个像素进行大量工作,这意味着图像内容上有大量循环)。

这可以解释图像仍然通过字节数组处理。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文