谢谢
还有pixel下
读出来的图象width和height比实际的多4啊
为什么呢?

解决方案 »

  1.   

    你是不是看了picturebox的width属性?把它的边框也算了进去
    把border去掉
    或者算scalewidth看看行不行
      

  2.   

    需要把PICTUREBOX的边框去掉
    picture1.apearnce=0      '设为平板样式
    picture1.borderstyle=0   '设为无边框样式
    picture1.sclaemode=3     '单位设为像素
      

  3.   

    不知你是不是这个意思:
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim color As Long
    color = Picture1.Point(X, Y)
    Picture1.ToolTipText = "color=" & color & ": red = " & color Mod 256 & ", green = " & ((color And &HFF00) / 256) Mod 256 & ", blue = " & (color And &HFF0000) / 65536
    End Sub
      

  4.   

    代码如下:
    Dim Color as long
    Dim Red as long
    Dim Green as Long
    Dim Blue as long
    Color =Picture1.Point(X, Y)  'X,Y坐标任意,只要在PICTUREBOX范围内
    Red = Color and &HFF&
    Greed = (Color\256) and &HFF&
    Blue =Color\65536顺便改成楼上的样子:
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim Color as long
    Color =Picture1.Point(X, Y) '得到鼠标在picture控件上的X,Y坐标处颜色
    picture1.tooltips="RED: " & (Color and &HFF) & ",Green:" & ((Color\256) and &HFF) & ",Blue:" & (Color\65536)
    End Sub
    使用了整除法,速度稍快一点点。
      

  5.   

    //怎么获取某个象素点的象素值呢? Point 方法
          按照长整数,返回在 Form 或 PictureBox 上所指定磅的红-绿-蓝 (RGB) 颜色。不支持命名参数。语法object.Point(x, y)Point 方法的语法包含下列部分:部分 描述 
    object 可选的。一个对象表达式,其值为“应用于”列表中的一个对象。如果省略 object,带有焦点的 Form 象缺省为 object. 
    x, y 必需的。均为单精度值,指示 Form 或 PictureBox 的 ScaleMode 属性中该点的水平(x-轴)和垂直(y-轴)坐标。必须用括号包括这些值。 
    //读出来的图象width和height比实际的多4啊
    //为什么呢?picturebox的width和height是控件本身的宽和高,而不是图像的宽和高
    如果你没有使用自定义坐标,在AutoRedraw设为True的前提下,可以用ScaleWidth和ScaleHeight取得图像的宽和高
      

  6.   

    Visual Basic 对于定义色彩有二种方法:1、使用定义的常数:如色彩属性的设定为红色,可以常数 vbRed 表示2、直接使用色彩设定:以十六进位数来指定色彩,方式为: &HBBGGRR&BB是指定蓝色的部分,GG是指绿色,RR则为指定红色。每个部分都是两位从 00 到 FF 的十六进位数。中间值为 80。因此,以下的数值将指定灰色,它属于三种色彩的中间部分:&H808080&上述二种色彩表示方式对应如下:色彩常数 值 中文描述 英文描述 色块样板 vbRed &H0000FF& 红色 Red vbGreen &H00FF00& 绿色 Green vbBlue &HFF0000& 蓝色 Blue vbBlack &H000000& 黑色 Black   vbYellow &H00FFFF& 黄色 (红+绿) Yellow vbMagenta &HFF00FF& 洋红色 (红+蓝) Magenta Cyan &HFFFF00& 青绿色 (绿+蓝) Cyan vbWhite &HFFFFFF& 白色 White 上述第 2 种方法,可以衍生出『若知道一值,则如何反算其红、绿、蓝颜色值各为何?』的问题。其计算方法则是反其道而行,计算顺序为首先计算蓝色值、其次为绿色值、最后为红色值。写成模块如下:Private Sub ReturnRGB(ByVal lngColor As Long, intRed As Integer, intGreen As Integer, intBlue As Integer)intRed = lngColor Mod 256intGreen = (lngColor \ 256) Mod 256intBlue = lngColor \ 256 \ 256End Sub 
      

  7.   

    Platform SDK: Windows GDI 
    GetPixel
    The GetPixel function retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates. COLORREF GetPixel(
      HDC hdc,    // handle to DC
      int nXPos,  // x-coordinate of pixel
      int nYPos   // y-coordinate of pixel
    );
    Parameters
    hdc 
    [in] Handle to the device context. 
    nXPos 
    [in] Specifies the logical x-coordinate of the pixel to be examined. 
    nYPos 
    [in] Specifies the logical y-coordinate of the pixel to be examined. 
    Return Values
    The return value is the RGB value of the pixel. If the pixel is outside of the current clipping region, the return value is CLR_INVALID. Res
    The pixel must be within the boundaries of the current clipping region. Not all devices support GetPixel. An application should call GetDeviceCaps to determine whether a specified device supports this function. Requirements 
      Windows NT/2000 or later: Requires Windows NT 3.1 or later.
      Windows 95/98/Me: Requires Windows 95 or later.
      Header: Declared in Wingdi.h; include Windows.h.
      Library: Use Gdi32.lib.