位图步与4个字节的关系? [英] Bitmap Stride And 4 bytes Relation?
本文介绍了位图步与4个字节的关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请告诉我这是否句话是什么意思:
步幅属性,包含一行的字节宽度。行的大小,因为对于效率,该系统确保了数据被打包成开始的四字节边界和被填充到四个字节的多行然而未必是像素尺寸的整数倍。
块引用>解决方案步幅被填充。这意味着,它被向上舍入到的4最接近的倍数。
(假设8位灰度,或每像素8位):宽度|迈
--------------
1 | 4
2 | 4
3 | 4
4 | 4
5 | 8
6 | 8
7 | 8
8 | 8
9 | 12
10 | 12
11 | 12
12 | 12等。
在C#中,你可能会实现这个是这样的:
静态INT PaddedRowWidth(INT bitsPerPixel,诠释W,INT padToNBytes)
{
如果(padToNBytes == 0)
抛出新ArgumentOutOfRangeException(padToNBytes,垫值必须大于0);
INT padBits = 8 * padToNBytes;
返回((W * bitsPerPixel +(padBits-1))/ padBits)* padToNBytes;
}静态INT RowStride(INT bitsPerPixel,诠释宽度){返回PaddedRowWidth(bitsPerPixel,宽度4); }Whats does this sentence mean:
The Stride property, holds the width of one row in bytes. The size of a row however may not be an exact multiple of the pixel size because for efficiency, the system ensures that the data is packed into rows that begin on a four byte boundary and are padded out to a multiple of four bytes.
解决方案Stride is padded. That means that it gets rounded up to the nearest multiple of 4. (assuming 8 bit gray, or 8 bits per pixel):
Width | stride -------------- 1 | 4 2 | 4 3 | 4 4 | 4 5 | 8 6 | 8 7 | 8 8 | 8 9 | 12 10 | 12 11 | 12 12 | 12
etc.
In C#, you might implement this like this:
static int PaddedRowWidth(int bitsPerPixel, int w, int padToNBytes) { if (padToNBytes == 0) throw new ArgumentOutOfRangeException("padToNBytes", "pad value must be greater than 0."); int padBits = 8* padToNBytes; return ((w * bitsPerPixel + (padBits-1)) / padBits) * padToNBytes; } static int RowStride(int bitsPerPixel, int width) { return PaddedRowWidth(bitsPerPixel, width, 4); }
这篇关于位图步与4个字节的关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文