Layer.Layer
内容
[
隐藏
]Layer()
初始化一个新的实例Layer
班级。延迟初始化的构造函数.
public Layer()
例子
下面的示例演示了如果在 Aspose.PSD 中使用简单的构造函数版本,您可以如何在新创建的图层上绘图
[C#]
string outputFilePath = "output.psd";
int width = 100;
int height = 100;
using (var image = new PsdImage(width, height))
{
var layer = new Layer();
layer.Bottom = height;
layer.Right = width;
image.AddLayer(layer);
Graphics graphic = new Graphics(layer);
graphic.Clear(Color.Yellow);
// 用钢笔工具画一个矩形
graphic.DrawRectangle(new Pen(Color.Red), new Rectangle(30, 10, 40, 80));
// 用蓝色实心画笔绘制另一个矩形
graphic.DrawRectangle(new Pen(new SolidBrush(Color.Blue)), new Rectangle(10, 30, 80, 40));
image.Save(outputFilePath);
}
也可以看看
- class Layer
- 命名空间 Aspose.PSD.FileFormats.Psd.Layers
- 部件 Aspose.PSD
Layer(RasterImage, bool)
初始化一个新的实例Layer
类.
public Layer(RasterImage image, bool disposeImage = false)
范围 | 类型 | 描述 |
---|---|---|
image | RasterImage | 图片。 |
disposeImage | Boolean | 如果设置为真的 [处理图像]。 |
例子
以下代码演示了无需直接加载即可将 JPEG/PNG/等图像文件加载到 PsdImage 的能力。
[C#]
string filePath = "PsdExample.psd";
string outputFilePath = "PsdResult.psd";
using (var image = new PsdImage(200, 200))
{
using (var im = Image.Load(filePath))
{
Layer layer = null;
try
{
layer = new Layer((RasterImage)im);
image.AddLayer(layer);
}
catch (Exception)
{
if (layer != null)
{
layer.Dispose();
}
throw;
}
}
image.Save(outputFilePath);
}
也可以看看
- class RasterImage
- class Layer
- 命名空间 Aspose.PSD.FileFormats.Psd.Layers
- 部件 Aspose.PSD
Layer(Stream)
初始化一个新的实例Layer
类.
public Layer(Stream stream)
范围 | 类型 | 描述 |
---|---|---|
stream | Stream | 图像流 |
例子
以下示例演示了如何将 Bmp、Jpeg、Jpeg2000、Png、Psd、Tiff、Gif 图像作为图层添加到 PsdImage
[C#]
string outputFilePath = "PsdResult.psd";
var filesList = new string[]
{
"PsdExample.psd",
"BmpExample.bmp",
"GifExample.gif",
"Jpeg2000Example.jpf",
"JpegExample.jpg",
"PngExample.png",
"TiffExample.tif",
};
using (var image = new PsdImage(200, 200))
{
foreach (var fileName in filesList)
{
string filePath = fileName;
using (var stream = new FileStream(filePath, FileMode.Open))
{
Layer layer = null;
try
{
layer = new Layer(stream);
image.AddLayer(layer);
}
catch (Exception e)
{
if (layer != null)
{
layer.Dispose();
}
throw e;
}
}
}
image.Save(outputFilePath);
}
也可以看看
- class Layer
- 命名空间 Aspose.PSD.FileFormats.Psd.Layers
- 部件 Aspose.PSD
Layer(Rectangle, byte[], byte[], byte[], string)
初始化一个新的实例Layer
来自字节数组的类.
public Layer(Rectangle bounds, byte[] redBytes, byte[] greenBytes, byte[] blueBytes, string name)
范围 | 类型 | 描述 |
---|---|---|
bounds | Rectangle | 图层边界。 |
redBytes | Byte[] | 红色字节。 |
greenBytes | Byte[] | 绿色字节。 |
blueBytes | Byte[] | 蓝色字节。 |
name | String | 图层名称。 |
例外
例外 | (健康)状况 |
---|---|
PsdImageException | 字节数组不能为空 or 字节数组长度必须等于边界尺寸 (bounds.Width * bounds.Height) |
也可以看看
- struct Rectangle
- class Layer
- 命名空间 Aspose.PSD.FileFormats.Psd.Layers
- 部件 Aspose.PSD