可能是我没有把问题表达清楚:我要的效果是窗体逐渐透明,即整个窗体各点之间有着不同的透明度,
而不是随着时间的变化而改变透明度
比如窗体从上到下透明慢慢增加或减少(特别注明是静态的,不是动态的
不是靠改变整个窗体的透明度来实现)好象这样,窗体的上半部分透明度高,然后向下透明度逐渐降低,到了窗体的底部,
可能就为不透明了
(假如一幅背景图在窗体后,则图像从上到下从清晰度慢慢减少或增加,不是
 靠时间的,是静态的)

解决方案 »

  1.   

    可以提示一下?
    本人可图像这一块和api这一块不熟?
    莱鸟请教
      

  2.   

    我用的是win2000版本,也只要在win2000下就可以了
      

  3.   

    '假如你要把下“图1”和“图2”做Alpha混合,
    '那么我们暂且把“图1”称作“源图”,把
    '“图2”称作“目标图”。首先要把源图和目
    '标图对应要混合的象素RGB值分离从而得到三
    '基色分量,把源像素的三个颜色分量分别乘
    '上Alpha的值,
    '并把目标像素的三个颜色分量
    '分别乘上Alpha的反值,'接下来把结果按对应颜色分量相加
    '再对最后求得的每个分量结果除以Alpha的最大值'最后把三个颜色分量重新合成为一个像素输出。'Alpha的最大值当然是256了。
    'Alpha算法可以这样描述:'AlphaRed=(Red1*Alpha+Red2*(256-Alpha))/256
    'AlphaGreen=(Green1*Alpha+Green2*(256-Alpha))/256
    'AlphaBlue=(Blue1*Alpha+Blue2*(256-Alpha))/256'(R1*a+R2*(256-a))/256
    '注:三种基色最终要合成后输出,Alpha反值=最大值-Alpha值
    'R1 代表源象素的R分量
    'R2 代表目标象素的R分量
    'a 代表Alpha值最简单的方法用API里的Setpixel和Getpixel不过,逐点做很慢,加上你API不熟,就更难搞了....建议你去看看Zyl910的文章吧,不然,做出来了也会巨慢的...
      

  4.   

    下线了,明天还有事,上面的公式可以用,如果你不会写,等明天下午我上线的时侯把代码(用上面的公式做Alpha变转)写好贴上来!其实以前Zyl910写过一个,而且,效率非常高,不过,就是太复杂了,才入门的不好看懂,如果你不是非常要求效率,用上面的公式自己写一个足够了,我以前就是用上面的公式自己写的,不过效率太低,后来就没用了,用的系统提供的那个函数,不过,要完成你说的那种效果,只能自己逐点做了.....      :)
      

  5.   

    求Zyl910的效率非常高的算法.
    [email protected]
    谢谢
      

  6.   

    麻烦哪位大虾能讲明白一点吗?
    邮:  [email protected]
    小弟万分跪谢
      

  7.   

    win2000/xp下,这样就行了!
    请注意这是 Windows 2000 新增的API函数。
    制作半透明窗体和形状不规则的窗体
    函数SetLayeredWindowAttributes  使用这个函数,可以轻松的实现半透明窗体。按照微软的要求,透明窗体窗体在创建时应使用WS_EX_LAYERED参数(用CreateWindowEx),或者在创建后设置该参数(用SetWindowLong),我选用后者。全部函数、常量声明如下: 
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long 
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long 
       其中hwnd是透明窗体的句柄,crKey为颜色值,bAlpha是透明度,取值范围是[0,255],dwFlags是透明方式,可以取两个值:当取值为LWA_ALPHA时,crKey参数无效,bAlpha参数有效;当取值为LWA_COLORKEY时,bAlpha参数有效而窗体中的所有颜色为crKey的地方将变为透明--这个功能很有用:我们不必再为建立不规则形状的窗体而调用一大堆区域分析、创建、合并函数了,只需指定透明处的颜色值即可,哈哈哈哈!请看具体代码。
    Private Const WS_EX_LAYERED = &H80000
    Private Const GWL_EXSTYLE = (-20)
    Private Const LWA_ALPHA = &H2
    Private Const LWA_COLORKEY = &H1
    Private Sub Form_Load()
      Dim rtn As Long
      rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
      rtn = rtn Or WS_EX_LAYERED
      SetWindowLong hwnd, GWL_EXSTYLE, rtn
      SetLayeredWindowAttributes hwnd, 0, 200, LWA_ALPHA
    End Sub动态的修改bAlpha就可以实现窗体的
    嘿嘿,试试吧!!
      

  8.   


    http://www.fantasiasoft.net/Zyl910/AlphaDemo.zip
    用到了DIB和模拟指针
    至于那种渐变透明的窗口
    SetLayeredWindowAttributes功能太局限了
    用UpdateLayeredWindow可能能办到老外写的给窗口加阴影的程序,可能是你所需要的实现技术
    http://vbaccelerator.com/home/VB/Code/Libraries/Graphics_and_GDI/Drop_Shadows/article.asp
      

  9.   

    'AlphaRed=(Red1*Alpha+Red2*(256-Alpha))/256
    'AlphaGreen=(Green1*Alpha+Green2*(256-Alpha))/256
    'AlphaBlue=(Blue1*Alpha+Blue2*(256-Alpha))/256
    这只是整体透明的计算公式
    渐变透明需要用到带Alpha通道的透明合成
    (整数)运算公式是:
    A=(A1*AllAlpha)\255
    R=R0+(clng(R1)-R0)*A\255
    G=G0+(clng(G1)-G0)*A\255
    B=B0+(clng(B1)-B0)*A\255R、G、B是合成的RGB值
    R0、G0、B0是背景层某点的RGB
    R1、G1、B1、A1是上层某点的RGB、Alpha
      

  10.   

    Private Declare Function UpdateLayeredWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal hdcDst As Long, ByRef pptDst As POINT, ByRef psize As SIZE, ByVal hdcSrc As Long, ByRef pptSrc As POINT, ByVal crKey As Long, ByRef pblend As BLENDFUNCTION, ByVal dwFlags As Long) As Long
      

  11.   

    老外的程序看过了,好不好,但不是我想要的.
    Zyl910的例子很好看,小弟深表佩服.但我想要的效果好象都不是以上的?不知各位
    是否真正明白我的意思? 
    不要我再讲一遍吧?
    [email protected]
      

  12.   

    公式都在这里了,自己写吧!用Dib处理或Setpixelv和GetPixel引用楼上的:'AlphaRed=(Red1*Alpha+Red2*(256-Alpha))/256
    'AlphaGreen=(Green1*Alpha+Green2*(256-Alpha))/256
    'AlphaBlue=(Blue1*Alpha+Blue2*(256-Alpha))/256
    这只是整体透明的计算公式
    渐变透明需要用到带Alpha通道的透明合成
    (整数)运算公式是:
    A=(A1*AllAlpha)\255
    R=R0+(clng(R1)-R0)*A\255
    G=G0+(clng(G1)-G0)*A\255
    B=B0+(clng(B1)-B0)*A\255R、G、B是合成的RGB值
    R0、G0、B0是背景层某点的RGB
    R1、G1、B1、A1是上层某点的RGB、Alpha
      

  13.   

    免费使用
    免费升级超越水晶报表,是我们的目标
    彻底解除程序员负担,极大提高用户设定灵活性
    LLanV报表工具,经过了10000行以上数据的压力测试,性能优良!其中一部分功能如下:  
    1.支持资料卡(比如:个人简历),表单(比如:销售定单),报表(比如:销售月报表)的预览打印
    2.不用任何设定,就可以默认产生专业的页面
    3.用户可以一次性设定企业标准样式(比如:公司标志,台头)
    4.支持文本,线条,方框,图片,等报表元素
    5.对各报表元素和报表区域等提供丰富的属性
    6.用户可以在运行期间编辑文本,线条,方框,图片,明细列, 操作简单
    7.支持同一列相同数据合并成一个格
    8.可以在运行期间增删,调换明细列
    9.提供多种报表风格
    10.支持页合计,总计
    11.支持的套打报表
    12.支持MIS开发的各种开发工具:如VC、VB、Delphi等
    13.可以直接连接数据库
    14.用户可以把设定后的报表样式保存为报表样式文件
    15.报表头和报表尾均可多于一页
    16.报表样式文件格式完全开放
    17.可以实现中国式复杂报表样式
    18.无须编程请发EMAIL给[email protected]
      

  14.   

    有哪位可以写一个例子给我吗?我实在是没什么头绪
    [email protected]
      

  15.   

    '新建一个标准EXE
    '窗体上添加Picture1,Picture2,Command1三个控件
    'Picture1和Picture2控件中分别载入两张不同的图片
    '复制以下代码到Form1
    Option Explicit
    '自定义类型
    Private Type RGB_Color
        cR As Long
        cG As Long
        cb As Long
    End Type'API函数
    Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
    Private Declare Function SetPixelV Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
    Private Declare Function timeGetTime Lib "winmm.dll" () As Long
    Private Sub Command1_Click()
        Command1.Enabled = False
        
        Dim I As Long, J As Long
        Dim Ahdc As Long, Bhdc As Long
        Dim Acolor As Long, Bcolor As Long
        Dim Argb As RGB_Color, Brgb As RGB_Color
        Dim OutRGB As RGB_Color
        Dim OutColor As Long
        Ahdc = Picture1.hDC
        Bhdc = Picture2.hDC
        
        Dim a As Long, B As Long    a = timeGetTime
        
        Dim cAlpha As Long
        cAlpha = 129 '这里是透明度,0到255    
        For I = 0 To Picture2.ScaleWidth
            For J = 0 To Picture2.ScaleHeight
                
                Acolor = GetPixel(Ahdc, I, J)
                Bcolor = GetPixel(Bhdc, I, J)
                
                Argb = Color2RGB(Acolor)
                Brgb = Color2RGB(Bcolor)
                
                
                
                With OutRGB
                
                    'Alpha转换公式
                    'AlphaRed=(Red1*Alpha+Red2*(256-Alpha))/256
                    'AlphaGreen=(Green1*Alpha+Green2*(256-Alpha))/256
                    'AlphaBlue=(Blue1*Alpha+Blue2*(256-Alpha))/256
                    .cR = (Argb.cR * cAlpha + Brgb.cR * (256 - cAlpha)) / 256
                    .cG = (Argb.cG * cAlpha + Brgb.cG * (256 - cAlpha)) / 256
                    .cb = (Argb.cb * cAlpha + Brgb.cb * (256 - cAlpha)) / 256
                    
                OutColor = RGB(.cR, .cG, .cb)
                End With
                
                
                    Call SetPixelV(Bhdc, I, J, OutColor)
            Next J
        Next I
        
    Set Picture2.Picture = Picture2.Image
        B = timeGetTime
        Me.Caption = "用时" & B - a & "毫秒"    Command1.Enabled = True
    End SubPrivate Function Color2RGB(lngColor As Long) As RGB_Color
        With Color2RGB
            .cR = lngColor And &HFF
            .cG = (lngColor \ &H100) And &HFF
            .cb = (lngColor \ &H10000) And &HFF
        End With
    End Function
      

  16.   

    在2000/xp中似乎可以解决,但我找到的都是对全窗口有效的。winmm.dll?
      

  17.   

    在2000/xp中似乎可以解决,但我找到的都是对全窗口有效的。winmm.dll?
      

  18.   

    我贴的代码就可以呀!    a = timeGetTime
        
        Dim cAlpha As Long
        cAlpha = 129 '这里是透明度,0到255    
        For I = 0 To Picture2.ScaleWidthcAlpha就是透明度的值0-255在循环中改变这个值就可以了呀!
      

  19.   

    *****注意:
     mr2000(心素如简) 比较理解我的意思加上一个静态的就更好了,不是随时间而改变  boyzhang(张郎) 我试了一下,好象不行呀,还很耗资源
     楼上的贴了这么多,先是跪着感谢了,但好象还是没一个解决我的问题 难道此问题无解吗?????????????????????????????
     真搞不懂
      

  20.   

    : Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As LongConst LWA_ALPHA = &H2   ':表示把窗体设置成半透明样式
    Const LWA_COLORKEY = &H1   ':表示不显示窗体中的透明色
    Private Const WS_EX_LAYERED = &H80000
    Private Const GWL_EXSTYLE = (-20)Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Sub Command1_Click()
          Timer1.Enabled = True
    End SubPrivate Sub Form_Load()
          Timer1.Enabled = False
          Timer1.Interval = 50
    End SubPrivate Sub Timer1_Timer()
            Static I As Long
            Dim rtn As Long
            I = I + 2
            If I >= 256 Then I = 1
            
            rtn = GetWindowLong(Me.hwnd, GWL_EXSTYLE)    ':取的窗口原先的样式
            rtn = rtn Or WS_EX_LAYERED     ':使窗体添加上新的样式WS_EX_LAYERED
            SetWindowLong Me.hwnd, GWL_EXSTYLE, rtn    ':把新的样式赋给窗体
            SetLayeredWindowAttributes Me.hwnd, 0, I, LWA_ALPHA
            '把窗体设置成半透明样式 , 第二个参数表示透明程度
            '取值范围0 --255, 为0时就是一个全透明的窗体了
            Me.Show
    End Sub
      

  21.   

    比如窗体从上到下透明慢慢增加或减少(特别注明是静态的,不是动态的
    不是靠改变整个窗体的透明度来实现)
    '________________________________
    SORRY!我没有仔细看..我上面的程序不符合楼主的要求!!!
    :-)
      

  22.   

    我贴的代码就可以呀!    a = timeGetTime
        
        Dim cAlpha As Long
        cAlpha = 129 '这里是透明度,0到255    
        For I = 0 To Picture2.ScaleWidthcAlpha就是透明度的值0-255在循环中改变这个值就可以了呀!
      

  23.   

    cAlpha就是透明度的值0到255以内
      

  24.   

    你的可以,不会吧,我试了N遍了,而且有时间老是出现内存泄漏问题
    你到底有没有理解我的意思.不要老是用什么TimeGetTime,Timer此类的东西好吧.静态的
    再重申一遍:
      窗体从上到下透明度逐渐不同,注意是静态的(同一时间),是窗体的透明度个个部分
      互不相同
      

  25.   

    特别声明一下:我用的还是512M+Win2000 Server
      

  26.   

    Private Declare Function UpdateLayeredWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal hdcDst As Long, ByRef pptDst As POINT, ByRef psize As SIZE, ByVal hdcSrc As Long, ByRef pptSrc As POINT, ByVal crKey As Long, ByRef pblend As BLENDFUNCTION, ByVal dwFlags As Long) As Long
      

  27.   

    我用的是:
    2 * P4 3.06 G CPU+ 技茄舰旗主板 + 4 * SCSI IV 硬盘 + 2 * 512M DDR400.
      

  28.   

    这是"线性渐变"的效果!想看看到底是什么,去PhotoShop或False里就能看到了!
    线性渐变是:颜色由深到浅.
    楼主想要是:由不透明到透明!我的机器 = Intel 赛扬II-700MHz + (2 * 128 + 64)MB ?ns SDRAM + 2M缓存7200转30G IDE硬盘 & 一块不知名厂商生产的型号为:BX-W977EF 的主板!!
      

  29.   

    倒!  ..........  真的没话说了!TimeGetTime '返回WINDOWS运行时间例子
    dim a as long,b as long
    a=TimeGetTime
    一些代码
    b=TimeGetTime
    me.caption = b-a '这样可以计算使用了多少时间我给你的代码绝对没有问题,我在自己的机子上调试过!我的配置:Win2K+VB6Sp5 BX板 Celeron566 160M Ram做一个转换 337*441 两幅图合Alpha 用4663毫秒,这是因为用的GetPixel和SetPixelV这两个函数,这两个API的效率太低了,如果用Zyl910的那个方法(DIB处理)可以一秒做5-6帧(视机器速度而定,我做过这种东东),不过,这个例子最简单,如果你连这个都看不懂,那,想看懂那种用DIB的就更不可能了....这么简单的代码你也调不过,还在坛子上问了一个多礼拜,看来你真的要从头开始学呀!要静心,不要什么都来问别人,毕竟人家告诉你的,你要是没搞懂,那不还是别人的?'-----------------------------------我没有恶意,只是给你提一点建议.....    :)对了,想渐变要控制那个cAlpha的值就像
            '只能在0至255之间
            If cAlpha > 254 Then cAlpha = 255
                cAlpha = cAlpha + 1
            end if
      

  30.   

    对了,我的代码应该在Win9X和Win2K都可以使用,因为,SetPixel和SetPixelV这两个API在9X和2K(NT)下都可以使用,而且是逐点做的,只要知道算法,什么灰度转换,Alpha,浮雕,等,都可以做,不像SetLayeredWindowAttributes一类的函数,只能在Win2K以后的系统里才能支持,而且,这个函数只能做全部透明,不能做渐变.......我做的DIB处理(没有使用模拟指针),灰度可以达到每秒8-10帧(不是全屏),Alpha可以到每秒3-5帧(速度都取决于你的机器配置),不过,还是没有zyl910的例子快[我的算法写的很烂  :)   ],还有就是没有使用指针,毕竟使用指针比较容易出错......
      

  31.   

    对了,再提一下常识性的问题Appearance=0'不要显示3D样式
    AutoRedraw=True'不要逐点的显示,
    等到画完后用
    Set Picture1.Picture = Picture1.Image
    可以提高效率
    AutoSize=True'尺寸自动
    BorderStyle=0'不要边框线
    ScaleMode=3'这句很关键,API工作在Pixel
    '再载入两张一模一样大小,内容不同的图片
    分别到Picture1和Picture2
      

  32.   

    楼主的问题我也想知道
    另外我截了一张图
    http://www2.ycwb.net/upload/files/yes111.jpg
    是一个显示日历和记事的小工具,但是界面很好看,尤其是部分半透明和阴影效果
    我用2个窗体叠加实现了部分半透明(而且是不规则窗体的叠加)
    但是阴影效果实现就费劲了,哪位看看这个有啥好办法,或者不使用叠加也可以实现部分半透明的效果?应该跟楼主的帖子要求的功能有相似的地方
      

  33.   

    这个可以实现,不过应该很难,因为按照当初Windows的消息循环设计思想,系统并没有提供这方面的支持
    不过奇怪的是2000竟然提供了一个设置窗体透明的函数,.net里也可以直接设置窗体透明度
    我感觉这完全是不应该的
    而且如果提供也不应该只简单的提供一个API
    也许还有其它相关的东西没有被找到吧
      

  34.   

    我没话说了,自己看看吧!http://boyzhangpublic.go.nease.net/example.jpg
    http://boyzhangpublic.go.nease.net/example.exe用上面的代码做的Alpha混合.....
      

  35.   

    搞定了!
    http://www.fantasiasoft.net/Zyl910/GradAlphaForm.rar'项目:渐变透明的窗口
    '作者:zyl910
    '版本:1.0.0
    '日期:2004-4-10
    'E-Mail:[email protected]
    '
    '问题来源:
    'http://expert.csdn.net/Expert/topic/2916/2916483.xml?temp=5.643862E-02
    '主  题:  本人再问一遍---透渐透明窗体(静态)
    '作 者:      lottery009 (gary)
    '等 级:
    '信 誉 值:  100
    '所属论坛:   VB API
    '问题点数:  50
    '回复次数:  47
    '发表时间:  2004-4-2 10:14:59
    '
    '注意:按Esc或双击窗体结束。
    '
    'Bug:
    '1.[2004/4/10]带阴影的鼠标指针在窗口上移动时画面有些错乱。那是Windows自身问题,无法解决。
      

  36.   

    哈哈,得来全不费功夫,以前知道2000有个函数设置透明,不过从来没用过,是哪个函数也不知道!
    多谢楼上的Layered Windows
    Using a layered window can significantly improve performance and visual effects for a window that has a complex shape, animates its shape, or wishes to use alpha blending effects. The system automatically composes and repaints layered windows and the windows of underlying applications. As a result, layered windows are rendered smoothly, without the flickering typical of complex window regions. In addition, layered windows can be partially translucent, that is, alpha-blended.To create a layered window, specify the WS_EX_LAYERED extended window style when calling the CreateWindowEx function, or call the SetWindowLong function to set WS_EX_LAYERED after the window has been created. After the CreateWindowEx call, the layered window will not become visible until the SetLayeredWindowAttributes or UpdateLayeredWindow function has been called for this window. Note that WS_EX_LAYERED cannot be used for child windows.To set the opacity level or the transparency color key for a given layered window, call SetLayeredWindowAttributes. After the call, the system may still ask the window to paint when the window is shown or resized. However, because the system stores the image of a layered window, the system will not ask the window to paint if parts of it are revealed as a result of relative window moves on the desktop. Legacy applications do not need to restructure their painting code if they want to add translucency or transparency effects for a window, because the system redirects the painting of windows that called SetLayeredWindowAttributes into off-screen memory and recomposes it to achieve the desired effect.For faster and more efficient animation or if per-pixel alpha is needed, call UpdateLayeredWindow. UpdateLayeredWindow should be used primarily when the application must directly supply the shape and content of a layered window, without using the redirection mechanism the system provides through SetLayeredWindowAttributes. In addition, using UpdateLayeredWindow directly uses memory more efficiently, because the system does not need the additional memory required for storing the image of the redirected window. For maximum efficiency in animating windows, call UpdateLayeredWindow to change the position and the size of a layered window. Please note that after SetLayeredWindowattributes has been called, subsequent UpdateLayeredWindow calls will fail until the layering style bit is cleared and set again.Hit testing of a layered window is based on the shape and transparency of the window. This means that the areas of the window that are color-keyed or whose alpha value is zero will let the mouse messages through. However, if the layered window has the WS_EX_TRANSPARENT extended window style, the shape of the layered window will be ignored and the mouse events will be passed to other windows underneath the layered window.
      

  37.   

    要渐变,只有逐点做.好像没有现成的API
      

  38.   

    boyZhang把那个例子的源码发给我好吗?
    以后可真的要向各位好好学习了[email protected]
      

  39.   

    那个例子是在学校里随便乱写的,写的很零乱(我不习惯用别人的机子写程序,很多工具用的不顺手),写完就编译后发到我的FTP上的,不知道还能不能找到,如果还在那个机子上,明天中午就传给你......