Layer.Layer

Layer()

Inizializza una nuova istanza diLayer classe. Costruttore per inizializzazione pigra.

public Layer()

Esempi

L’esempio seguente mostra come disegnare su un livello appena creato se viene utilizzata la versione del costruttore semplice in 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);

    // disegna un rettangolo con lo strumento Penna
    graphic.DrawRectangle(new Pen(Color.Red), new Rectangle(30, 10, 40, 80));

    // disegna un altro rettangolo con Solid Brush in colore blu
    graphic.DrawRectangle(new Pen(new SolidBrush(Color.Blue)), new Rectangle(10, 30, 80, 40));

    image.Save(outputFilePath);
}

Guarda anche


Layer(RasterImage, bool)

Inizializza una nuova istanza diLayer classe.

public Layer(RasterImage image, bool disposeImage = false)
ParametroTipoDescrizione
imageRasterImageL’immagine.
disposeImageBooleanse impostato suVERO [disponi l’immagine].

Esempi

Il codice seguente dimostra la possibilità di caricare file immagine JPEG/PNG/etc su PsdImage senza caricamento diretto.

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

Guarda anche


Layer(Stream)

Inizializza una nuova istanza diLayer classe.

public Layer(Stream stream)
ParametroTipoDescrizione
streamStreamIl flusso di immagini

Esempi

L’esempio seguente mostra come aggiungere immagini Bmp, Jpeg, Jpeg2000, Png, Psd, Tiff, Gif come livelli a 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);
}

Guarda anche


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

Inizializza una nuova istanza diLayer classe da array di byte.

public Layer(Rectangle bounds, byte[] redBytes, byte[] greenBytes, byte[] blueBytes, string name)
ParametroTipoDescrizione
boundsRectangleIl livello delimita.
redBytesByte[]I byte rossi.
greenBytesByte[]I byte verdi.
blueBytesByte[]I byte blu.
nameStringIl nome del livello.

Eccezioni

eccezionecondizione
PsdImageExceptionGli array di byte non possono essere vuoti o La lunghezza degli array di byte deve essere uguale alle dimensioni dei limiti (bounds.Width * bounds.Height)

Guarda anche