Quantcast
Channel: magick Discussions Rss Feed
Viewing all articles
Browse latest Browse all 3693

New Post: Multiple layer (PSD) placing images on top of each other

$
0
0
I want to save more images in the one PSD file.

The first layer exclude the psd file, I would also like to save.
using (MagickImageCollection psd = new MagickImageCollection())
{
    MagickImage[] image = new MagickImage[CloneMap.Layers.Count];
    SharpMap.Map psdMap = new SharpMap.Map(CloneMap.Size);

    foreach (SharpMap.Layers.ILayer layer in CloneMap.Layers)
    {
        if (layer.SRID == 0)
        {
            foreach (SharpMap.Layers.Layer psdLayer in CloneMap.Layers)
            {
                if (layer.LayerName == psdLayer.LayerName)
                    psdMap.Layers.Add(psdLayer);
                else
                {
                    SharpMap.Layers.ILayer lay = psdMap.Layers.GetLayerByName(psdLayer.LayerName);
                    if (lay != null)
                        psdMap.Layers.Remove(lay);
                }
            }
            psdMap.ZoomToBox(bx);
            Image imageSource = psdMap.GetMap();

            ImageConverter converter = new ImageConverter();

            image[CloneMap.Layers.IndexOf(layer)] = new MagickImage((byte[])converter.ConvertTo(imageSource, typeof(byte[])), settings);
            imageSource.Dispose();
            GC.Collect();
            image[CloneMap.Layers.IndexOf(layer)].ResolutionUnits = Resolution.PixelsPerInch;
            image[CloneMap.Layers.IndexOf(layer)].Density = new PointD(dpi);
            image[CloneMap.Layers.IndexOf(layer)].Label = layer.LayerName;
            psd.Add(image[CloneMap.Layers.IndexOf(layer)]);
        }
    }

    using (MagickImage result = psd.Flatten())
    {
        psd.Write(filepath + "\\" + filename + "_" + filenumber + fileext);
    }                                
}

Viewing all articles
Browse latest Browse all 3693

Trending Articles