private Sub Command1_click() 
    Dim color As Long  
    Dim r As Integer :Dim g As Integer:Dim b As Integer 
    Dim r1 As Integer :Dim g1 As Integer:Dim b1 As Integer 
    Dim times As Long 
    times = 1  
    Picture1.AutoRedraw = True 
    Picture1.ScaleMode = 3 
    W= Picture1.ScaleWidth 
    H = Picture1.ScaleHeight 
    For i = 0 To W     
      For j = 0 To H
        times = times + 1  '每执行一次循环自动加1 
        color = Picture1.Point(i, j) 
           '分别获得指定点的r、g、b的分量值 
         r = color And &HFF 
        g = (color And 62580) / 256 
        b = (color And &HFF0000) / 65536 
        If times Mod 2 = 0 Then  'times mod 2为0表第示一色块 
               r1 = r 
               g1 = g 
               b1 = b 
               Picture1.CurrentX = i 
               Picture1.CurrentY = j 
              SetPixelV Picture1.hdc,Picture1.CurrentX,Picture1.CurrentY, RGB(r1,g1,b1)              
        ElseIf times Mod 2 <> 0 Then ' 表明为第二色块 
                 Picture1.CurrentX = i 
               Picture1.CurrentY = j 
               SetPixelV Picture1.hdc,Picture1.CurrentX,Picture1.CurrentY, RGB(r1, g1, b1) 
                         
        End If 
      Next j 
    Next i 
End Sub    我的目的就是使相邻两个色块(图片放大之后成色块)的颜色一样,以两色块之间的前一色块的颜色为准.(例第2个色块和第一个色块颜色一样,第4个色块与第三个色块颜色一样...)大家理解我的代码了吗,原图地址为为:http://images13.51.com/47/a/27/8c/adgj1314/1193813807_0.99812700.jpg        
     但我点击按钮之后图像好像没什么反应 达不到我要的效果! 

解决方案 »

  1.   

    有反应才怪了。你从Picture1中取了像素点的颜色,然后又原样贴回Picture1中,不知道你在干嘛。
      

  2.   

    一楼说得没错。你
    SetPixelV   Picture1.hdc,Picture1.CurrentX,Picture1.CurrentY,   RGB(r1,g1,b1)          
    这一句都一样的,我知道你的意思,但是你i和j又变了以后,这样写就不是以前一块为准了,还是以取的自己为准。可以设个临时变量存下上一色块的值赋进去。
      

  3.   

     楼上的  
     我每执行一次循环一次i,j的位置都不同的啊
       times mod 2为0时表明为前一色块 此时位于i,j位置的像素点的颜色为原(r,g,b)
       times mod 2不为0时表明为后一色块 此时位于i,j位置的像素点的颜色为前一色块所保存的(r1,g1,b1)
      是不 
      我觉得我的代码没有什么错误啊
      

  4.   

    Option Explicit
    Private Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As LongPrivate Sub Command1_click()
            Dim color     As Long
            Dim r     As Integer: Dim g         As Integer: Dim b      As Integer
            Dim r1     As Integer: Dim g1         As Integer: Dim b1      As Integer
            Dim times     As Long
            Dim w As Long, h As Long, i As Long, j As Long
            times = 1
            Picture1.AutoRedraw = True
            Picture1.ScaleMode = 3
            w = Picture1.ScaleWidth
            h = Picture1.ScaleHeight
            For i = 0 To w Step 2
                For j = 0 To h
                    color = Picture1.Point(i, j)
                    SetPixelV Picture1.hdc, i + 1, j, color
                Next j
            Next i
    End Sub
      

  5.   

    整理下
    去掉多余的变量声明 和减短多余的循环长度
    Option ExplicitPrivate Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As LongPrivate Sub Command1_click()
      Dim color As Long
      Dim w As Long, h As Long, i As Long, j As Long
      
      With Picture1
        .AutoRedraw = True
        .ScaleMode = 3
        w = .ScaleWidth - 1 - (.ScaleWidth Mod 2)
        h = .ScaleHeight - 1
        For i = 0 To w Step 2
          For j = 0 To h
            color = .Point(i, j)
            SetPixelV .hdc, i + 1, j, color
          Next j
        Next i
      End With
    End Sub
      

  6.   

    我现在把代码优化了一下
     但还是不变的啊
        Dim color  As Long
        Dim color1 As Long
        Dim r As Integer: Dim g As Integer: Dim b As Integer
        Picture2.ScaleMode = 3
        Picture2.AutoRedraw =true
        W1 = Picture2.ScaleWidth
        H1 = Picture2.ScaleHeight
        For i = 0 To W1
            For j = 0 To H1 Step 2
                color = Picture2.Point(i, j)
                Picture2.CurrentX = i
                Picture2.CurrentY = j + 1
                SetPixelV Picture2.hdc, Picture2.CurrentX, Picture2.CurrentY, color
            Next j
        Next i
      
     怎么办啊 都急得想跳楼了
     哎```
      

  7.   

    picture1?
    picture2?
    我测试是可以改变相应像素颜色的
      

  8.   

      ayalicer 
      感谢你一直以来的关注!
       我所说的优化代码只是错把picture1写成picture2 我觉得这段优化的代码理论上可以实现 但为什么就是实现不了呢
      你说的测试可以改变相应像素颜色
       是用上面两段代码吗 我都试过了没用的
        如果真的实现了把代码贴出来好不 Thanks. 我都快崩溃了
      

  9.   

      5楼和6楼的我都试过了
     没改变啊 
      郁闷  这个问题困扰我几天了 原图地址:
       http://images13.51.com/47/a/27/8c/adgj1314/1193813807_0.99812700.jpg
      

  10.   

    要不你把你的代码发给我邮件中吧 我看看有什么错漏的地方
    [email protected]
      

  11.   

        ayalicer 邮件已发送
        请注意查收.谢谢
      

  12.   

    我意思要你的整个相关的工程,不是光代码 *.frm *.vbp ...之类的 你用winrar打包 发给我
    代码你网页中我都看过了但是你邮件中描述的 好像是放大图像(放大为X*3 Y*2) 并不只是修正像素颜色
      

  13.   

    ayalicer 
        第二封邮件已发出 请查收
       谢谢
       在这也谢谢关注此贴的大侠们.你们都是好样的
          
       
       
      

  14.   

    首先你要知道
    scalemode 只是1个度量单位或者方法
    改变 scalemode 并不会改变 图像的大小
    所以在我看来 你很可能是在其他地方有错漏 
      

  15.   

       ayalicer 不会吧 搞了这么久你还不懂我的需求啊 
         你看二楼就懂我的意思
          没关系 我再说一下:原图是不是由好多色块组成是不(放大之后的效果),我就是以循环的方式使相邻两个色块的颜色一样,两个色块之间以第一个色块的颜色为准。
         其他地方有错漏,不会吧,我找了这么久都没找出来. 
       
         
      

  16.   

    如果只是放大 直接用 picture1.paintpicture 指定放大后的图像大小 就可以了 何必1个1个像素去处理.
      

  17.   

    比如说把原图放大 w*3, h*2
    Picture1.PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth * 3, Picture1.ScaleHeight * 2, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
      

  18.   

    如果不是放大图像 只是合并 上下相邻 2个被放大的像素 也就是色块 
    那么先要知道被放大的W和H的倍数 WB,HB
    然后用line (x1,y1)-(x1+WB-1,y2+WB-1),color,BF 重画被合并的色块
    关键是要知道色块大小 或者说 放大倍数