最近在搞一个图形图像的项目。不知道经理为什么选择了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);