Option ExplicitDim Tex As POINTAPI
Dim Dis As Long
Dim Pot1 As POINTAPI
Dim pRot As Double
Dim oRot As DoubleConst Ken = 0.0005
Const PI = 3.1415926
Const Scal = 0.92
Const ScaX = 13
Const ScaY = 13
Private Sub Emendation_Click()
   
  Dim BColor As Long
  Dim i As Long, j As Long
  
  Tex.X = Pic1.Width / 2
  Tex.Y = Pic1.Height / 2
    
  For j = 1 To Pic1.Height
       
       For i = 1 To Pic1.Width
       
             
       BColor = GetPixel(Pic1.hdc, i, j)
       pRot = (i - Tex.X) ^ 2 + (j - Tex.Y) ^ 2
        
        If i <> Tex.X Then
   
             oRot = Atn((j - Tex.Y) / (i - Tex.X))
                
                Else
      
             If j <= Tex.Y Then
                    oRot = -PI / 2
                        Else
                    oRot = PI / 2
             End If
       
        End If
       
   
             If i >= Tex.X Then
   
                Pot1.X = Scal * (i + Ken * pRot * Cos(oRot)) + ScaX
                Pot1.Y = Scal * (j + Ken * pRot * Sin(oRot)) + ScaY
                
                SetPixel Pic2.hdc, Pot1.X + 1, Pot1.Y + 1, BColor
                SetPixel Pic2.hdc, Pot1.X, Pot1.Y + 1, BColor
                SetPixel Pic2.hdc, Pot1.X + 1, Pot1.Y, BColor
                SetPixel Pic2.hdc, Pot1.X, Pot1.Y, BColor
                SetPixel Pic2.hdc, Pot1.X - 1, Pot1.Y, BColor
                SetPixel Pic2.hdc, Pot1.X, Pot1.Y - 1, BColor
                SetPixel Pic2.hdc, Pot1.X - 1, Pot1.Y - 1, BColor
                   
                   Else
                
                Pot1.X = Scal * (i - Ken * pRot * Cos(oRot)) + ScaX
                Pot1.Y = Scal * (j - Ken * pRot * Sin(oRot)) + ScaY
                
                SetPixel Pic2.hdc, Pot1.X + 1, Pot1.Y + 1, BColor
                SetPixel Pic2.hdc, Pot1.X, Pot1.Y + 1, BColor
                SetPixel Pic2.hdc, Pot1.X + 1, Pot1.Y, BColor
                SetPixel Pic2.hdc, Pot1.X, Pot1.Y, BColor
                SetPixel Pic2.hdc, Pot1.X - 1, Pot1.Y, BColor
                SetPixel Pic2.hdc, Pot1.X, Pot1.Y - 1, BColor
                SetPixel Pic2.hdc, Pot1.X - 1, Pot1.Y - 1, BColor
            
            End If
  
     Next
  NextPic2.Picture = Pic2.ImageEnd Sub

解决方案 »

  1.   

    不是,zyl910,thirdapple这两只都不在,他们应解答得来。
    高手也各有所长啊。
    帮你UP吧。
      

  2.   

    谢谢,
          我上面说的有点不对,我是说想利用 "设备无关位图(DIB)"直接对显存进行读写...
          着急呀  ...
      

  3.   

    预备工作:
    用CreateDIBSection创建DIB项,记得保存lplpVoid参数得值,它是DIB位图数据的地址
    创建DC并把创建的DIB项选入
    把图像Bitblt进来处理方法:
    虽然用GetBitmapBits可以得到图像数据
    但这样比较慢
    由于先前得到了lplpVoid参数得值(DIB位图数据的地址)
    可以把一个数组的SAFEARRAY结构的pvData改成lplpVoid参数得值
    这样可以减少复制内存的时间方法可参考AdamBear的文章:
    http://www.csdn.net/develop/author/netauthor/AdamBear/最关键是这个:http://www.csdn.net/Develop/read_article.asp?id=13066
    具体的图像处理程序可参考:
    http://www.21code.com/codebase/?pos=down&id=1754
    源码类型: VisualBasic源码-图形方面   
      
    上传时间: 2001-10-28  
    下载次数: 101  
    源码大小: 83 KB 源码评价:      源码简介:快速图形处理程序,有几种常见的处理效果,但是速度都比其他示例快
      

  4.   

    这几天我想出了一种新的处理DIB图片的方法:模拟二级指针对于640*480的图像的半透明合并
    只比Bitblt慢3倍
    比AlphaBlend慢1倍
    比GetPixel、SetPixelV算半透明快94倍!处理时间(我的CPU是K6-2 350):
    普通透明:105毫秒
    Alpha通道透明:185毫秒Bitblt到PictureBox:24毫秒
    AlphaBlend:58毫秒
    GetPixel、SetPixelV算:10.08秒
    程序在http://zyl910vb.51.net/test/里的ZDIBop.rar
    (没有源程序,只有exe。因为程序好没有写完)
      

  5.   

    (zyl910):
            读取到DIB方法我明白,但怎样按照不规则的顺序写入显寸呢?
            谢谢你的回答
      

  6.   

    按照不规则的顺序写入显寸呢?
    ?????不明白这是什么意思
    先在DIB图片中处理
    再用Bitblt到屏幕hDC不行吗?
      

  7.   

    我还是不太理解,zyl910(910:分儿,我来了!) (L2002) ,你看我上面的那段程序,我是将一幅图片的象素点运算后写入第二副图片,但在第二副图象里的位置是和第一幅图不一样的。该怎么写入dib呢?
        求教老兄:
        恳请回答!  
      

  8.   

    你先看看这个程序:http://www.21code.com/codebase/?pos=down&id=1754
    源码类型: VisualBasic源码-图形方面   
      
    上传时间: 2001-10-28  
    下载次数: 101  
    源码大小: 83 KB 源码评价:      源码简介:快速图形处理程序,有几种常见的处理效果,但是速度都比其他示例快参照它的例子写
      

  9.   

    zyl910(910:分儿,我来了!) (L2002):      我仔细看了上面的程序,还是感觉我的问题有他特殊的地方,例程里的图像变化能写入第二个dib数组, 可我的不行,因为,我的图像实际上不是变换颜色,而是变化了坐标,而且坐标值不是线性变换,是一个二次曲线.
          她怎么写入dib数组呢?
      

  10.   

    计算好地址就行了!比如这是24位色DIB
    宽、高、每一行所占字节分别为Width、Height、WidthBytes那么(x,y)的数组下标为(Height-y-1)*WidthBytes+x*3
      

  11.   

    由于DIB图像数据是逆序存储的
    数据的第一行实际上是图像的最后一行
    所以是Height-y-1
      

  12.   

    同时你的算法可以优化
    要尽量避免 幂运算 以及 浮点乘除比如:
    Tex.X = Pic1.Width \ 2
    Tex.Y = Pic1.Height \ 2

    Tex.X = Pic1.Width / 2
    Tex.Y = Pic1.Height / 2
      

  13.   

    我怎么能得到WidthBytes的值呢?
      

  14.   

    Function MapArray(ByRef a As Variant) As Long'cause it was uncommented, I decided to. (gonchuki)
    'ok, this is documented in the original app but i don't
    'use that function here :-P
    'Original comment as follows:
        ' ...very useful function of my DIB-Helper class. MapArray fools VB
        ' making him think that his array (which is not bounded, in fact)
        ' is mapped to particular space in memory (DIB bits in our case).
        ' it returns byte-width of one line of pixels in DIB
    'so what it does is return a linear array whit the color information of each pixel
    'but be careful!!! each pixel is converted to three (RGB) bytes and the DIB is upside-down
    'and what we have in memory is the last pixel at the beggining and in the format BGR    sa.cDims = 1
        sa.cbElements = 1
        sa.pvData = lpRGB
        sa.CE0 = bmH.biSizeImage
        
        CopyMemory saPtr, ByVal VarPtr(a) + 8, 4
        CopyMemory ByVal saPtr, VarPtr(sa), 4
    '☆☆这就是WidthBytes,作为函数的返回值☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆
        MapArray = bmH.biSizeImage \ bmH.biHeight
    End Function