Layer.Layer

Layer()

Inicializa una nueva instancia delLayer clase. Constructor para inicialización diferida.

public Layer()

Ejemplos

El siguiente ejemplo demuestra cómo puede dibujar en una capa recién creada si se usa la versión de constructor simple en 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);

    // dibujar un rectángulo con la herramienta Pluma
    graphic.DrawRectangle(new Pen(Color.Red), new Rectangle(30, 10, 40, 80));

    // dibuja otro rectángulo con Pincel Sólido en color Azul
    graphic.DrawRectangle(new Pen(new SolidBrush(Color.Blue)), new Rectangle(10, 30, 80, 40));

    image.Save(outputFilePath);
}

Ver también


Layer(RasterImage, bool)

Inicializa una nueva instancia delLayer clase.

public Layer(RasterImage image, bool disposeImage = false)
ParámetroEscribeDescripción
imageRasterImageLa imagen.
disposeImageBooleansi se establece enverdadero [eliminar imagen].

Ejemplos

El siguiente código demuestra la capacidad de cargar archivos de imagen JPEG/PNG/etc en PsdImage sin carga directa.

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

Ver también


Layer(Stream)

Inicializa una nueva instancia delLayer clase.

public Layer(Stream stream)
ParámetroEscribeDescripción
streamStreamEl flujo de imágenes

Ejemplos

El siguiente ejemplo demuestra cómo puede agregar imágenes Bmp, Jpeg, Jpeg2000, Png, Psd, Tiff, Gif como capas 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);
}

Ver también


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

Inicializa una nueva instancia delLayer clase de matrices de bytes.

public Layer(Rectangle bounds, byte[] redBytes, byte[] greenBytes, byte[] blueBytes, string name)
ParámetroEscribeDescripción
boundsRectangleLos límites de la capa.
redBytesByte[]Los bytes rojos.
greenBytesByte[]Los bytes verdes.
blueBytesByte[]Los bytes azules.
nameStringEl nombre de la capa.

Excepciones

excepcióncondición
PsdImageExceptionLas matrices de bytes no pueden estar vacías o La longitud de las matrices de bytes debe ser igual a las dimensiones de los límites (límites.Ancho * límites.Altura)

Ver también