Class VmskResource
VmskResource class
Class VmskResource. 此资源包含有关向量层掩码 的信息
public class VmskResource : VectorPathDataResource
构造函数
特性
方法
姓名 | 描述 |
---|
override Save(StreamContainer, int) | 将资源保存到指定的流容器中。 |
override ToString() | 返回一个String代表这个实例. |
字段
例子
下面的例子演示了对 VmskResource 资源加载的支持。如何编辑路径。
[C#]
[Test]
public void TestPsdNet106()
{
string sourceFileName = "Rectangle.psd";
string exportPath = "Rectangle_changed.psd";
var im = (PsdImage)Image.Load(sourceFileName);
using (im)
{
var resource = GetVmskResource(im);
// 阅读
if (resource.IsDisabled != false ||
resource.IsInverted != false ||
resource.IsNotLinked != false ||
resource.Paths.Length != 7 ||
resource.Paths[0].Type != VectorPathType.PathFillRuleRecord ||
resource.Paths[1].Type != VectorPathType.InitialFillRuleRecord ||
resource.Paths[2].Type != VectorPathType.ClosedSubpathLengthRecord ||
resource.Paths[3].Type != VectorPathType.ClosedSubpathBezierKnotUnlinked ||
resource.Paths[4].Type != VectorPathType.ClosedSubpathBezierKnotUnlinked ||
resource.Paths[5].Type != VectorPathType.ClosedSubpathBezierKnotUnlinked ||
resource.Paths[6].Type != VectorPathType.ClosedSubpathBezierKnotUnlinked)
{
throw new Exception("VmskResource was read wrong");
}
var pathFillRule = (PathFillRuleRecord)resource.Paths[0];
var initialFillRule = (InitialFillRuleRecord)resource.Paths[1];
var subpathLength = (LengthRecord)resource.Paths[2];
// 路径填充规则不包含任何附加信息
if (pathFillRule.Type != VectorPathType.PathFillRuleRecord ||
initialFillRule.Type != VectorPathType.InitialFillRuleRecord ||
initialFillRule.IsFillStartsWithAllPixels != false ||
subpathLength.Type != VectorPathType.ClosedSubpathLengthRecord ||
subpathLength.IsClosed != true ||
subpathLength.IsOpen != false)
{
throw new Exception("VmskResource paths were read wrong");
}
// 编辑
resource.IsDisabled = true;
resource.IsInverted = true;
resource.IsNotLinked = true;
var bezierKnot = (BezierKnotRecord)resource.Paths[3];
bezierKnot.Points[0] = new Point(0, 0);
bezierKnot = (BezierKnotRecord)resource.Paths[4];
bezierKnot.Points[0] = new Point(8039797, 10905190);
initialFillRule.IsFillStartsWithAllPixels = true;
subpathLength.IsClosed = false;
im.Save(exportPath);
}
}
private VmskResource GetVmskResource(PsdImage image)
{
var layer = image.Layers[1];
VmskResource resource = null;
var resources = layer.Resources;
for (int i = 0; i < resources.Length; i++)
{
if (resources[i] is VmskResource)
{
resource = (VmskResource)resources[i];
break;
}
}
if (resource == null)
{
throw new Exception("VmskResource not found");
}
return resource;
}
也可以看看