Exemplo n.º 1
0
        public IFormat HandleRequest(int format)
        {
            IFormat extension = null;

            if (format == 7)
            {
                extension = new PsdFormat();
            }
            else if (Successor != null)
            {
                Successor.HandleRequest(format);
            }
            return(extension);
        }
Exemplo n.º 2
0
        public static IFormat ChooseFormat(int index)
        {
            IFormat format = null;

            switch (index)
            {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5: format = new BaseFormats(); break;

            case 6: format = new XpsFormat(); break;

            case 7: format = new PdfFormat(); break;

            case 8: format = new PsdFormat(); break;

            default: break;
            }

            return(format);
        }
            /// <summary>
            /// Reads Image Resource Blocks (native PSD metadata) in PSD format
            /// </summary> 
            public static void ReadImageResourceBlocks()
            {
                try
                {
                    //ExStart:ReadImageResourceBlocksInPSD
                    // initialize PsdFormat
                    PsdFormat psdFormat = new PsdFormat(Common.MapSourceFilePath(filePath));

                    // check if contain Image Resource Blocks
                    if (psdFormat.HasImageResourceBlocks)
                    {
                        // get native photoshop metadata
                        ImageResourceMetadata imageResource = psdFormat.GetImageResourceBlocks();

                        // display all blocks
                        foreach (ImageResourceBlock imageResourceBlock in imageResource.Blocks)
                        {
                            Console.WriteLine("Id: {0}, size: {1}", imageResourceBlock.DefinedId, imageResourceBlock.DataSize);

                            // create your own logic to parse image resource block
                            byte[] data = imageResourceBlock.Data;
                        }
                    }
                    //ExEnd:ReadImageResourceBlocksInPSD
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Gets IPTC metadata from PSD file
            /// </summary> 
            public static void ReadIPTCMetadata()
            {
                try
                {
                    //ExStart:GetIPTCMetadataInPSD
                    // initialize PsdFormat
                    PsdFormat psdFormat = new PsdFormat(Common.MapSourceFilePath(filePath));

                    // check if PSD contains IPTC metadata
                    if (psdFormat.HasIptc)
                    {
                        // get iptc collection
                        IptcCollection iptc = psdFormat.GetIptc();

                        // and display it
                        foreach (IptcProperty iptcProperty in iptc)
                        {
                            Console.Write("Tag id: {0}, name: {1}", iptcProperty.TagId, iptcProperty.Name);
                        }
                    }
                    //ExEnd:GetIPTCMetadataInPSD
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Gets XMP Properies in PSD file
            /// </summary> 
            public static void GetXMPProperties()
            {
                try
                {
                    //ExStart:GetXMPPropertiesPSDFormat
                    // initialize PsdFormat 
                    PsdFormat psdFormat = new PsdFormat(Common.MapSourceFilePath(filePath));

                    // get photoshop namespace
                    var photoshopMetadata = psdFormat.XmpValues.Schemes.Photoshop;

                    // get color mode
                    //ColorMode colorMode = (ColorMode)photoshopMetadata.ColorMode;
                    PhotoshopColorMode colorMode = (PhotoshopColorMode)photoshopMetadata.ColorMode;

                    // get IIC profile
                    var iicProfile = photoshopMetadata.ICCProfile;
                    //ExEnd:GetXMPPropertiesPSDFormat
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            //ExEnd:SourcePSDFilePath

            /// <summary>
            /// Gets Psd Info
            /// </summary> 
            public static void GetPsdInfo()
            {
                try
                {
                    //ExStart:GetPsdInfo
                    // initialize PsdFormat 
                    PsdFormat psdFormat = new PsdFormat(Common.MapSourceFilePath(filePath));

                    // get PSD info
                    PsdMetadata metadata = psdFormat.GetPsdInfo();

                    if (metadata != null)
                    {
                        // get ChannelsCount 
                        Console.WriteLine("Channels Count: {0}", metadata.ChannelsCount);
                        // get ColorMode 
                        Console.WriteLine("Color Mode: {0}", metadata.ColorMode);
                        // get CompressionMethod 
                        Console.WriteLine("Compression Method: {0}", metadata.CompressionMethod);
                        // get Height 
                        Console.WriteLine("Height: {0}", metadata.Height);
                        // get Width 
                        Console.WriteLine("Width: {0}", metadata.Width);
                        // get PhotoshopVersion 
                        Console.WriteLine("Photoshop Version: {0}", metadata.PhotoshopVersion);

                    }
                    //ExEnd:GetPsdInfo
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }