zoukankan      html  css  js  c++  java
  • C#删除区域实现透明

    最近在搞一个图形图像的项目。不知道经理为什么选择了C#语言,但还是要做,呵呵。

    在期间出现一个比较难解决的问题如下:

    删除当前图层的指定区域用来显示下面图层在这个区域的图像,相当于PS蒙版层的效果。

    实现代码如下:

    Bitmap tmp = new Bitmap(page.ImageFileName);
                Bitmap image = new Bitmap(tmp.Width, tmp.Height);
                Graphics g = Graphics.FromImage(image);
                g.Clear(Color.Transparent);
                g.DrawImage(tmp, 0, 0, tmp.Width, tmp.Height);
                tmp.Dispose();
                g = Graphics.FromImage(image);
                foreach (IVObject obj in page.Layers[1].VObjects)
                {
                    Matrix m;
                    GraphicsPath path = new GraphicsPath();
                    switch (obj.GetType().Name)
                    {
                        case "RectangleVObject":
                            path.ClearMarkers();
                            path.AddRectangle(obj.GetVObjectBounds());
                            m = obj.Transform;
                            m.Translate((m.OffsetX * 1.33F - m.OffsetX),
                                (m.OffsetY * 1.33F - m.OffsetY), MatrixOrder.Append);
                            m.Scale(1.33F, 1.33F);
                            path.Transform(m);
                            g.SetClip(path);
                            g.Clear(Color.Transparent);

    Bitmap sourceImage = new Bitmap(imageFileName);

    Bitmap image = new Bitmap(sourceImage .Width, sourceImage .Height); 

    Graphics g = Graphics.FromImage(image); 

    g.Clear(Color.Transparent);

    g.DrawImage(sourceImage , 0, 0, sourceImage .Width, sourceImage.Height);

    sourceImage .Dispose();

    GraphicsPath path = new GraphicsPath();   

    Rectangle r = new Rectangle(x,y,w,h);

    path.AddRectangle(r);

    g.SetClip(path);

    g.Clear(Color.Transparent);

  • 相关阅读:
    mvc edmx 的config文件
    Openwrt安装软件的方法
    如何用JQuery实现单元格 循环变背景色
    Vue的生命周期
    hmtl弹出框样式
    在星巴克买咖啡思考技术团队的管理
    RealTimePerformanceDemoView
    《SAAS创业指南》拆书笔记——产品打磨和商业模式初步验证
    基于日志的回放对比系统设计
    异常测试-中间件故障演练
  • 原文地址:https://www.cnblogs.com/wwwzzg168/p/3570205.html
Copyright © 2011-2022 走看看