//ExEnd:SourceJpegFilePath
            #region working with XMP data
            /// <summary>
            ///Gets XMP properties from Jpeg file
            /// </summary>
            public static void GetXMPProperties()
            {
                try
                {
                    //ExStart:GetXmpPropertiesJpegImage
                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // get XMP data
                    XmpProperties xmpProperties = jpegFormat.GetXmpProperties();

                    // show XMP data
                    foreach (string key in xmpProperties.Keys)
                    {
                        try
                        {
                            XmpNodeView xmpNodeView = xmpProperties[key];
                            Console.WriteLine("[{0}] = {1}", xmpNodeView.Name, xmpNodeView.Value);
                        }
                        catch { }
                    }
                    //ExEnd:GetXmpPropertiesJpegImage
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
Exemplo n.º 2
0
        /// <summary>
        /// 压缩处理
        /// </summary>
        /// <param name="photoBytes">bytes</param>
        /// <returns></returns>
        private MemoryStream ComPress(byte[] photoBytes)
        {
            // 检测格式
            ISupportedImageFormat format = new JpegFormat {
                Quality = 70
            };
            Size size = new Size(150, 0);

            using (MemoryStream inStream = new MemoryStream(photoBytes))
            {
                using (MemoryStream outStream = new MemoryStream())
                {
                    // 使用重载初始化ImageFactory以保留EXIF元数据。
                    using (ImageFactory imageFactory = new ImageFactory(true))
                    {
                        // 加载,调整大小,设置格式和质量并保存图像。
                        imageFactory.Load(inStream)
                        .Resize(size)
                        .Format(format)
                        .Save(outStream);
                        return(outStream);
                    }
                }
            }
        }
            /// <summary>
            /// Gets Exif info from Jpeg file
            /// </summary>
            public static void GetExifInfo()
            {
                try
                {
                    //ExStart:GetExifPropertiesJpegImage
                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // get EXIF data
                    JpegExifInfo exif = (JpegExifInfo)jpegFormat.GetExifInfo();

                    if (exif != null)
                    {
                        // get artist
                        Console.WriteLine("Artist: {0}", exif.Artist);
                        // get description
                        Console.WriteLine("Description: {0}", exif.ImageDescription);
                        // get user's comment
                        Console.WriteLine("User Comment: {0}", exif.UserComment);
                        // get user's Model
                        Console.WriteLine("Model: {0}", exif.Model);
                        // get user's Make
                        Console.WriteLine("Make: {0}", exif.Make);
                        // get user's CameraOwnerName
                        Console.WriteLine("CameraOwnerName: {0}", exif.CameraOwnerName);
                    }
                    //ExEnd:GetExifPropertiesJpegImage
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
        private void DeepfryImage(string imageFilename, int numPasses = 1)
        {
            for (int i = 0; i < numPasses; i++)
            {
                var imageBytes = File.ReadAllBytes(imageFilename);
                var format     = new JpegFormat {
                    Quality = 10
                };

                using (var inStream = new MemoryStream(imageBytes))
                    using (var outStream = new MemoryStream())
                        using (var saveFileStream = new FileStream(imageFilename, FileMode.Open, FileAccess.Write))
                            using (var imageFactory = new ImageFactory(preserveExifData: true))
                            {
                                imageFactory.Load(inStream)
                                .Saturation(100)
                                .Contrast(100)
                                .Gamma(1.0f)
                                //.GaussianSharpen(30)
                                .Format(format)
                                .Save(outStream);
                                outStream.CopyTo(saveFileStream);
                            }
            }
        }
Exemplo n.º 5
0
        private void Recompress(string sourceName, string destName, int width, int height, int quality)
        {
            ISupportedImageFormat format = new JpegFormat {
                Quality = quality
            };
            var size = new Size(width, height);
            var rl   = new ResizeLayer(size, ResizeMode.Crop);

            using (FileStream src = File.OpenRead(Path.Combine(_baseDir, sourceName)))
            {
                string destPath = Path.Combine(_baseDir, destName);
                if (File.Exists(destPath))
                {
                    File.Delete(destPath);
                }
                using (FileStream dest = File.Create(destPath))
                {
                    using (var factory = new ImageFactory())
                    {
                        factory
                        .Load(src)
                        .Resize(rl)
                        .Format(format)
                        .Save(dest);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public Image crop(Image img, Rectangle rect)
        {
            byte[] photoBytes = imageToByteArray(img);

            // Format is automatically detected though can be changed.
            ISupportedImageFormat format = new JpegFormat {
                Quality = 70
            };

            Image resultingImage = default(Image);

            using (MemoryStream inStream = new MemoryStream(photoBytes))
            {
                using (MemoryStream outStream = new MemoryStream())
                {
                    // Initialize the ImageFactory using the overload to preserve EXIF metadata.
                    using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
                    {
                        // Load, resize, set the format and quality and save an image.
                        imageFactory.Load(inStream)
                        .Crop(rect);


                        resultingImage = imageFactory.Image;
                    }
                }
            }

            return(resultingImage);
        }
Exemplo n.º 7
0
        public void ImageProcessorTest1()
        {
            string imagePath = @"D:\test\img\123.jpg";
            //string saveImagePath = @"D:\test\img\123N555.jpg";

            //string imagePath = @"D:\test\1\xx.png";
            string saveImagePath = @"D:\test\1\xx_new3.png";

            byte[] photoBytes = File.ReadAllBytes(imagePath);
            // Format is automatically detected though can be changed.
            ISupportedImageFormat format = new JpegFormat {
            };

            //Size size = new Size(150, 0);
            using (MemoryStream inStream = new MemoryStream(photoBytes))
            {
                using (MemoryStream outStream = new MemoryStream())
                {
                    // Initialize the ImageFactory using the overload to preserve EXIF metadata.
                    using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
                    {
                        // Load, resize, set the format and quality and save an image.
                        imageFactory.Load(inStream)
                        .Filter(MatrixFilters.GreyScale)
                        .Format(format)
                        .Save(saveImagePath);
                    }
                    // Do something with the stream.
                }
            }
        }
Exemplo n.º 8
0
        public void SaveUserImage(Stream image, string imagePath)
        {
            byte[] photoBytes = ReadFully(image);
            // Format is automatically detected though can be changed.
            ISupportedImageFormat format = new JpegFormat {
                Quality = 70
            };
            Size size = new Size(150, 0);

            using (MemoryStream inStream = new MemoryStream(photoBytes))
            {
                using (MemoryStream outStream = new MemoryStream())
                {
                    // Initialize the ImageFactory using the overload to preserve EXIF metadata.
                    using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
                    {
                        // Load, resize, set the format and quality and save an image.
                        imageFactory.Load(inStream)
                        .Resize(size)
                        .Format(format)
                        .Save(outStream);
                    }
                    using (FileStream file = new FileStream(Root + "test.jpg", FileMode.Open, FileAccess.Read))
                    {
                        byte[] bytes = new byte[file.Length];
                        file.Read(bytes, 0, (int)file.Length);
                        outStream.Write(bytes, 0, (int)file.Length);
                    }
                }
            }
        }
Exemplo n.º 9
0
        public static byte[] GetPreview(byte[] original, int quality)
        {
            using (var inputStream = new MemoryStream(original))
            {
                using (var outputStream = new MemoryStream())
                {
                    using (var factory = new ImageFactory())
                    {
                        // create a format object
                        // the preview will use Jpeg so that we can reduce the quality
                        // for faster rendering, the final product will use the original
                        // format and the original quality
                        var format = new JpegFormat
                        {
                            Quality = quality
                        };

                        // load the image and format it
                        factory.Load(inputStream)
                        .Format(format)
                        .Save(outputStream);
                    }

                    var length = (int)outputStream.Length;

                    var bytes = new byte[length];

                    outputStream.Read(bytes, 0, length);

                    return(bytes);
                }
            }
        }
Exemplo n.º 10
0
        private ISupportedImageFormat GetFormat(string extension, ImageInstruction ins)
        {
            ISupportedImageFormat format = null;

            if (extension.Equals(".jpg", StringComparison.OrdinalIgnoreCase) || extension.Equals(".jpeg", StringComparison.OrdinalIgnoreCase))
            {
                format = new JpegFormat {
                    Quality = ins.JpegQuality
                }
            }
            ;
            else
            if (extension.Equals(".gif", StringComparison.OrdinalIgnoreCase))
            {
                format = new GifFormat {
                }
            }
            ;
            else if (extension.Equals(".png", StringComparison.OrdinalIgnoreCase))
            {
                format = new PngFormat {
                }
            }
            ;

            return(format);
        }
Exemplo n.º 11
0
        private void ProcessImage(string inputImage, string outputImage)
        {
            byte[] photoBytes = File.ReadAllBytes(inputImage);

            ISupportedImageFormat format = new JpegFormat {
                Quality = 70
            };
            Size size = new Size(EDEN_EDITOR_PREVIEW_WIDTH, EDEN_EDITOR_PREVIEW_HEIGHT);

            using (MemoryStream inStream = new MemoryStream(photoBytes))
            {
                using (MemoryStream outStream = new MemoryStream())
                {
                    using (ImageFactory imageFactory = new ImageFactory())
                    {
                        imageFactory.Load(inStream)
                        .Resize(size)
                        .Format(format)
                        .Save(outStream);
                    }

                    using (FileStream file = new FileStream(outputImage, FileMode.Create, FileAccess.Write))
                    {
                        outStream.WriteTo(file);
                    }
                }
            }
        }
Exemplo n.º 12
0
        public static byte[] Shadowing(byte[] image, int percents)
        {
            byte[] photoBytes = image;
            byte[] newImg;

            ISupportedImageFormat format = new JpegFormat {
                Quality = 70
            };

            using (MemoryStream inStream = new MemoryStream(photoBytes))
            {
                using (MemoryStream outStream = new MemoryStream())
                {
                    using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
                    {
                        imageFactory.Load(inStream)
                        .Brightness(-percents)
                        .Format(format)
                        .Save(outStream);
                    }
                    newImg = outStream.ToArray();
                }
            }
            return(newImg);
        }
        public HttpResponseMessage GetThumbnail(string imagePath, int width)
        {
            if (false == string.IsNullOrWhiteSpace(imagePath) && imagePath.IndexOf("{{") < 0)
            {
                var image = Image.FromFile(System.Web.Hosting.HostingEnvironment.MapPath(imagePath));

                MemoryStream outStream = new MemoryStream();

                byte[] photoBytes            = File.ReadAllBytes(System.Web.Hosting.HostingEnvironment.MapPath(imagePath)); // change imagePath with a valid image path
                ISupportedImageFormat format = new JpegFormat {
                    Quality = 70
                };                                                              // convert to jpg

                var inStream = new MemoryStream(photoBytes);

                var imageFactory = new ImageFactory(preserveExifData: true);

                Size size = ResizeKeepAspect(image.Size, width, width);

                ResizeLayer resizeLayer = new ResizeLayer(size, ResizeMode.Max);
                imageFactory.Load(inStream)
                .Resize(resizeLayer)
                .Format(format)
                .Save(outStream);

                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = new StreamContent(outStream);
                response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/png");
                return(response);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Takes manufacturer as input and returns photos made on particular camera
        /// </summary>
        /// <param name="manufacturer">Camera manufacturer name</param>
        public void FilterByCameraManufacturer(string manufacturer)
        {
            // Map directory in source folder
            string sourceDirectoryPath = Common.MapSourceFilePath(this.PhotosDirectory);

            // get jpeg files
            string[] files = Directory.GetFiles(sourceDirectoryPath, "*.jpg");

            List <string> result = new List <string>();

            foreach (string path in files)
            {
                // recognize file
                FormatBase format = FormatFactory.RecognizeFormat(path);

                // casting to JpegFormat
                if (format is JpegFormat)
                {
                    JpegFormat jpeg = (JpegFormat)format;

                    // get exif data
                    JpegExifInfo exif = (JpegExifInfo)jpeg.GetExifInfo();

                    if (exif != null)
                    {
                        if (string.Compare(exif.Make, manufacturer, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            // add file path to list
                            result.Add(Path.GetFileName(path));
                        }
                    }
                }
            }
            Console.WriteLine(string.Join("\n", result));
        }
        public Image Optimize(string inputfile, int finalsize = 1024, bool retobj = false, float hdpi = 0, float vdpi = 0)
        {
            var outputpath = inputfile.GetOutputPath(ActionType.OPTIMIZE);

            ISupportedImageFormat format = new JpegFormat();
            Size size = new Size(finalsize, 0);

            using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
            {
                if (retobj)
                {
                    using (Image sourceImg = imageFactory.Load(inputfile).Resize(size).Format(format).Image)
                    {
                        var clonedImg = new Bitmap(sourceImg.Width, sourceImg.Height, PixelFormat.Format32bppArgb);

                        clonedImg.SetResolution(hdpi == 0 ? Image.FromFile(inputfile).HorizontalResolution : hdpi, vdpi == 0 ? Image.FromFile(inputfile).VerticalResolution : vdpi);

                        using (var copy = Graphics.FromImage(clonedImg))
                        {
                            copy.DrawImage(sourceImg, 0, 0);
                        }

                        return(clonedImg);
                    }
                }
                else
                {
                    imageFactory.Load(inputfile).Resize(size).Format(format).Save(outputpath);
                }

                return(imageFactory.Load(inputfile).Image);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Уменьшение размера файла.
        /// На вход принимает файл по типу FileInfo
        /// </summary>
        public static void ResizeImage(FileInfo fileInfo)
        {
            var isCorrect = false;

            if (SizeCorrection(fileInfo))
            {
                isCorrect = true;
            }
            ISupportedImageFormat format = new JpegFormat {
                Quality = 70
            };

            using (MemoryStream inStream = new MemoryStream(fileInfo.PhotoBytes))
            {
                using (FileStream outStream = File.Create($"{DirectoryFind(fileInfo)}{fileInfo.FileName}.{format.DefaultExtension}"))
                {
                    using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
                    {
                        if (isCorrect)
                        {
                            imageFactory.Load(inStream).Format(format).Save(outStream);
                        }
                        else
                        {
                            Size size = imageFactory.Load(inStream).Image.Size / 2;
                            imageFactory.Load(inStream).Resize(size).Format(format).Save(outStream);
                        }
                    }
                }
            }
        }
Exemplo n.º 17
0
        public void saveSmallFileToBoardFolder(string shortName,
                                               HttpPostedFileBase postFile,
                                               double time,
                                               string uploadName)
        {
            long   iTime         = Convert.ToInt64(time * 1000);
            string uploadsFolder = HttpContext.Current.Server
                                   .MapPath("~/Content/Images");

            System.IO.Directory.CreateDirectory(uploadsFolder);
            string folder = Path.Combine(uploadsFolder, shortName);

            System.IO.Directory.CreateDirectory(folder);
            string justFile = iTime + "s.jpg";
            string fileName = Path.Combine(folder, justFile);
            ISupportedImageFormat format = new JpegFormat {
                Quality = 70
            };
            Size size = new Size(250, 0);

            using (FileStream outStream = new FileStream(fileName, FileMode.Create))
            {
                using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
                {
                    imageFactory.Load(postFile.InputStream)
                    .Resize(size)
                    .Format(format)
                    .Save(outStream);
                }
            }
        }
Exemplo n.º 18
0
        private static Stream GetResizeImageStream(byte[] imageData, int height, int width)
        {
            ISupportedImageFormat format = new JpegFormat {
                Quality = 70
            };
            Size size = new Size(width, height);

            using (MemoryStream inStream = new MemoryStream(imageData))
            {
                using (MemoryStream outStream = new MemoryStream())
                {
                    // Initialize the ImageFactory using the overload to preserve EXIF metadata.
                    using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
                    {
                        // Load, resize, set the format and quality and save an image.
                        imageFactory.Load(inStream)
                        .Resize(size)
                        .Format(format)
                        .Save(outStream);

                        return(outStream);
                    }
                    // Do something with the stream.
                }
            }
        }
        public async Task ResizeCache()
        {
            var fileName       = Guid.NewGuid().ToString();
            var width          = (ushort)122;
            var format         = new JpegFormat();
            var id             = Guid.NewGuid();
            var versionName    = Guid.NewGuid().ToString();
            var cachedFileName = Guid.NewGuid().ToString();

            var imaging = Substitute.For <IImaging>();

            imaging.Get(Naming.DefaultExtension, 85).Returns(format);
            imaging.Resize(Arg.Any <byte[]>(), Arg.Any <ImageVersion>());
            var container = Substitute.For <IContainer>();
            var table     = Substitute.For <ITableStorage>();
            var queue     = Substitute.For <IStorageQueue>();
            var naming    = Substitute.For <INaming>();

            naming.FromFileName(fileName).Returns(id);
            naming.DynamicVersion(format.DefaultExtension, 85, width, 0).Returns(versionName);
            naming.FileName(id, versionName, format.DefaultExtension).Returns(cachedFileName);

            var store  = new DataStore(imaging, container, table, queue, naming);
            var result = await store.Resize(fileName, width, 0, Naming.DefaultExtension, 85, true);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Raw);
            Assert.AreEqual(format.MimeType, result.MimeType);

            naming.Received().FromFileName(fileName);
            naming.Received().DynamicVersion(format.DefaultExtension, 85, width, 0);
            naming.Received().FileName(id, versionName, format.DefaultExtension);
            imaging.Received().Get(Naming.DefaultExtension, 85);
            imaging.Received().Resize(Arg.Any <byte[]>(), Arg.Any <ImageVersion>());
        }
Exemplo n.º 20
0
        public ActionResult Download(string id, string fileName)
        {
            if (!string.IsNullOrEmpty(Request.Headers["If-Modified-Since"]))
            {
                Response.StatusCode        = 304;
                Response.StatusDescription = "Not Modified";
                Response.AddHeader("Content-Length", "0");
                return(Content(String.Empty));
            }

            var file = AsefianFileContextHelper.GetFile(id, fileName);

            try
            {
                MemoryStream outStream = new MemoryStream();

                using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false))
                {
                    ISupportedImageFormat format = new JpegFormat {
                        Quality = 70
                    };

                    imageFactory.Load(file.Data)
                    .Format(format)
                    .Save(outStream);

                    return(File(outStream, MimeMapping.GetMimeMapping(fileName)));
                }
            }
            catch (Exception)
            {
                return(File(file.Data, file.MimeType));
            }
        }
Exemplo n.º 21
0
        public void ImageProcessorSandbox()
        {
            var file       = @"E:\CONTENT\CURSOR1.BMP";
            var size       = new Size(150, 0);
            var photoBytes = File.ReadAllBytes(file);
            // Format is automatically detected though can be changed.
            ISupportedImageFormat format = new JpegFormat {
                Quality = 100
            };

            using (var inStream = new MemoryStream(photoBytes))
            {
                using (var outStream = new MemoryStream())
                {
                    // Initialize the ImageFactory using the overload to preserve EXIF metadata.
                    using (var imageFactory = new ImageFactory(preserveExifData: true))
                    {
                        // Load, resize, set the format and quality and save an image.
                        imageFactory.Load(inStream)
                        .Resize(size)
                        .Format(format)
                        .Save(outStream);
                    }
                    // Do something with the stream.
                    var fileStream = File.Create(@".\CURSOR1.BMP");
                }
            }
        }
Exemplo n.º 22
0
        public void SavePicture(HttpPostedFileBase file, string name, Size size, string formatFile = "jpg")
        {
            if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
            {
                // Format is automatically detected though can be changed.
                ISupportedImageFormat format = new JpegFormat {
                    Quality = 90
                };

                if (formatFile == "png")
                {
                    format = new PngFormat()
                    {
                        Quality = 90
                    }
                }
                ;

                //https://naimhamadi.wordpress.com/2014/06/25/processing-images-in-c-easily-using-imageprocessor/
                // Initialize the ImageFactory using the overload to preserve EXIF metadata.
                using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
                {
                    var path = Path.Combine(Server.MapPath("~/images/community"), string.Format("{0}.{1}", name, formatFile));

                    // Load, resize, set the format and quality and save an image.
                    imageFactory.Load(file.InputStream)
                    .Resize(size)
                    .Format(format)
                    .Save(path);
                }
            }
        }
Exemplo n.º 23
0
 public void TestCompress()
 {
     for (int i = 10; i <= 100;)
     {
         var    k          = (i < 90 ? i += 10 : i += 1);
         var    distPath   = @"C:\Users\Public\Pictures\Sample Pictures\a\Jellyfish-compress-" + i + ".jpg";
         var    srcPath    = @"C:\Users\Public\Pictures\Sample Pictures\Jellyfish.bmp";
         byte[] photoBytes = File.ReadAllBytes(srcPath);
         // Format is automatically detected though can be changed.
         ISupportedImageFormat format = new JpegFormat {
             Quality = i
         };
         using (MemoryStream inStream = new MemoryStream(photoBytes))
         {
             using (MemoryStream outStream = new MemoryStream())
             {
                 // Initialize the ImageFactory using the overload to preserve EXIF metadata.
                 using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
                 {
                     // Load, resize, set the format and quality and save an image.
                     imageFactory.Load(inStream)
                     //.Resize(new Size(1000, 800))
                     .Format(format)
                     .Save(distPath);
                 }
                 // Do something with the stream.
             }
         }
     }
 }
            //ExEnd:SourceJpegFilePath
            #region working with XMP data
            /// <summary>
            ///Gets XMP properties from Jpeg file
            /// </summary> 
            public static void GetXMPProperties()
            {
                try
                {
                    //ExStart:GetXmpPropertiesJpegImage
                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // get XMP data
                    XmpProperties xmpProperties = jpegFormat.GetXmpProperties();

                    // show XMP data
                    foreach (string key in xmpProperties.Keys)
                    {
                        try
                        {
                            XmpNodeView xmpNodeView = xmpProperties[key];
                            Console.WriteLine("[{0}] = {1}", xmpNodeView.Name, xmpNodeView.Value);
                        }
                        catch { }
                    }
                    //ExEnd:GetXmpPropertiesJpegImage
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
Exemplo n.º 25
0
        /// <summary>
        /// Method used to crop image.
        /// </summary>
        /// <param name="inputImagePathString">input image path</param>
        /// <param name="outputImagePathName">ouput image path</param>
        /// <param name="x1">x</param>
        /// <param name="y1">y</param>
        /// <param name="width">widht of cropped image</param>
        /// <param name="height">height of cropped image</param>
        public static void CropImage(string inputImagePathString, String outputImagePathName, int x1, int y1, int width, int height)
        {
            byte[] photoBytes = File.ReadAllBytes(inputImagePathString);
            // Format is automatically detected though can be changed.
            ISupportedImageFormat format = new JpegFormat {
                Quality = 70
            };
            Rectangle rectangle = new Rectangle(x1, y1, width, height);

            using (MemoryStream inStream = new MemoryStream(photoBytes))
            {
                using (MemoryStream outStream = new MemoryStream())
                {
                    // Initialize the ImageFactory using the overload to preserve EXIF metadata.
                    using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
                    {
                        // Load, resize, set the format and quality and save an image.
                        imageFactory.Load(inStream)
                        .Crop(rectangle)
                        .Format(format)
                        .Save(outStream);

                        FileStream fileStream = new FileStream(outputImagePathName, FileMode.Create);
                        outStream.WriteTo(fileStream);
                        fileStream.Close();
                    }
                    // Do something with the stream.
                    outStream.Close();
                }
            }
        }
        private static ISupportedImageFormat GetFormatFromSelectedOutput(ImageFormat convertTo)
        {
            ISupportedImageFormat format = null;

            switch (convertTo.ToString())
            {
            case "Jpeg":
                format = new JpegFormat {
                };
                break;

            case "Png":
                format = new PngFormat {
                };
                break;

            case "Tiff":
                format = new TiffFormat {
                };
                break;

            default:
                break;
            }
            return(format);
        }
Exemplo n.º 27
0
        public ActionResult AgregarFotoPorfolio(EditarUsuarioModel modelo)
        {
            if (ModelState.IsValid)
            {
                HttpPostedFileBase file = modelo.File;

                Usuario usuarioActual = ObtenerUsuarioActual(User);

                if (file != null && file.ContentLength > 0)
                {
                    Guid   guid = Guid.NewGuid();
                    string str  = guid.ToString();

                    string path = Path.Combine(Server.MapPath("~/PorfoliosPictures"), str + ".jpg");

                    using (MemoryStream outStream = new MemoryStream())
                    {
                        using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false))
                        {
                            Size size = new Size(1000, 1000);
                            ISupportedImageFormat format = new JpegFormat {
                                Quality = 80
                            };
                            imageFactory.Load(file.InputStream)
                            .Constrain(size)
                            .BackgroundColor(Color.White)
                            .Format(format)
                            .Save(path);
                        }
                    }


                    //crear nueva foto porfolio
                    FotoPorfolio foto = new FotoPorfolio();
                    foto.Usuario   = usuarioActual;
                    foto.UsuarioId = usuarioActual.Id;
                    foto.Url       = str;

                    //agregarla a la lista
                    //if (usuarioActual.Fotos == null)
                    //{
                    // usuarioActual.Fotos = new List<FotoPorfolio>();
                    //}
                    usuarioActual.Fotos.Add(foto);

                    //db.Usuarios.Add(usuarioActual);
                    //db.SaveChanges();

                    db.FotosPorfolio.Add(foto);
                    db.SaveChangesAsync();


                    return(RedirectToAction("Index"));

                    //return View("Usuario", usuarioActual);
                }
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 28
0
        public ActionResult ModificarUsuario(EditarUsuarioModel modelo)
        {
            if (ModelState.IsValid)
            {
                HttpPostedFileBase file     = modelo.File;
                Usuario            userInfo = modelo.MyUserInfo;

                if (userInfo.Fotos == null)
                {
                    userInfo.Fotos = new List <FotoPorfolio>();
                }


                if (file != null && file.ContentLength > 0)
                {
                    Guid   guid = Guid.NewGuid();
                    string str  = guid.ToString();

                    string path = Path.Combine(Server.MapPath("~/ProfilePictures"), str + ".jpg");

                    using (MemoryStream outStream = new MemoryStream())
                    {
                        using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false))
                        {
                            Size size = new Size(200, 200);
                            ISupportedImageFormat format = new JpegFormat {
                                Quality = 80
                            };
                            imageFactory.Load(file.InputStream)
                            .Constrain(size)
                            .BackgroundColor(Color.White)
                            .Format(format)
                            .Save(path);
                        }
                    }

                    userInfo.URLFotoPerfil = str;
                }
                Usuario usuarioActual = ObtenerUsuarioActual(User);

                //copiar una por una las propiedades al usuario actual
                usuarioActual.Apellido      = userInfo.Apellido;
                usuarioActual.Descripcion   = userInfo.Descripcion;
                usuarioActual.Email         = userInfo.Descripcion;
                usuarioActual.Facebook      = userInfo.Facebook;
                usuarioActual.Instagram     = userInfo.Instagram;
                usuarioActual.Nombre        = userInfo.Nombre;
                usuarioActual.Rol           = userInfo.Rol;
                usuarioActual.Telefono      = userInfo.Telefono;
                usuarioActual.URLFotoPerfil = userInfo.URLFotoPerfil;
                usuarioActual.Website       = userInfo.Website;

                db.Entry(usuarioActual).State = EntityState.Modified;
                db.SaveChanges();

                return(View("Usuario", ObtenerUsuarioActual(User)));
            }
            return(View(modelo));
        }
Exemplo n.º 29
0
        public static void ConvertToJPGHQ(string path)
        {
            ISupportedImageFormat jpgFormat = new JpegFormat {
                Quality = 100
            };

            ConvertWebPToImage(path, jpgFormat, ".jpg");
        }
Exemplo n.º 30
0
        private void ConvertToJPGNQ(string path)
        {
            ISupportedImageFormat jpgFormat = new JpegFormat {
                Quality = 80
            };

            ConvertWebPToImage(path, jpgFormat, ".jpg");
        }
Exemplo n.º 31
0
        public void ResizeImg(string file)
        {
            var replace = true;

            if (file == "")
            {
                file = @"D:\img.jpeg";
            }
            var outfile = file;

            if (!replace)
            {
                outfile = file.Replace(".jpeg", "_out" + DateTime.Now.ToString("MMddHHmmss") + ".jpeg");
            }

            var minDimMax = 256;

            byte[] photoBytes = File.ReadAllBytes(file);

            using (MemoryStream inStream = new MemoryStream(photoBytes))
            {
                using (var img = System.Drawing.Image.FromStream(inStream))
                {
                    var w = img.Width;
                    var h = img.Height;
                    //if (w > minDimMax && h > minDimMax)
                    //{
                    // Format is automatically detected though can be changed.
                    ISupportedImageFormat format = new JpegFormat {
                        Quality = 90
                    };

                    Size size1 = new Size(minDimMax, minDimMax * 10);
                    Size size2 = new Size(minDimMax * 10, minDimMax);

                    var         resize1 = new ResizeLayer(size1, ResizeMode.Max);
                    var         resize2 = new ResizeLayer(size2, ResizeMode.Max);
                    ResizeLayer layer   = w < h ? resize1 : resize2;
                    using (MemoryStream outStream = new MemoryStream())
                    {
                        // Initialize the ImageFactory using the overload to preserve EXIF metadata.
                        using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true))
                        {
                            // Load, resize, set the format and quality and save an image.
                            imageFactory.Load(inStream)
                            .Resize(layer)
                            .Format(format)
                            .Save(outfile);
                        }
                    }
                    //}
                    //else if (!replace)
                    //{
                    //    File.Copy(file, outfile);
                    //}
                }
            }
        }
            /// <summary>
            /// Updates XMP data of Jpeg file and creates output file
            /// </summary> 
            public static void UpdateXMPProperties()
            {
                try
                {
                    //ExStart:UpdateXmpPropertiesJpegImage
                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // get xmp wrapper
                    XmpPacketWrapper xmpPacket = jpegFormat.GetXmpData();

                    // create xmp wrapper if not exists
                    if (xmpPacket == null)
                    {
                        xmpPacket = new XmpPacketWrapper();
                    }

                    // check if DublinCore schema exists
                    if (!xmpPacket.ContainsPackage(Namespaces.DublinCore))
                    {
                        // if not - add DublinCore schema
                        xmpPacket.AddPackage(new DublinCorePackage());
                    }

                    // get DublinCore package
                    DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore);
                     
                    string authorName = "New author"; 
                    string description = "New description";
                    string subject = "New subject" ;
                    string publisher = "New publisher";
                    string title = "New title";

                    // set author
                    dublinCorePackage.SetAuthor(authorName);
                    // set description
                    dublinCorePackage.SetDescription(description);
                    // set subject
                    dublinCorePackage.SetSubject(subject);
                    // set publisher
                    dublinCorePackage.SetPublisher(publisher);
                    // set title
                    dublinCorePackage.SetTitle(title);
                    // update XMP package
                    jpegFormat.SetXmpData(xmpPacket);

                    // commit changes
                    jpegFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:UpdateXmpPropertiesJpegImage
                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
        public void RemoveXMPData()
        {
            try
            {
                //ExStart:RemoveXMPData
                // create new instance of JpegFormat
                JpegFormat jpeg = new JpegFormat(@"C:\image.jpg");

                // use RemoveXmpData method to remove xmp metadata
                jpeg.RemoveXmpData();
                //ExEnd:RemoveXMPData
            }
            catch (Exception exp)
            {

            }
        }
            /// <summary>
            /// Detects barcodes in the Jpeg
            /// </summary>
            public static void DetectBarcodeinJpeg()
            {
                //ExStart:DetectBarcodeinJpeg
                // initialize JpegFormat
                JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(barcodeFilePath));

                // get barcodes:  UPCA, UPCE, EAN13
                string[] barCodes = jpegFormat.GetBarCodeTypes();

                Console.WriteLine("Barcode Detected:\n");

                for (int i = 0; i < barCodes.Length; i++)
                {
                    Console.WriteLine("Code Type: {0}", barCodes[i].ToString());
                }

                //ExEnd:DetectBarcodeinJpeg
            }
            /// <summary>
            ///Update ApplicationRecord/EnvelopeRecord datasets of IPTC metadata
            /// </summary>
            public static void UpdateIPTCMetadataOfApplicationRecord()
            {
                try
                {
                    //ExStart:UpdateIPTCMetadataOfApplicationRecord

                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // initialize dataset
                    IptcApplicationRecord applicationRecord = new IptcApplicationRecord();

                    // update category
                    applicationRecord.Category = "category";

                    // update copyright notice
                    applicationRecord.CopyrightNotice = "Aspose";

                    // update release date
                    applicationRecord.ReleaseDate = DateTime.Now;

                    // update iptc metadata
                    jpegFormat.UpdateIptc(applicationRecord);

                    // and commit changes
                    jpegFormat.Save();

                    //EXEnd:UpdateIPTCMetadataOfApplicationRecord
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Remove IPTC metadata of Jpeg file
            /// </summary>
            public static void RemoveIPTCMetadataOfJPEG()
            {
                try
                {
                    //ExStart:RemoveIPTCMetadataOfJPEG

                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // remove iptc
                    jpegFormat.RemoveIptc();

                    // and commit changes
                    jpegFormat.Save();
                    //ExEnd:RemoveIPTCMetadataOfJPEG
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Updates IPTC metadata of Jpeg file
            /// </summary>
            public static void UpdateIPTCMetadataOfJPEG()
            {
                try
                {
                    //ExStart:UpdateIPTCMetadataOfJPEG

                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // initialize IptcCollection
                    IptcCollection collection = new IptcCollection();

                    // add string property
                    collection.Add(new IptcProperty(2, "category", 15, "formats"));

                    // add integer property
                    collection.Add(new IptcProperty(2, "urgency", 10, 5));

                    // update iptc metadata
                    jpegFormat.UpdateIptc(collection);

                    // and commit changes
                    jpegFormat.Save();
                    //ExEnd:UpdateIPTCPhotoMetadataFromXMP
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Updates Basic Job XMP data of Jpeg file and creates output file
            /// </summary> 
            public static void UpdateBasicJobXMPProperties()
            {
                try
                {
                    //ExStart:UpdateBasicJobTicketXmpPropertiesJpegImage
                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // get xmp data
                    var xmp = jpegFormat.GetXmpData();

                    BasicJobTicketPackage package = null;

                    // looking for the BasicJob schema if xmp data is presented
                    if (xmp != null)
                    {
                        package = xmp.GetPackage(Namespaces.BasicJob) as BasicJobTicketPackage;
                    }
                    else
                    {
                        xmp = new XmpPacketWrapper();
                    }

                    if (package == null)
                    {
                        // create package if not exist
                        package = new BasicJobTicketPackage();

                        // and add it to xmp data
                        xmp.AddPackage(package);
                    }

                    // create array of jobs
                    Job[] jobs = new Job[1];
                    jobs[0] = new Job()
                    {
                        Id = "1",
                        Name = "test job"
                    };

                    // update schema
                    package.SetJobs(jobs);

                    // update xmp data
                    jpegFormat.SetXmpData(xmp);

                    // commit changes
                    jpegFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:UpdateBasicJobTicketXmpPropertiesJpegImage

                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Reads Image Resource Blocks (native PSD metadata) in Jpeg format
            /// </summary> 
            public static void ReadImageResourceBlocks()
            {
                try
                {
                    //ExStart:ReadImageResourceBlocksInJpeg
                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // check if JPEG contain photoshop metadata
                    if (jpegFormat.HasImageResourceBlocks)
                    {

                        // get native photoshop metadata
                        ImageResourceMetadata imageResource = jpegFormat.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:ReadImageResourceBlocksInJpeg
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Removes Exif info of Jpeg file and creates output file
            /// </summary> 
            public static void RemoveExifInfo()
            {
                try
                {
                    //ExStart:RemoveExifPropertiesJpegImage
                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // remove Exif info
                    jpegFormat.RemoveExifInfo();

                    // commit changes
                    jpegFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:RemoveExifPropertiesJpegImage
                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Removes GPS Data of Jpeg file and creates output file
            /// </summary> 
            public static void RemoveGPSData()
            {
                try
                {
                    //ExStart:RemoveGPSDataJpegImage
                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // get location
                    GpsLocation location = jpegFormat.GetGpsLocation();
                    if (location != null)
                    {
                        // remove GPS location
                        jpegFormat.RemoveGpsLocation();
                    }

                    // commit changes
                    jpegFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:RemoveGPSDataJpegImage

                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Updates Exif info using properties and creates output file
            /// </summary> 
            public static void UpdateExifInfoUsingProperties()
            {
                try
                {
                    //ExStart:UpdateExifValuesUsingPropertiesJpegImage
                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // get EXIF data
                    JpegExifInfo exif = (JpegExifInfo)jpegFormat.ExifValues;

                    // set artist
                    exif.Artist = "new test artist";

                    // set the name of the camera's owner
                    exif.CameraOwnerName = "new camera owner's name";

                    // set description
                    exif.ImageDescription = "update test description";

                    // commit changes
                    jpegFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:UpdateExifValuesUsingPropertiesJpegImage

                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Updates Exif info of Jpeg file and creates output file
            /// </summary> 
            public static void UpdateExifInfo()
            {
                try
                {
                    //ExStart:UpdateExifPropertiesJpegImage
                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // get EXIF data
                    JpegExifInfo exif = (JpegExifInfo)jpegFormat.GetExifInfo();
                    if (exif == null)
                    {
                        // initialize EXIF data if null
                        exif = new JpegExifInfo();
                    }

                    // set artist
                    exif.Artist = "Usman";
                    // set make
                    exif.Make = "ABC";
                    // set model
                    exif.Model = "S120";
                    // set the name of the camera's owner
                    exif.CameraOwnerName = "Owner";
                    // set description
                    exif.ImageDescription = "sample description";

                    // update EXIF data
                    jpegFormat.SetExifInfo(exif);

                    // commit changes
                    jpegFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:UpdateExifPropertiesJpegImage
                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Gets Exif info from Jpeg file
            /// </summary> 
            public static void GetExifInfo()
            {
                try
                {
                    //ExStart:GetExifPropertiesJpegImage
                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // get EXIF data
                    JpegExifInfo exif = (JpegExifInfo)jpegFormat.GetExifInfo();

                    if (exif != null)
                    {
                        // get artist 
                        Console.WriteLine("Artist: {0}", exif.Artist);
                        // get description 
                        Console.WriteLine("Description: {0}", exif.ImageDescription);
                        // get user's comment 
                        Console.WriteLine("User Comment: {0}", exif.UserComment);
                        // get user's Model 
                        Console.WriteLine("Model: {0}", exif.Model);
                        // get user's Make 
                        Console.WriteLine("Make: {0}", exif.Make);
                        // get user's CameraOwnerName 
                        Console.WriteLine("CameraOwnerName: {0}", exif.CameraOwnerName);
                        // get longitude
                        Console.WriteLine("Longitude: {0}", exif.GPSData.Longitude[0].ToString());
                        // get latitude
                        Console.WriteLine("Latitude: {0}", exif.GPSData.Latitude[0].ToString());
                    }
                    //ExEnd:GetExifPropertiesJpegImage
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Updates thumbnails in XMP data of Jpeg file and creates output file
            /// </summary> 
            public static void UpdateThumbnailInXMPData()
            {
                try
                {
                    //ExStart:UpdateThumbnailXmpPropertiesJpegImage

                    string path = Common.MapSourceFilePath(filePath);
                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // get image base64 string
                    string base64String;
                    using (Image image = Image.FromFile(path))
                    {
                        using (MemoryStream m = new MemoryStream())
                        {
                            image.Save(m, image.RawFormat);
                            byte[] imageBytes = m.ToArray();

                            // Convert byte[] to Base64 String
                            base64String = Convert.ToBase64String(imageBytes);
                        }
                    }

                    // create image thumbnail
                    Thumbnail thumbnail = new Thumbnail { ImageBase64 = base64String };

                    // initialize array and add thumbnail
                    Thumbnail[] thumbnails = new Thumbnail[1];
                    thumbnails[0] = thumbnail;

                    // update thumbnails property in XMP Basic schema
                    jpegFormat.XmpValues.Schemes.XmpBasic.Thumbnails = thumbnails;

                    // commit changes
                    jpegFormat.Save(Common.MapDestinationFilePath(filePath));

                    //ExEnd:UpdateThumbnailXmpPropertiesJpegImage

                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Removes Photoshop Metadata in Jpeg format
            /// </summary> 
            public static void RemovePhotoshopMetadata()
            {
                try
                {
                    //ExStart:RemovePhotoshopMetadataJpegImage
                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // remove photoshop metadata
                    jpegFormat.RemovePhotoshopData();

                    // and commit changes
                    jpegFormat.Save();
                    //ExEnd:RemovePhotoshopMetadataJpegImage 
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Updates XMP values of Jpeg file and creates output file
            /// </summary> 
            public static void UpdateXMPValues()
            {
                try
                {
                    //ExStart:UpdateXmpValuesJpegImage
                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    const string dcFormat = "test format";
                    string[] dcContributors = { "test contributor" };
                    const string dcCoverage = "test coverage";
                    const string phCity = "NY";
                    const string phCountry = "USA";
                    const string xmpCreator = "GroupDocs.Metadata";

                    jpegFormat.XmpValues.Schemes.DublinCore.Format = dcFormat;
                    jpegFormat.XmpValues.Schemes.DublinCore.Contributors = dcContributors;
                    jpegFormat.XmpValues.Schemes.DublinCore.Coverage = dcCoverage;
                    jpegFormat.XmpValues.Schemes.Photoshop.City = phCity;
                    jpegFormat.XmpValues.Schemes.Photoshop.Country = phCountry;
                    jpegFormat.XmpValues.Schemes.XmpBasic.CreatorTool = xmpCreator;

                    // commit changes
                    jpegFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:UpdateXmpValuesJpegImage
                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Read Specific Exif tag
            /// </summary>
            /// 
            public static void ReadExifTag()
            {
                JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                // get EXIF data
                ExifInfo exifInfo = jpegFormat.GetExifInfo();
                if (exifInfo != null)
                {
                    // get specific tag using indexer
                    TiffAsciiTag artist = (TiffAsciiTag)exifInfo[TiffTagIdEnum.Artist];
                    if (artist != null)
                    {
                        Console.WriteLine("Artist: {0}", artist.Value);
                    }
                }

            }
            /// <summary>
            /// Read All Exif tags
            /// </summary>
            /// 
            public static void ReadAllExifTags()
            {
                JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                // get EXIF data
                ExifInfo exifInfo = jpegFormat.GetExifInfo();
                if (exifInfo != null)
                {
                    TiffTag[] allTags = exifInfo.Tags;

                    foreach (TiffTag tag in allTags)
                    {
                        switch (tag.TagType)
                        {
                            case TiffTagType.Ascii:
                                TiffAsciiTag asciiTag = tag as TiffAsciiTag;
                                Console.WriteLine("Tag: {0}, value: {1}", asciiTag.DefinedTag, asciiTag.Value);
                                break;

                            case TiffTagType.Rational:
                                TiffRationalTag rationalTag = tag as TiffRationalTag;
                                Console.WriteLine("Tag: {0}, value: {1}", rationalTag.DefinedTag, rationalTag.Value);
                                break;
                        }//end of switch
                    }//end of foreach
                }//end of if (exifInfo != null)

            }
            /// <summary>
            /// Gets IPTC metadata from Jpeg file
            /// </summary> 
            public static void GetIPTCMetadata()
            {
                try
                {
                    //ExStart:GetIPTCMetadata
                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // if file contains iptc metadata
                    if (jpegFormat.HasIptc)
                    {
                        // get iptc collection
                        IptcCollection iptcCollection = jpegFormat.GetIptc();

                        // go through array and write property name and formatted value
                        foreach (IptcProperty iptcProperty in iptcCollection)
                        {
                            Console.WriteLine(string.Format("{0}: {1}", iptcProperty.Name, iptcProperty.GetFormattedValue()));
                        }

                        // initialize IptcDataSetCollection to read well-known properties
                        IptcDataSetCollection dsCollection = new IptcDataSetCollection(iptcCollection);

                        // try to read Application Record dataset
                        if (dsCollection.ApplicationRecord != null)
                        {
                            // get category
                            string category = dsCollection.ApplicationRecord.Category;

                            // get headline
                            string headline = dsCollection.ApplicationRecord.Headline;
                        }

                        if (dsCollection.EnvelopeRecord != null)
                        {
                            // get model version
                            int? modelVersion = dsCollection.EnvelopeRecord.ModelVersion;

                            // get dataSent property
                            DateTime? dataSent = dsCollection.EnvelopeRecord.DataSent;
                        }
                    }
                    //ExEnd:GetIPTCMetadata
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Updates CameraRaw XMP data of Jpeg file and creates output file
            /// </summary> 
            public static void UpdateCameraRawXMPProperties()
            {
                try
                {
                    //ExStart:UpdateCameraRawXmpPropertiesJpegImage
                    // initialize JpegFormat
                    JpegFormat JpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // get access to CameraRaw schema
                    var package = JpegFormat.XmpValues.Schemes.CameraRaw;

                    // update properties
                    package.AutoBrightness = true;
                    package.AutoContrast = true;
                    package.CropUnits = CropUnits.Pixels;

                    // update white balance
                    package.SetWhiteBalance(WhiteBalance.Auto);

                    // commit changes
                    JpegFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:UpdateCameraRawXmpPropertiesJpegImage
                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }
            /// <summary>
            /// Updates PagedText XMP data of Jpeg file and creates output file
            /// </summary> 
            public static void UpdatePagedTextXMPProperties()
            {
                try
                {
                    //ExStart:UpdatePagedTextXmpPropertiesJpegImage
                    // initialize JpegFormat
                    JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath));

                    // get access to PagedText schema
                    var package = jpegFormat.XmpValues.Schemes.PagedText;


                    // update MaxPageSize
                    package.MaxPageSize = new Dimensions(600, 800);

                    // update number of pages
                    package.NumberOfPages = 10;

                    // update plate names
                    package.PlateNames = new string[] { "1", "2", "3" };

                    // commit changes
                    jpegFormat.Save(Common.MapDestinationFilePath(filePath));
                    //ExEnd:UpdatePagedTextXmpPropertiesJpegImage
                    Console.WriteLine("File saved in destination folder.");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }
            }