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

转载于:https://www.cnblogs.com/RobotG/archive/2010/05/06/Transparent.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值