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

関連項目


Layer(RasterImage, bool)

の新しいインスタンスを初期化しますLayerclass.

public Layer(RasterImage image, bool disposeImage = false)
パラメータタイプ説明
imageRasterImage画像。
disposeImageBooleanに設定した場合真実 【処分画像】。

次のコードは、直接ロードせずに JPEG/PNG/etc 画像ファイルを 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);
}

関連項目


Layer(Stream)

の新しいインスタンスを初期化しますLayerclass.

public Layer(Stream stream)
パラメータタイプ説明
streamStream画像ストリーム

次の例は、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);
}

関連項目


Layer(Rectangle, byte[], byte[], byte[], string)

の新しいインスタンスを初期化しますLayerバイト配列からのクラス.

public Layer(Rectangle bounds, byte[] redBytes, byte[] greenBytes, byte[] blueBytes, string name)
パラメータタイプ説明
boundsRectangleレイヤーの境界。
redBytesByte[]赤いバイト。
greenBytesByte[]緑のバイト。
blueBytesByte[]ブルーバイト。
nameStringレイヤー名。

例外

例外調子
PsdImageExceptionバイト配列を空にすることはできません または バイト配列の長さは境界次元 (bounds.Width * bounds.Height) と等しくなければなりません

関連項目