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);

  • 相关阅读:
    jquery ajax 向后台传递数组
    定时任务
    C# 好用的插件
    C# 跳出循环
    存储区更新、插入或删除语句影响到了意外的行数(0)。实体在加载后可能被修改或删除。刷新 ObjectS
    Opencv2.4.9源码分析——HoughLinesP
    OpenCV+C++ 视频图片相互转换
    opencv2.2版本不稳定
    OpenCV 透视变换【图像归一化矫正】
    opencv配置注意事项【总结】
  • 原文地址:https://www.cnblogs.com/wwwzzg168/p/3570205.html
Copyright © 2011-2022 走看看