【问题标题】:Where are the RGB values stored in this array?这个数组中存储的 RGB 值在哪里?
【发布时间】:2012-05-31 18:47:00
【问题描述】:

我一直在创建的控件中使用以下子控件,以便更快地修改位图中的像素:

    Protected Sub LockForMemory()
        idata = ime.LockBits(New Rectangle(0, 0, ime.Width, ime.Height), ImageLockMode.WriteOnly, ime.PixelFormat)
        ipoint = idata.Scan0

        ibytes = Math.Abs(idata.Stride) * ime.Height
        ReDim irgbvalues(ibytes - 1)
        System.Runtime.InteropServices.Marshal.Copy(ipoint, irgbvalues, 0, ibytes)
    End Sub

所有这些都有效,稍后当我在操作后检索实际图像时,它也可以正常工作。问题在于设置这些实际像素。

这个数组是什么?我知道它充满了Integers,但每个指数代表什么?一开始我以为是这样设置的:

数组-> [像素 0,0 的 R][像素 0,0 的 G][像素 0,0 的 B][像素 2,0 的 R][像素 2 的 G, 0][B of Pixel 2,0]

然而,这似乎并不正确。

【问题讨论】:

    标签: vb.net arrays rgb lockbits


    【解决方案1】:

    这取决于 ime.PixelFormat 的值。每个像素可以表示为 RGB、ARGB、调色板查找索引等。

    http://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat.aspx

    另外,您需要注意字节顺序。字节可能采用 little-endian 字节顺序,但这取决于您的目标平台。

    对于 Format32bppArgb,这可能会对格式有所帮助:

    PixelFormat.Format32bppArgb seems to have wrong byte order

    【讨论】:

    • 于是,我查看了一下,发现是Format32bppArgb像素格式。有了这些信息,您能否为我详细说明一下这个主题?
    • 哦,好的。现在这是有道理的。谢谢您的帮助! +1 和支票给你!
    猜你喜欢
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    • 1970-01-01
    • 2010-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多