Các Tài Nguyên Được Hỗ Trợ
Hỗ trợ của GdFlResource
Bài viết này mô tả Hỗ trợ của GdFlResource trong tệp PSD với Aspose.PSD. Đoạn mã sau cho thấy cách Aspose.PSD hỗ trợ GdFlResource.
String dataDir = Utils.getDataDir(SupportOfGdFlResource.class) + "PSD/"; | |
String sourceFileName = dataDir + "ComplexGradientFillLayer.psd"; | |
String exportPath = dataDir + "ComplexGradientFillLayer_after.psd"; | |
PsdImage im = (PsdImage) Image.load(sourceFileName); | |
try { | |
for (Layer layer : im.getLayers()) { | |
if (layer instanceof FillLayer) { | |
FillLayer fillLayer = (FillLayer) layer; | |
for (LayerResource res : fillLayer.getResources()) { | |
if (res instanceof GdFlResource) { | |
// Reading | |
GdFlResource resource = (GdFlResource) res; | |
if (resource.getAlignWithLayer() != false || | |
(Math.abs(resource.getAngle() - 45.0) > 0.001) || | |
resource.getDither() != true || | |
resource.getReverse() != false || | |
!resource.getColor().equals(Color.getEmpty()) || | |
Math.abs(resource.getHorizontalOffset() - (-39)) > 0.001 || | |
Math.abs(resource.getVerticalOffset() - (-5)) > 0.001 || | |
resource.getTransparencyPoints().length != 3 || | |
resource.getColorPoints().length != 2) { | |
throw new RuntimeException("Resource Parameters were read wrong"); | |
} | |
IGradientTransparencyPoint[] transparencyPoints = resource.getTransparencyPoints(); | |
if (Math.abs(100.0 - transparencyPoints[0].getOpacity()) > 0.25 || | |
transparencyPoints[0].getLocation() != 0 || | |
transparencyPoints[0].getMedianPointLocation() != 50 || | |
Math.abs(50.0 - transparencyPoints[1].getOpacity()) > 0.25 || | |
transparencyPoints[1].getLocation() != 2048 || | |
transparencyPoints[1].getMedianPointLocation() != 50 || | |
Math.abs(100.0 - transparencyPoints[2].getOpacity()) > 0.25 || | |
transparencyPoints[2].getLocation() != 4096 || | |
transparencyPoints[2].getMedianPointLocation() != 50) { | |
throw new RuntimeException("Gradient Transparency Points were read Wrong"); | |
} | |
IGradientColorPoint[] colorPoints = resource.getColorPoints(); | |
if (!colorPoints[0].getColor().equals(Color.fromArgb(203, 64, 140)) || | |
colorPoints[0].getLocation() != 0 || | |
colorPoints[0].getMedianPointLocation() != 50 || | |
!colorPoints[1].getColor().equals(Color.fromArgb(203, 0, 0)) || | |
colorPoints[1].getLocation() != 4096 || | |
colorPoints[1].getMedianPointLocation() != 50) { | |
throw new RuntimeException("Gradient Color Points were read Wrong"); | |
} | |
// Editing | |
resource.setAngle(30.0); | |
resource.setDither(false); | |
resource.setAlignWithLayer(true); | |
resource.setReverse(true); | |
resource.setHorizontalOffset(25); | |
resource.setVerticalOffset(-15); | |
List<IGradientColorPoint> newColorPoints = new ArrayList<IGradientColorPoint>(); | |
Collections.addAll(newColorPoints, resource.getColorPoints()); | |
List<IGradientTransparencyPoint> newTransparencyPoints = new ArrayList<IGradientTransparencyPoint>(); | |
Collections.addAll(newTransparencyPoints, resource.getTransparencyPoints()); | |
GradientColorPoint gr = new GradientColorPoint(); | |
gr.setMedianPointLocation(75); | |
gr.setLocation(4096); | |
gr.setColor(Color.getViolet()); | |
newColorPoints.add(gr); | |
colorPoints[1].setLocation(3000); | |
GradientTransparencyPoint gr2 = new GradientTransparencyPoint(); | |
gr2.setOpacity(80.0); | |
gr2.setLocation(4096); | |
gr2.setMedianPointLocation(25); | |
newTransparencyPoints.add(gr2); | |
transparencyPoints[2].setLocation(3000); | |
resource.setColorPoints(newColorPoints.toArray(new IGradientColorPoint[0])); | |
resource.setTransparencyPoints(newTransparencyPoints.toArray(new IGradientTransparencyPoint[0])); | |
im.save(exportPath); | |
} | |
break; | |
} | |
break; | |
} | |
} | |
} finally { | |
im.dispose(); | |
} |
Hỗ trợ của VmskResource
Bài viết này mô tả Hỗ trợ của VmskResource trong tệp PSD với Aspose.PSD. Đoạn mã sau cho thấy cách Aspose.PSD hỗ trợ VmskResource.
String dataDir = Utils.getDataDir(SupportOfVmskResource.class) + "PSD/"; | |
String sourceFileName = dataDir + "Rectangle.psd"; | |
String exportPath = dataDir + "Rectangle_changed.psd"; | |
PsdImage im = (PsdImage) Image.load(sourceFileName); | |
try { | |
VmskResource resource = getVmskResource(im); | |
// Reading | |
if (resource.isDisabled() != false || | |
resource.isInverted() != false || | |
resource.isNotLinked() != false || | |
resource.getPaths().length != 7 || | |
resource.getPaths()[0].getType() != VectorPathType.PathFillRuleRecord || | |
resource.getPaths()[1].getType() != VectorPathType.InitialFillRuleRecord || | |
resource.getPaths()[2].getType() != VectorPathType.ClosedSubpathLengthRecord || | |
resource.getPaths()[3].getType() != VectorPathType.ClosedSubpathBezierKnotUnlinked || | |
resource.getPaths()[4].getType() != VectorPathType.ClosedSubpathBezierKnotUnlinked || | |
resource.getPaths()[5].getType() != VectorPathType.ClosedSubpathBezierKnotUnlinked || | |
resource.getPaths()[6].getType() != VectorPathType.ClosedSubpathBezierKnotUnlinked) { | |
throw new RuntimeException("VmskResource was read wrong"); | |
} | |
PathFillRuleRecord pathFillRule = (PathFillRuleRecord) resource.getPaths()[0]; | |
InitialFillRuleRecord initialFillRule = (InitialFillRuleRecord) resource.getPaths()[1]; | |
LengthRecord subpathLength = (LengthRecord) resource.getPaths()[2]; | |
// Path fill rule doesn't contain any additional information | |
if (pathFillRule.getType() != VectorPathType.PathFillRuleRecord || | |
initialFillRule.getType() != VectorPathType.InitialFillRuleRecord || | |
initialFillRule.isFillStartsWithAllPixels() != false || | |
subpathLength.getType() != VectorPathType.ClosedSubpathLengthRecord || | |
subpathLength.isClosed() != true || | |
subpathLength.isOpen() != false) { | |
throw new RuntimeException("VmskResource paths were read wrong"); | |
} | |
// Editing | |
resource.setDisabled(true); | |
resource.setInverted(true); | |
resource.setNotLinked(true); | |
BezierKnotRecord bezierKnot = (BezierKnotRecord) resource.getPaths()[3]; | |
bezierKnot.getPoints()[0] = new Point(0, 0); | |
bezierKnot = (BezierKnotRecord) resource.getPaths()[4]; | |
bezierKnot.getPoints()[0] = new Point(8039797, 10905190); | |
initialFillRule.setFillStartsWithAllPixels(true); | |
subpathLength.setClosed(false); | |
im.save(exportPath); | |
} finally { | |
im.dispose(); | |
} |
Hỗ trợ của SoCoResource
SoCoResource chứa thông tin về Lớp Màu Tô. Bài viết này biểu diễn cách Aspose.PSD cho Java hỗ trợ SoCoResource trong một tệp PSD.
- Tải một tệp PSD như hình ảnh bằng phương thức Factory Load mà lớp Image cung cấp.
- Nhận SoCoResource từ lớp hình ảnh
- Thiết lập các thuộc tính cần thiết
- Lưu kết quả
Đoạn mã sau cho thấy cách Aspose.PSD cho Java hỗ trợ SoCoResource.
String dataDir = Utils.getDataDir(SupportOfSoCoResource.class) + "ModifyingAndConvertingImages/"; | |
String sourceFileName = dataDir + "ColorFillLayer.psd"; | |
String exportPath = dataDir + "SoCoResource_Edited.psd"; | |
PsdImage im = (PsdImage) Image.load(sourceFileName); | |
try { | |
for (Layer layer : im.getLayers()) { | |
if (layer instanceof FillLayer) { | |
FillLayer fillLayer = (FillLayer) layer; | |
for (LayerResource resource : fillLayer.getResources()) { | |
if (resource instanceof SoCoResource) { | |
SoCoResource socoResource = (SoCoResource) resource; | |
assert Color.fromArgb(63, 83, 141).equals(socoResource.getColor()); | |
socoResource.setColor(Color.getRed()); | |
break; | |
} | |
} | |
break; | |
} | |
im.save(exportPath); | |
} | |
} finally { | |
im.dispose(); | |
} |