public static void Run()
        {
            //ExStart:AddThumbnailToJFIFSegment
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_PSD();

            // Load PSD image.
            using (PsdImage image = (PsdImage)Image.Load(dataDir + "1280px-Zebras_Serengeti.psd"))
            {
                // Iterate over resources.
                foreach (var resource in image.ImageResources)
                {
                    // Find thumbnail resource. Typically they are in the Jpeg file format.
                    if (resource is ThumbnailResource || resource is Thumbnail4Resource)
                    {
                        // Adjust thumbnail data.
                        var thumbnail      = (ThumbnailResource)resource;
                        var jfifData       = new FileFormats.Jpeg.JFIFData();
                        var thumbnailImage = new JpegImage(100, 100);
                        try
                        {
                            // Fill thumbnail data.
                            int[] pixels = new int[thumbnailImage.Width * thumbnailImage.Height];
                            for (int i = 0; i < pixels.Length; i++)
                            {
                                pixels[i] = i;
                            }

                            // Assign thumbnail data.
                            thumbnailImage.SaveArgb32Pixels(thumbnailImage.Bounds, pixels);
                            jfifData.Thumbnail         = thumbnailImage;
                            jfifData.XDensity          = 1;
                            jfifData.YDensity          = 1;
                            thumbnail.JpegOptions.Jfif = jfifData;
                        }
                        catch
                        {
                            thumbnailImage.Dispose();
                            throw;
                        }
                    }
                }

                image.Save();
            }
            //ExEnd:AddThumbnailToJFIFSegment
        }
Esempio n. 2
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            //ExStart:ColorConversionUsingICCProfiles

            // Create a new JpegImage.
            using (JpegImage image = new JpegImage(500, 500))
            {
                // Fill image data.
                int   count   = image.Width * image.Height;
                int[] pixels  = new int[count];
                int   r       = 0;
                int   g       = 0;
                int   b       = 0;
                int   channel = 0;
                for (int i = 0; i < count; i++)
                {
                    if (channel % 3 == 0)
                    {
                        r++;
                        if (r == 256)
                        {
                            r = 0;
                            channel++;
                        }
                    }
                    else if (channel % 3 == 1)
                    {
                        g++;
                        if (g == 256)
                        {
                            g = 0;
                            channel++;
                        }
                    }
                    else
                    {
                        b++;
                        if (b == 256)
                        {
                            b = 0;
                            channel++;
                        }
                    }

                    pixels[i] = Color.FromArgb(r, g, b).ToArgb();
                }

                // Save the newly created pixels.
                image.SaveArgb32Pixels(image.Bounds, pixels);

                // Save the resultant image with default Icc profiles.
                image.Save(dataDir + "Default_profiles.jpg");

                // Update color profile.
                StreamSource rgbprofile  = new StreamSource(File.OpenRead(dataDir + "eciRGB_v2.icc"));
                StreamSource cmykprofile = new StreamSource(File.OpenRead(dataDir + "ISOcoated_v2_FullGamut4.icc"));
                image.RgbColorProfile  = rgbprofile;
                image.CmykColorProfile = cmykprofile;

                // Save the resultant image with new YCCK profiles. You will notice differences in color values if compare the images.
                JpegOptions options = new JpegOptions();
                options.ColorType = JpegCompressionColorMode.Ycck;
                image.Save(dataDir + "Ycck_profiles.jpg", options);
            }


            //ExEnd:ColorConversionUsingICCProfiles
        }