您的位置首页生活百科

编程VB实现BMP图象RBG分量的显示

编程VB实现BMP图象RBG分量的显示

的有关信息介绍如下:

编程VB实现BMP图象RBG分量的显示

BMP图像从第55字节开始存储颜色信息。。并且顺序是从图片的右下角始往左上角依次存储。。位深为24的BMP图像每像素占三个字节。。依次为RGB。。用二进制的方式打开BMP图像。。定义以个三个字节的数组读入。。然后换算成十进制即可。。 不同位深的BMP图像颜色信息存储方式不同。。并且每行的颜色数据可能最后几位没有用(BMP图像每行字节数必须是四的倍数,因此可能在每行末补了1-3字节)。。你自己去查点BMP图像存储格式的资料看吧 如果你是把BMP图像显示到PictureBox控件中,然后用鼠标来获取某点的颜色分量就好办得多。。 在窗体上画一个Picture1和一个Cmmand1 Private Sub Command1_Click() Dim Color As Long Dim R As Integer Dim G As Integer Dim B As Integer Picture1.BackColor = RGB(200, 130, 50) Color = Picture1.Point(20, 20) B = Int(Color / 65536) G = Int((Color Mod 65536) / 256) R = Int(Color Mod 256) Print R Print G Print B End Sub 如此如此便OK了。。。Point方法取得指定坐标点的颜色值,返回一个长整数 ------------------------------------------------------------------- 求24位BMP硬盘图(X,Y)点颜色分量Private Sub Command3_Click() Dim BMPWidth As Long Dim BMPHeight As Long Dim LineWidth As Long Dim ArrByte(0 To 3) As Byte Dim R As Integer Dim G As Integer Dim B As Integer Open "D:\111.bmp" For Binary As #1 Get #1, 19, ArrByte BMPWidth = ArrByte(3) * 256 ^ 3 + ArrByte(2) * 256 ^ 2 + ArrByte(1) * 256 + ArrByte(0) Get #1, 23, ArrByte BMPHeight = ArrByte(3) * 256 ^ 3 + ArrByte(2) * 256 ^ 2 + ArrByte(1) * 256 + ArrByte(0) 'BMP图要求每行字节数为4的倍数,不够则填充1-3个无用字节 Select Case (BMPWidth * 3) Mod 4 Case 0 LineWidth = BMPWidth * 3 Case 1 LineWidth = BMPWidth * 3 + 3 Case 2 LineWidth = BMPWidth * 3 + 2 Case 3 LineWidth = BMPWidth * 3 + 1 End Select '此为求 (0,0)点颜色分量 Get #1, FindByte(LineWidth, BMPHeight, 0, 0), ArrByte R = ArrByte(2) G = ArrByte(1) B = ArrByte(0) Print R; G; B Close #1 End Sub Private Function FindByte(ByVal LineWidth As Long, ByVal LineCount As Long, ByVal X As Long, ByVal Y As Long) As Long FindByte = 55 + (LineCount - Y - 1) * LineWidth + 3 * X End Function ----------------------------------这下齐了 大哥怎么还不处理!