zoukankan      html  css  js  c++  java
  • C++:GDI+ 半透明的阴影效果

    利用 GDI+可以很容易的描画出逼真的半透明效果的阴影。

    void DrawShadow(Graphics &g, GraphicsPath ButtonPath)
    {
        g.SetPageUnit(UnitPixel); //设置Graphics的坐标单位为像素

        GraphicsPath &ShadowPath = *(ButtonPath.Clone());    //拷贝一个按钮区域路径的副本,用来生成阴影区域路径

        // 获得阴影区域
        Matrix ShadowMatrix;
        ShadowMatrix.Translate( ShadowSize, ShadowSize );// 平移,ShadowSize即阴影延伸出来的像素数,这里是向右下方移动的,可以根据实际情况修改。
        ShadowPath.Transform(&ShadowMatrix);    // 应用矩阵

        Region ButtonRegion(&ButtonPath);  //利用按钮的路径建立按钮区域
        Region ShadowRegion(&ShadowPath);  //利用阴影路径建立阴影的区域
       
        ShadowRegion.Exclude(&ButtonRegion); // 区域求差,这样就得出了纯粹的阴影区域,排除了阴影区域和按钮区域重合的部分。
       
        // 初始化渐变画刷
        PathGradientBrush brush(&ShadowPath);
        brush.SetCenterColor(ShadowColor); // 这里利用的是路径渐变画刷
        Color colors[] = ...{Color(0, 0, 0, 0)};
        int count = 1;
        brush.SetSurroundColors(colors, &count);
        brush.SetFocusScales(0.75f, 0.75f);  //对渐变效果进行调整,使其更加自然。这句的实际作用是对渐变效果进行缩放。参数是横纵两个坐标轴的缩放比例。

        g.FillRegion(&brush, &ShadowRegion);

        delete &ShadowPath; //别忘了删除Clone出来的副本。
    }

  • 相关阅读:
    __getitem__ 方法的使用
    python加载测试用例时,修改用例不必须以“test”开头
    python 反射
    python 类中__getattr__的使用
    python 中 __dict__函数的使用
    python 类中__int__和__str__的使用
    ubuntu16.04Nvidia驱动、CUDA、cuDNN安装与卸载
    C++中的各种可调用对象
    ubuntu16.04安装QGIS工具
    C/C++中extern关键字详解
  • 原文地址:https://www.cnblogs.com/kevinzhwl/p/3878937.html
Copyright © 2011-2022 走看看