当前位置:编程学习 > VB >>

一个基础的问题 看你会不 呵

我用setpixelv或setpixel定义图像颜色,为什么结果都是一种颜色呢? 
代码如下: 
  先是api函数声明 
Private command1_click() 
dim m as long:dim r as integer:dim g as integer:dim b as integer 
  W=picture1.width 
  H=picture1.height 
  for i=1 to W  
    for  j=1 to H 
     m=picture1.point(i,j) 
     r = m And &HFF 
     g = (m And &HFF00&) \ &H100 
     b = (m And &HFF0000) \ &H10000 
     /*中间这是一段根椐r g b的范围重新设置r g b值的代码*/  
    picture1.currentX=i 
    picture1.currentY=j 
    setpixel picture1.hdc,picture1.currentX,picture1.currentY,_ 
     RGB(r,g,b) 
    next j 
  next i  --------------------编程问答--------------------
xiaoyongiloveyou (小勇,我爱你)你好,我真恨不得把我的昵称改成小勇。
你哪段代码需要加一句才能看出效果,因为你原来的代码基本上没有对图片颜色进行更改!
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long

Private Sub Command1_Click()
Dim m As Long, r As Integer, g As Integer, b As Integer
Dim W As Long, H As Long, i As Long, j As Long
  W = Picture1.ScaleWidth
  H = Picture1.ScaleHeight
  For i = 1 To W
    For j = 1 To H
     m = Picture1.Point(i, j)
     r = m And &HFF
     g = (m And &HFF00&) \ &H100
     b = (m And &HFF0000) \ &H10000
'     中间这是一段根椐r g b的范围重新设置r g b值的代码
    If g > 150 Then g = 150 '加这一句,才能看出效果
    Picture1.CurrentX = i
    Picture1.CurrentY = j
    SetPixel Picture1.hdc, Picture1.CurrentX, Picture1.CurrentY, RGB(r, g, b)
    Next j
  Next i

End Sub
--------------------编程问答--------------------      m = Picture1.Point(i, j) 
     r = m And &HFF 
     g = (m And &HFF00&) \ &H100 
     b = (m And &HFF0000) \ &H10000
结果还是 m=RGB(r, g, b)
什么都没做` --------------------编程问答--------------------      g = (m And &HFF00&) \ &H100  
     b = (m And &HFF0000) \ &H10000  
 改成     g = (m And &HFF00&) 
    b = (m And &HFF0000)   --------------------编程问答-------------------- 好像没那么简单,呵呵.
补充:VB ,  多媒体
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,