Loading Raster Layers

Graphics Mill supports loading layers of different types from PSD files. This article describes how to work with raster layers.

To start reading a PSD file use the PsdReader(String) constructor, which accepts a filename as an argument.

Note

While a PSD file is opened by Graphics Mill, no other application can delete or modify the file.

To access layers use the PsdReader.Frames property which returns a collection of PsdFrame instances. For each raster layer the following data can be obtained:

  • bitmap (the GetBitmap() method),
  • name (the Name property),
  • dimensions (the Height and the Width properties),
  • pixel format (the PixelFormat property),
  • position of the upper-left corner (the X and the Y properties),
  • visibility (the IsVisible property).
Note

Check the layer type before extracting a bitmap. It is impossible to extract a bitmap from a layer of an unknown type.

The following code opens a PSD file, iterates through its layers, and saves bitmaps from the raster layers to separate PNG files:

C#
//create PSD reader
using (var reader = new PsdReader(@"Images\BusinessCard.psd"))
{
    //read layers and save raster layers in PNG files
    for (int i = 0; i < reader.Frames.Count; i++)
    {
        using (var frame = reader.Frames[i])
        {
            Console.WriteLine("Frame " + frame.Index + " is processing. Frame type is " + frame.Type + ".");

            if (frame.Type == FrameType.Raster)
            {
                using (var bitmap = frame.GetBitmap())
                {
                    bitmap.Save(@"Images\Output\frame_" + i + ".png");
                }
            }
        }
    }
}

See Also

Reference

Manual