public void Test_WithImage()
		{
			using (MagickImage image = new MagickImage())
			{
				image.AddProfile(ColorProfile.USWebCoatedSWOP);
				ExceptionAssert.Throws<MagickResourceLimitErrorException>(delegate()
				{
					image.ColorSpace = ColorSpace.CMYK;
				});
				image.Read(Files.SnakewarePNG);

				ColorProfile profile = image.GetColorProfile();
				Assert.IsNull(profile);

				image.AddProfile(ColorProfile.SRGB);
				TestProfile(image.GetColorProfile(), "icc");
			}
		}
		public void Test_ICM()
		{
			using (MagickImage image = new MagickImage(Files.SnakewarePNG))
			{
				ColorProfile profile = image.GetColorProfile();
				Assert.IsNull(profile);

				image.AddProfile(new ImageProfile("icm", ColorProfile.SRGB.ToByteArray()));
				TestProfile(image.GetColorProfile(), "icc");
			}
		}
        public void Test_ClippingPaths()
        {
            using (IMagickImage image = new MagickImage(Files.EightBimTIF))
            {
                EightBimProfile profile = image.Get8BimProfile();
                TestProfile(profile);

                using (IMagickImage emptyImage = new MagickImage(Files.EightBimTIF))
                {
                    emptyImage.Strip();
                    Assert.IsNull(emptyImage.GetIptcProfile());
                    emptyImage.AddProfile(profile);

                    profile = emptyImage.Get8BimProfile();
                    TestProfile(profile);
                }
            }
        }
		public void Test_ClippingPaths()
		{
			using (MagickImage image = new MagickImage(Files.EightBimTIF))
			{
				EightBimProfile profile = image.Get8BimProfile();
				TestProfile(profile);

				using (MagickImage emptyImage = new MagickImage(Files.EightBimTIF))
				{
					emptyImage.Strip();
					Assert.IsNull(emptyImage.Get8BimProfile());
					emptyImage.AddProfile(profile);

					profile = emptyImage.Get8BimProfile();
					TestProfile(profile);
				}
			}
		}
Beispiel #5
0
        public static void ApplyPreviewImageMagick(string source, string destination, double maxWidth, double maxHeight,
                                                   [CanBeNull] AcPreviewImageInformation information)
        {
            using (var image = new MagickImage(source)) {
                if (maxWidth > 0d || maxHeight > 0d)
                {
                    var k = Math.Max(maxHeight / image.Height, maxWidth / image.Width);
                    image.Interpolate = PixelInterpolateMethod.Catrom;
                    image.FilterType  = FilterType.Lanczos;
                    image.Sharpen();
                    image.Resize((int)(k * image.Width), (int)(k * image.Height));
                    image.Crop((int)maxWidth, (int)maxHeight, Gravity.Center);
                }

                image.Quality = 95;
                image.Density = new Density(96, 96);
                if (File.Exists(destination))
                {
                    try {
                        File.Delete(destination);
                    } catch (UnauthorizedAccessException) {
                        Thread.Sleep(200);
                        File.Delete(destination);
                    }
                }

                var profile = new ExifProfile();
                profile.SetValue(ExifTag.Software, AcToolsInformation.Name);

                if (information?.ExifStyle != null)
                {
                    profile.SetValue(ExifTag.Artist, information.ExifStyle);
                }

                if (information?.Name != null)
                {
                    profile.SetValue(ExifTag.ImageDescription, information.Name);
                }

                image.AddProfile(profile);
                image.Write(destination);
            }
        }
        public void Test_Remove()
        {
            using (IMagickImage image = new MagickImage(Files.SnakewarePNG))
            {
                ColorProfile profile = image.GetColorProfile();
                Assert.IsNull(profile);

                image.AddProfile(ColorProfile.SRGB);

                Assert.IsNull(image.GetProfile("icm"));

                profile = image.GetColorProfile();
                Assert.IsNotNull(profile);

                image.RemoveProfile(profile.Name);

                profile = image.GetColorProfile();
                Assert.IsNull(profile);
            }
        }
Beispiel #7
0
        public override Task <BitmapSource> GetRenderedFrame(int index)
        {
            // the first image is always returns synchronously.
            if (index == 0 && _thumbnail != null)
            {
                return(new Task <BitmapSource>(() => _thumbnail));
            }

            return(new Task <BitmapSource>(() =>
            {
                using (var image = new MagickImage(_path))
                {
                    image.AddProfile(ColorProfile.SRGB);
                    image.Density = new Density(Math.Floor(image.Density.X), Math.Floor(image.Density.Y));
                    image.AutoOrient();

                    var bs = image.ToBitmapSource();
                    bs.Freeze();
                    return bs;
                }
            }));
        }
Beispiel #8
0
            public void ShouldFilterTheTagsWhenWritten()
            {
                using (var memStream = new MemoryStream())
                {
                    using (IMagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
                    {
                        var profile = image.GetExifProfile();
                        Assert.AreEqual(44, profile.Values.Count());

                        profile.Parts = ExifParts.ExifTags;
                        image.AddProfile(profile);

                        image.Write(memStream);
                    }

                    memStream.Position = 0;
                    using (IMagickImage image = new MagickImage(memStream))
                    {
                        var profile = image.GetExifProfile();
                        Assert.AreEqual(24, profile.Values.Count());
                    }
                }
            }
Beispiel #9
0
        public void ShouldReadTheExifChunk()
        {
            using (IMagickImage input = new MagickImage(MagickColors.YellowGreen, 1, 1))
            {
                ExifProfile exifProfile = new ExifProfile();
                exifProfile.SetValue(ExifTag.ImageUniqueID, "Have a nice day");

                input.AddProfile(exifProfile);

                using (var memoryStream = new MemoryStream())
                {
                    input.Write(memoryStream, MagickFormat.Png);

                    memoryStream.Position = 0;

                    using (IMagickImage output = new MagickImage(memoryStream))
                    {
                        exifProfile = output.GetExifProfile();

                        Assert.IsNotNull(exifProfile);
                    }
                }
            }
        }
		public void Test_Constructor()
		{
			using (MemoryStream memStream = new MemoryStream())
			{
				using (MagickImage image = new MagickImage(Files.ImageMagickJPG))
				{
					ExifProfile profile = image.GetExifProfile();
					Assert.IsNull(profile);

					profile = new ExifProfile();
					profile.SetValue(ExifTag.Copyright, "Dirk Lemstra");

					image.AddProfile(profile);

					profile = image.GetExifProfile();
					Assert.IsNotNull(profile);

					image.Write(memStream);
				}

				memStream.Position = 0;
				using (MagickImage image = new MagickImage(memStream))
				{
					ExifProfile profile = image.GetExifProfile();

					Assert.IsNotNull(profile);
					Assert.AreEqual(1, profile.Values.Count());

					ExifValue value = profile.Values.FirstOrDefault(val => val.Tag == ExifTag.Copyright);
					TestValue(value, "Dirk Lemstra");
				}
			}
		}
		public void Test_Values()
		{
			using (MagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
			{
				ExifProfile profile = image.GetExifProfile();
				TestProfile(profile);

				using (MagickImage emptyImage = new MagickImage(Files.ImageMagickJPG))
				{
					Assert.IsNull(emptyImage.GetExifProfile());
					emptyImage.AddProfile(profile);

					profile = emptyImage.GetExifProfile();
					TestProfile(profile);
				}
			}
		}
		public void Test_SetValue()
		{
			double[] latitude = new double[] { 12.3, 4.56, 789.0 };

			using (MemoryStream memStream = new MemoryStream())
			{
				using (MagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
				{
					ExifProfile profile = image.GetExifProfile();

					profile.SetValue(ExifTag.Software, "GraphicsMagick.NET");

					ExifValue value = profile.GetValue(ExifTag.Software);
					TestValue(value, "GraphicsMagick.NET");

					ExceptionAssert.Throws<ArgumentException>(delegate()
					{
						value.Value = 15;
					});

					profile.SetValue(ExifTag.ShutterSpeedValue, 75.55);

					value = profile.GetValue(ExifTag.ShutterSpeedValue);
					TestValue(value, 75.55);

					ExceptionAssert.Throws<ArgumentException>(delegate()
					{
						value.Value = 75;
					});

					profile.SetValue(ExifTag.XResolution, 150.0);

					value = profile.GetValue(ExifTag.XResolution);
					TestValue(value, 150.0);

					ExceptionAssert.Throws<ArgumentException>(delegate()
					{
						value.Value = "GraphicsMagick.NET";
					});

					image.Density = new MagickGeometry(72);

					value = profile.GetValue(ExifTag.XResolution);
					TestValue(value, 150.0);

					value = profile.GetValue(ExifTag.ReferenceBlackWhite);
					Assert.IsNotNull(value);

					profile.SetValue(ExifTag.ReferenceBlackWhite, null);

					value = profile.GetValue(ExifTag.ReferenceBlackWhite);
					TestValue(value, (string)null);

					profile.SetValue(ExifTag.GPSLatitude, latitude);

					value = profile.GetValue(ExifTag.GPSLatitude);
					TestValue(value, latitude);

					image.AddProfile(profile);

					image.Write(memStream);
				}

				memStream.Position = 0;
				using (MagickImage image = new MagickImage(memStream))
				{
					ExifProfile profile = image.GetExifProfile();

					Assert.IsNotNull(profile);
					Assert.AreEqual(43, profile.Values.Count());

					ExifValue value = profile.GetValue(ExifTag.Software);
					TestValue(value, "GraphicsMagick.NET");

					value = value = profile.GetValue(ExifTag.ShutterSpeedValue);
					TestValue(value, 75.55);

					value = value = profile.GetValue(ExifTag.XResolution);
					TestValue(value, 150.0);

					value = profile.GetValue(ExifTag.ReferenceBlackWhite);
					Assert.IsNull(value);

					value = profile.GetValue(ExifTag.GPSLatitude);
					TestValue(value, latitude);

					profile.Parts = ExifParts.ExifTags;

					image.AddProfile(profile);

					memStream.Position = 0;
					image.Write(memStream);
				}

				memStream.Position = 0;
				using (MagickImage image = new MagickImage(memStream))
				{
					ExifProfile profile = image.GetExifProfile();

					Assert.IsNotNull(profile);
					Assert.AreEqual(24, profile.Values.Count());

					Assert.IsNotNull(profile.GetValue(ExifTag.FNumber));
					Assert.IsTrue(profile.RemoveValue(ExifTag.FNumber));
					Assert.IsFalse(profile.RemoveValue(ExifTag.FNumber));
					Assert.IsNull(profile.GetValue(ExifTag.FNumber));

					Assert.AreEqual(23, profile.Values.Count());
				}
			}
		}
		public void Test_Infinity()
		{
			using (MagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
			{
				ExifProfile profile = image.GetExifProfile();
				profile.SetValue(ExifTag.ExposureBiasValue, double.PositiveInfinity);
				image.AddProfile(profile);

				profile = image.GetExifProfile();
				ExifValue value = profile.GetValue(ExifTag.ExposureBiasValue);
				Assert.IsNotNull(value);
				Assert.IsTrue(double.PositiveInfinity.Equals(value.Value));

				profile.SetValue(ExifTag.ExposureBiasValue, double.NegativeInfinity);
				image.AddProfile(profile);

				profile = image.GetExifProfile();
				value = profile.GetValue(ExifTag.ExposureBiasValue);
				Assert.IsNotNull(value);
				Assert.IsTrue(double.NegativeInfinity.Equals(value.Value));

				profile.SetValue(ExifTag.FlashEnergy, double.NegativeInfinity);
				image.AddProfile(profile);

				profile = image.GetExifProfile();
				value = profile.GetValue(ExifTag.FlashEnergy);
				Assert.IsNotNull(value);
				Assert.IsTrue(double.PositiveInfinity.Equals(value.Value));
			}
		}
		public void Test_Values()
		{
			using (MagickImage image = new MagickImage(Files.EightBimTIF))
			{
				EightBimProfile profile = image.Get8BimProfile();
				TestProfileValues(profile);

				using (MagickImage emptyImage = new MagickImage(Files.ImageMagickJPG))
				{
					Assert.IsNull(emptyImage.Get8BimProfile());
					emptyImage.AddProfile(profile);

					profile = emptyImage.Get8BimProfile();
					TestProfileValues(profile);
				}
			}
		}
		public void Test_SetValue()
		{
			using (MemoryStream memStream = new MemoryStream())
			{
				string credit = null;
				for (int i = 0; i < 255; i++)
					credit += i.ToString() + ".";

				using (MagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
				{
					IptcProfile profile = image.GetIptcProfile();
					TestProfileValues(profile);

					IptcValue value = profile.GetValue(IptcTag.Title);
					TestValue(value, "Communications");

					profile.SetValue(IptcTag.Title, "Magick.NET Title");
					TestValue(value, "Magick.NET Title");

					value = profile.GetValue(IptcTag.Title);
					TestValue(value, "Magick.NET Title");

					value = profile.Values.FirstOrDefault(val => val.Tag == IptcTag.ReferenceNumber);
					Assert.IsNull(value);

					profile.SetValue(IptcTag.ReferenceNumber, "Magick.NET ReferenceNümber");

					value = profile.GetValue(IptcTag.ReferenceNumber);
					TestValue(value, "Magick.NET ReferenceNümber");

					profile.SetValue(IptcTag.Credit, credit);

					value = profile.GetValue(IptcTag.Credit);
					TestValue(value, credit);

					// Remove the 8bim profile so we can overwrite the iptc profile.
					image.RemoveProfile("8bim");
					image.AddProfile(profile);

					image.Write(memStream);
					memStream.Position = 0;
				}

				using (MagickImage image = new MagickImage(memStream))
				{
					IptcProfile profile = image.GetIptcProfile();
					TestProfileValues(profile, 20);

					IptcValue value = profile.GetValue(IptcTag.Title);
					TestValue(value, "Magick.NET Title");

					value = profile.GetValue(IptcTag.ReferenceNumber);
					TestValue(value, "Magick.NET ReferenceNümber");

					value = profile.GetValue(IptcTag.Credit);
					TestValue(value, credit);

					ExceptionAssert.Throws<ArgumentNullException>(delegate()
					{
						profile.SetValue(IptcTag.Caption, null, "Test");
					});

					profile.SetValue(IptcTag.Caption, "Test");
					value = profile.Values.ElementAt(1);
					Assert.AreEqual("Test", value.Value);

					profile.SetValue(IptcTag.Caption, Encoding.UTF32, "Test");
					Assert.AreEqual(Encoding.UTF32, value.Encoding);
					Assert.AreEqual("Test", value.Value);

					Assert.IsTrue(profile.RemoveValue(IptcTag.Caption));
					Assert.IsFalse(profile.RemoveValue(IptcTag.Caption));
					Assert.IsNull(profile.GetValue(IptcTag.Caption));
				}
			}
		}
Beispiel #16
0
        /// <summary>
        /// Load image from file
        /// </summary>
        /// <param name="path">Full path  of image file</param>
        /// <param name="width">Width value of scalable image format</param>
        /// <param name="height">Height value of scalable image format</param>
        /// <returns></returns>
        public static Bitmap Load(string path, int @width = 0, int @height = 0)
        {
            var ext = Path.GetExtension(path).ToLower();

            Bitmap bmp = null;

            switch (ext)
            {
            case ".gif":
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    var ms = new MemoryStream();
                    fs.CopyTo(ms);
                    ms.Position = 0;

                    bmp = new Bitmap(ms, true);
                }
                break;

            case ".ico":
                bmp = ReadIconFile(path);
                break;

            default:
                try
                {
                    GetBitmapFromFile();

                    if (bmp == null)
                    {
                        GetBitmapFromWic();
                    }
                }
                catch (Exception)
                {
                    GetBitmapFromWic();
                }
                break;
            }

            void GetBitmapFromFile()
            {
                var settings = new MagickReadSettings();

                if (ext.CompareTo(".svg") == 0)
                {
                    settings.BackgroundColor = MagickColors.Transparent;
                }

                if (width > 0 && height > 0)
                {
                    settings.Width  = width;
                    settings.Height = height;
                }


                using (var magicImg = new MagickImage(path, settings))
                {
                    magicImg.Quality = 100;

                    //Get Exif information
                    var profile = magicImg.GetExifProfile();
                    if (profile != null)
                    {
                        //Get Orieantation Flag
                        var exifTag = profile.GetValue(ExifTag.Orientation);

                        if (exifTag != null)
                        {
                            int orientationFlag = int.Parse(profile.GetValue(ExifTag.Orientation).Value.ToString());

                            var orientationDegree = GetOrientationDegree(orientationFlag);
                            if (orientationDegree != 0)
                            {
                                //Rotate image accordingly
                                magicImg.Rotate(orientationDegree);
                            }
                        }
                    }

                    //corect the image color
                    magicImg.AddProfile(ColorProfile.SRGB);

                    bmp = magicImg.ToBitmap();
                }
            }

            void GetBitmapFromWic()
            {
                var src = LoadImage(path);

                bmp = BitmapFromSource(src);
            }

            return(bmp);
        }
Beispiel #17
0
        public void Test_SetValue()
        {
            using (MemoryStream memStream = new MemoryStream())
            {
                string credit = null;
                for (int i = 0; i < 255; i++)
                {
                    credit += i.ToString() + ".";
                }

                using (IMagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
                {
                    IptcProfile profile = image.GetIptcProfile();
                    TestProfileValues(profile);

                    IptcValue value = profile.GetValue(IptcTag.Title);
                    TestValue(value, "Communications");

                    profile.SetValue(IptcTag.Title, "Magick.NET Title");
                    TestValue(value, "Magick.NET Title");

                    value = profile.GetValue(IptcTag.Title);
                    TestValue(value, "Magick.NET Title");

                    value = profile.Values.FirstOrDefault(val => val.Tag == IptcTag.ReferenceNumber);
                    Assert.IsNull(value);

                    profile.SetValue(IptcTag.ReferenceNumber, "Magick.NET ReferenceNümber");

                    value = profile.GetValue(IptcTag.ReferenceNumber);
                    TestValue(value, "Magick.NET ReferenceNümber");

                    profile.SetValue(IptcTag.Credit, credit);

                    value = profile.GetValue(IptcTag.Credit);
                    TestValue(value, credit);

                    // Remove the 8bim profile so we can overwrite the iptc profile.
                    image.RemoveProfile("8bim");
                    image.AddProfile(profile);

                    image.Write(memStream);
                    memStream.Position = 0;
                }

                using (IMagickImage image = new MagickImage(memStream))
                {
                    IptcProfile profile = image.GetIptcProfile();
                    TestProfileValues(profile, 19);

                    IptcValue value = profile.GetValue(IptcTag.Title);
                    TestValue(value, "Magick.NET Title");

                    value = profile.GetValue(IptcTag.ReferenceNumber);
                    TestValue(value, "Magick.NET ReferenceNümber");

                    value = profile.GetValue(IptcTag.Credit);
                    TestValue(value, credit);

                    ExceptionAssert.Throws <ArgumentNullException>(delegate()
                    {
                        profile.SetValue(IptcTag.Caption, null, "Test");
                    });

                    profile.SetValue(IptcTag.Caption, "Test");
                    value = profile.Values.ElementAt(1);
                    Assert.AreEqual("Test", value.Value);

                    profile.SetValue(IptcTag.Caption, Encoding.UTF32, "Test");
                    Assert.AreEqual(Encoding.UTF32, value.Encoding);
                    Assert.AreEqual("Test", value.Value);

                    Assert.IsTrue(profile.RemoveValue(IptcTag.Caption));
                    Assert.IsFalse(profile.RemoveValue(IptcTag.Caption));
                    Assert.IsNull(profile.GetValue(IptcTag.Caption));
                }
            }
        }
Beispiel #18
0
        /// <summary>
        /// Load image from file
        /// </summary>
        /// <param name="path">Full path  of image file</param>
        /// <param name="size">A custom size of image</param>
        /// <param name="colorProfileName">Name or Full path of color profile</param>
        /// <param name="isApplyColorProfileForAll">If FALSE, only the images with embedded profile will be applied</param>
        /// <returns></returns>
        public static Bitmap Load(string path, Size size = new Size(), string colorProfileName = "sRGB", bool isApplyColorProfileForAll = false)
        {
            var    ext = Path.GetExtension(path).ToLower();
            Bitmap bmp = null;

            switch (ext)
            {
            case ".gif":
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    var ms = new MemoryStream();
                    fs.CopyTo(ms);
                    ms.Position = 0;

                    bmp = new Bitmap(ms, true);
                }
                break;

            case ".ico":
                bmp = ReadIconFile(path);
                break;

            default:
                try
                {
                    bmp = GetBitmapFromFile();

                    if (bmp == null)
                    {
                        bmp = GetBitmapFromWic();
                    }
                }
                catch (Exception)
                {
                    bmp = GetBitmapFromWic();
                }
                break;
            }

            Bitmap GetBitmapFromFile()
            {
                Bitmap bmpData  = null;
                var    settings = new MagickReadSettings();

                if (ext.CompareTo(".svg") == 0)
                {
                    settings.BackgroundColor = MagickColors.Transparent;
                }

                if (size.Width > 0 && size.Height > 0)
                {
                    settings.Width  = size.Width;
                    settings.Height = size.Height;
                }

                //using (var magicColl = new MagickImageCollection())
                //{
                //    magicColl.Read(new FileInfo(path), settings);

                //    if (magicColl.Count > 0)
                //    {
                //        magicColl[0].Quality = 100;
                //        magicColl[0].AddProfile(ColorProfile.SRGB);

                //        bmp = BitmapBooster.BitmapFromSource(magicColl[0].ToBitmapSource());
                //    }
                //}

                using (var magicImg = new MagickImage(path, settings))
                {
                    magicImg.Quality = 100;

                    //Get Exif information
                    var profile = magicImg.GetExifProfile();
                    if (profile != null)
                    {
                        //Get Orieantation Flag
                        var exifTag = profile.GetValue(ExifTag.Orientation);

                        if (exifTag != null)
                        {
                            int orientationFlag = int.Parse(profile.GetValue(ExifTag.Orientation).Value.ToString());

                            var orientationDegree = GetOrientationDegree(orientationFlag);
                            if (orientationDegree != 0)
                            {
                                //Rotate image accordingly
                                magicImg.Rotate(orientationDegree);
                            }
                        }
                    }


                    // get the color profile of image
                    var imgColorProfile = magicImg.GetColorProfile();


                    // if always apply color profile
                    // or only apply color profile if there is an embedded profile
                    if (isApplyColorProfileForAll || imgColorProfile != null)
                    {
                        if (imgColorProfile != null)
                        {
                            // correct the image color space
                            magicImg.ColorSpace = imgColorProfile.ColorSpace;
                        }
                        else
                        {
                            // set default color profile and color space
                            magicImg.AddProfile(ColorProfile.SRGB);
                            magicImg.ColorSpace = ColorProfile.SRGB.ColorSpace;
                        }

                        var colorProfile = GetColorProfileFromString(colorProfileName);
                        if (colorProfile != null)
                        {
                            magicImg.AddProfile(colorProfile);
                            magicImg.ColorSpace = colorProfile.ColorSpace;
                        }
                    }


                    //get bitmap
                    bmpData = magicImg.ToBitmap();
                }

                return(bmpData);
            }

            Bitmap GetBitmapFromWic()
            {
                Bitmap bmpData = null;

                var src = LoadImage(path);

                bmpData = BitmapFromSource(src);

                return(bmpData);
            }

            return(bmp);
        }
		public void Test_FromIXPathNavigable()
		{
			using (MagickImage image = new MagickImage(Files.InvitationTif))
			{
				XmpProfile profile = image.GetXmpProfile();
				Assert.IsNotNull(profile);

				IXPathNavigable doc = profile.ToIXPathNavigable();

				ExceptionAssert.Throws<ArgumentNullException>(delegate()
				{
					XmpProfile.FromIXPathNavigable(null);
				});

				XmpProfile newProfile = XmpProfile.FromIXPathNavigable(doc);
				image.AddProfile(newProfile);

				doc = profile.ToIXPathNavigable();
				TestIXPathNavigable(doc);

				profile = image.GetXmpProfile();
				Assert.IsNotNull(profile);

				doc = profile.ToIXPathNavigable();
				TestIXPathNavigable(doc);

				Assert.AreEqual(profile, newProfile);
			}
		}
Beispiel #20
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (lsbResimlistesi.SelectedItem == null)
            {
                MessageBox.Show("Tekli düzenleme yapabilmek için önce seçim yapın !");
                return;
            }
            prgDurum.Maximum = 1;

            using (MagickImage image = new MagickImage(secilen))
            {
                toolStripStatusLabel1.Text = "Lütfen bekleyin.";
                ExifProfile profile2 = image.GetExifProfile();

                if (profile2 == null)
                {
                    profile2 = new ExifProfile();
                }



                // ExifProfile profile = new ExifProfile();
                // profile = new ExifProfile();
                if (true)
                {
                }
                if (chbBaslik.Checked)
                {
                    //   profile2.RemoveValue(ImageMagick.ExifTag.XPTitle);
                    byte[] d = Encoding.Unicode.GetBytes(txtBaslik.Text);
                    profile2.SetValue(ImageMagick.ExifTag.XPTitle, d);
                    profile2.SetValue(ImageMagick.ExifTag.ImageDescription, txtBaslik.Text);
                }
                if (chbKonu.Checked)
                {
                    // profile2.RemoveValue(ImageMagick.ExifTag.XPSubject);
                    byte[] d = Encoding.Unicode.GetBytes(txtKonu.Text);
                    profile2.SetValue(ImageMagick.ExifTag.XPSubject, d);
                }
                if (chbEtiketler.Checked)
                {
                    //  profile2.RemoveValue(ImageMagick.ExifTag.XPKeywords);
                    profile2.RemoveValue(ImageMagick.ExifTag.XPKeywords);
                    byte[] d = Encoding.Unicode.GetBytes(txtEtiketler.Text);
                    profile2.SetValue(ImageMagick.ExifTag.XPKeywords, d);
                }

                if (chbAciklama.Checked)
                {
                    //  profile2.RemoveValue(ImageMagick.ExifTag.XPComment);
                    byte[] d = Encoding.Unicode.GetBytes(txtAciklama.Text);
                    profile2.SetValue(ImageMagick.ExifTag.XPComment, d);
                }
                foreach (var item in image.ProfileNames)
                {
                    image.RemoveProfile(item);
                }
                image.AddProfile(profile2);
                image.Write(secilen);
                prgDurum.Value             = 1;
                lblDurum.Text              = "İşlem başarılı";
                toolStripStatusLabel1.Text = "Hazır";
            }
        }
Beispiel #21
0
        private void button3_Click(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "Lütfen bekleyin.";
            int toplam    = 0;
            int basarili  = 0;
            int basarisiz = 0;

            toplam           = lsbislem.Items.Count;
            prgDurum.Maximum = toplam;

            for (int i = 0; i < lsbislem.Items.Count; i++)
            {
                try
                {
                    using (MagickImage image = new MagickImage(lsbislem.Items[i].ToString()))
                    {
                        ExifProfile profile2 = image.GetExifProfile();

                        if (profile2 == null)
                        {
                            profile2 = new ExifProfile();
                        }



                        // ExifProfile profile = new ExifProfile();
                        // profile = new ExifProfile();
                        if (true)
                        {
                        }
                        if (chbBaslik.Checked)
                        {
                            byte[] d = Encoding.Unicode.GetBytes(txtBaslik.Text);
                            profile2.SetValue(ImageMagick.ExifTag.XPTitle, d);
                            profile2.SetValue(ImageMagick.ExifTag.ImageDescription, txtBaslik.Text);
                            // profile2.SetValue(ImageMagick.ExifTag.)
                        }
                        if (chbKonu.Checked)
                        {
                            byte[] d = Encoding.Unicode.GetBytes(txtKonu.Text);
                            profile2.SetValue(ImageMagick.ExifTag.XPSubject, d);
                        }
                        if (chbEtiketler.Checked)
                        {
                            //  profile2.RemoveValue(ImageMagick.ExifTag.XPKeywords);
                            byte[] d = Encoding.Unicode.GetBytes(txtEtiketler.Text);
                            profile2.SetValue(ImageMagick.ExifTag.XPKeywords, d);
                        }

                        if (chbAciklama.Checked)
                        {
                            byte[] d = Encoding.Unicode.GetBytes(txtAciklama.Text);
                            profile2.SetValue(ImageMagick.ExifTag.XPComment, d);
                        }
                        foreach (var item in image.ProfileNames)
                        {
                            image.RemoveProfile(item);
                        }
                        image.AddProfile(profile2);
                        image.Write(lsbislem.Items[i].ToString());
                        prgDurum.Value = 1;
                        basarili++;
                    }
                }
                catch (Exception)
                {
                    basarisiz++;
                }
                finally

                {
                }

                prgDurum.Value = basarisiz + basarili;
                lblDurum.Text  = "Toplam işlem: " + toplam.ToString() + " Başarılı işlem:" + basarili.ToString() + " Başarısız işlem: " + basarisiz.ToString();
            }
            lblDurum.Text = "İşlem tamamlandı. Toplam işlem: " + toplam.ToString() + " Başarılı işlem:" + basarili.ToString() + " Başarısız işlem: " + basarisiz.ToString();
            toolStripStatusLabel1.Text = "Hazır";
        }
Beispiel #22
0
        public static ConvertResult ConvertToRGB(FileInfo imageFI, bool withThumbnail, bool overwrite = false)
        {
            ConvertResult result;

            result.error          = null;
            result.generatedRGB   = null;
            result.generatedThumb = null;

            string      outputFolderPath;
            string      outputFilePath;
            var         outputFileExists = OutputPathCheck(imageFI, OUTPUTFOLDER_RGB, out outputFolderPath, out outputFilePath);
            MagickImage image;

            try
            {
                image = new MagickImage(imageFI);
            }
            catch (Exception ex)
            {
                result.error = ex;
                return(result);
            }

            try
            {
                image.AddProfile(ColorProfile.SRGB);

                if (overwrite || !outputFileExists)
                {
                    image.Write(outputFilePath);
                    result.generatedRGB = true;
                }
                else
                {
                    result.generatedRGB = false; // Skipped
                }
            }
            catch (Exception ex)
            {
                image.Dispose();
                result.error = ex;
                // Cannot generate thumbnail because there is no RGB image to derive from
                return(result);
            }
            try
            {
                if (withThumbnail)
                {
                    outputFileExists = OutputPathCheck(imageFI, OUTPUTFOLDER_THUMB, out outputFolderPath, out outputFilePath);
                    if (overwrite || !outputFileExists)
                    {
                        float newWidth  = image.Width * ThumbScale;
                        float newHeight = image.Height * ThumbScale;
                        image.Resize((int)newWidth, (int)newHeight);
                        image.Write(outputFilePath);
                        result.generatedThumb = true;
                    }
                    else
                    {
                        result.generatedThumb = false;
                    }
                }
                else
                {
                    result.generatedThumb = false;
                }
            }
            catch (Exception ex)
            {
                result.error = ex;
            }
            finally
            {
                image.Dispose();
            }

            return(result);
        }
Beispiel #23
0
        static void Main(string[] args)
        {
            try
            {
                bool?  integratedSecurity = null;
                bool   hasConnected = false;
                string dataSource, userId, password, initialCatalog;

                while (!hasConnected)
                {
                    Console.Clear();
                    dataSource         = "";
                    userId             = "";
                    password           = "";
                    initialCatalog     = "";
                    integratedSecurity = null;
                    SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();

                    //get connection string details
                    Console.WriteLine("Connection String Details: ");
                    Console.WriteLine("==========================");
                    while (integratedSecurity == null)
                    {
                        Console.WriteLine("Integrated Security? (Y/N)");
                        var x = Console.ReadLine();
                        if (x.ToLower() == "y")
                        {
                            integratedSecurity = true;
                        }
                        else if (x.ToLower() == "n")
                        {
                            integratedSecurity = false;
                        }
                        else
                        {
                            Console.WriteLine("Invalid input please enter Y for yes and N for no.");
                        }
                    }
                    Console.Write("Data Source     = ");
                    dataSource = Console.ReadLine();
                    if ((bool)!integratedSecurity)
                    {
                        Console.Write("User ID         = ");
                        userId = Console.ReadLine();
                        Console.Write("Password        = "******"Initial Catalog = ");
                    initialCatalog = Console.ReadLine();

                    //setup variables
                    builder.DataSource     = dataSource;
                    builder.InitialCatalog = initialCatalog;
                    if ((bool)integratedSecurity)
                    {
                        builder.IntegratedSecurity = true;
                    }
                    else
                    {
                        builder.UserID   = userId;
                        builder.Password = password;
                    }
                    Console.Write("Connecting to SQL server ... ");

                    using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                    {
                        try
                        {
                            connection.Open();
                            hasConnected = true;
                            Console.WriteLine("done.");

                            List <Byte[]> images     = new List <byte[]>();
                            List <int>    imageIds   = new List <int>();
                            string        table      = "";
                            string        byte_col   = "";
                            string        id_col     = "";
                            bool          foundTable = false;

                            while (!foundTable)
                            {
                                Console.Write("Table name      = ");
                                table = Console.ReadLine();
                                Console.Write("Image col name  = ");
                                byte_col = Console.ReadLine();
                                Console.Write("ID column name  = ");
                                id_col = Console.ReadLine();

                                //pull image data
                                String SQL = String.Format("SELECT [{2}], [{3}] FROM [{0}].[dbo].[{1}]", initialCatalog, table, byte_col, id_col);
                                Console.Write("Fetching image data ... ");
                                try
                                {
                                    using (SqlCommand command = new SqlCommand(SQL, connection))
                                    {
                                        using (SqlDataReader reader = command.ExecuteReader())
                                        {
                                            while (reader.Read())
                                            {
                                                if (reader.GetValue(0) != DBNull.Value)
                                                {
                                                    byte[] buffer = null;
                                                    buffer = (byte[])reader[0];
                                                    images.Add(buffer);
                                                    imageIds.Add(Convert.ToInt32(reader[1]));
                                                }
                                            }
                                            foundTable = true;
                                            Console.WriteLine("done.");
                                            Console.WriteLine("Image Count: " + images.Count());
                                            Console.WriteLine("=====================================");
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("Command could not be executed try again.");
                                }
                            }

                            //check for empty
                            if (images.Count > 0)
                            {
                                for (int i = 0; i < images.Count; i++)
                                {
                                    byte[] byteArray = images[i];
                                    if (byteArray.Length > 0)
                                    {
                                        using (MagickImage image = new MagickImage(byteArray))
                                        {
                                            //convert image
                                            if (image.ColorSpace.ToString() == "CMYK")
                                            {
                                                Console.WriteLine("CMYK Image for imageID: ID: " + imageIds[i]);
                                                MagickImageInfo info = new MagickImageInfo(byteArray);

                                                //====Download original image(CMYK)====
                                                Bitmap bmp = image.ToBitmap();
                                                Directory.CreateDirectory("CMYKImages");
                                                string fileName = "CMYKImages\\original_" + imageIds[i];
                                                if (info.Format == MagickFormat.Jpeg)
                                                {
                                                    fileName += ".jpeg";
                                                    bmp.Save(fileName, ImageFormat.Jpeg);
                                                }
                                                else if (info.Format == MagickFormat.Png)
                                                {
                                                    fileName += ".png";
                                                    bmp.Save(fileName, ImageFormat.Png);
                                                }
                                                //======================================

                                                //strip color profiles + convert to RGB
                                                image.Strip();
                                                image.AddProfile(ColorProfile.USWebCoatedSWOP);
                                                image.AddProfile(ColorProfile.SRGB);
                                                byteArray = image.ToByteArray();

                                                //add update command to query
                                                Console.Write("Updating record ... ");
                                                SqlCommand command = new SqlCommand(String.Format("UPDATE [{0}].[dbo].[{1}] SET [{2}] = 0x{0} where [{3}] = {4};", initialCatalog, table, byte_col, id_col, BitConverter.ToString(byteArray).Replace("-", "").ToLower(), imageIds[i]), connection);
                                                Console.Write(command.ExecuteNonQuery().ToString() + " rows affected. ... ");
                                                Console.WriteLine("done.");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("No image for ID: " + imageIds[i]);
                                    }
                                }
                                Console.WriteLine("===================");
                                Console.WriteLine("Checked all images.");
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Could not connect to the server.");
                            Console.WriteLine("Press Enter to try again.");
                            Console.WriteLine("Press Any other key to exit.");
                            ConsoleKeyInfo input;
                            input = Console.ReadKey(true);
                            if (input.Key != ConsoleKey.Enter)
                            {
                                Environment.Exit(0);
                            }
                        }
                        finally
                        {
                            connection.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey(true);
        }
        /// <summary>
        /// Load image from file
        /// </summary>
        /// <param name="path">Full path  of image file</param>
        /// <param name="width">Width value of scalable image format</param>
        /// <param name="height">Height value of scalable image format</param>
        /// <returns></returns>
        public static Bitmap Load(string path, int @width = 0, int @height = 0)
        {
            var ext = Path.GetExtension(path).ToLower();

            Bitmap bmp = null;

            switch (ext)
            {
            case ".gif":
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    var ms = new MemoryStream();
                    fs.CopyTo(ms);
                    ms.Position = 0;

                    bmp = new Bitmap(ms, true);
                }
                break;

            case ".ico":
                bmp = ReadIconFile(path);
                break;

            default:
                try
                {
                    GetBitmapFromFile();

                    if (bmp == null)
                    {
                        GetBitmapFromWic();
                    }
                }
                catch (Exception)
                {
                    GetBitmapFromWic();
                }
                break;
            }

            void GetBitmapFromFile()
            {
                var settings = new MagickReadSettings();

                if (ext.CompareTo(".svg") == 0)
                {
                    settings.BackgroundColor = MagickColors.Transparent;
                }

                if (width > 0 && height > 0)
                {
                    settings.Width  = width;
                    settings.Height = height;
                }


                //using (var magicColl = new MagickImageCollection())
                //{
                //    magicColl.Read(new FileInfo(path), settings);

                //    if (magicColl.Count > 0)
                //    {
                //        magicColl[0].Quality = 100;
                //        magicColl[0].AddProfile(ColorProfile.SRGB);

                //        bmp = BitmapBooster.BitmapFromSource(magicColl[0].ToBitmapSource());
                //    }
                //}


                using (var magicImg = new MagickImage(path, settings))
                {
                    magicImg.Quality = 100;

                    //Get Exif information
                    var profile = magicImg.GetExifProfile();
                    if (profile != null)
                    {
                        //Get Orieantation Flag
                        var exifTag = profile.GetValue(ExifTag.Orientation);

                        if (exifTag != null)
                        {
                            int orientationFlag = int.Parse(profile.GetValue(ExifTag.Orientation).Value.ToString());

                            var orientationDegree = GetOrientationDegree(orientationFlag);
                            if (orientationDegree != 0)
                            {
                                //Rotate image accordingly
                                magicImg.Rotate(orientationDegree);
                            }
                        }
                    }

                    //corect the image color
                    magicImg.AddProfile(ColorProfile.SRGB);

                    if (ext.CompareTo(".heic") == 0)
                    {
                        // NOTE: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                        // There is a bug with Magick.NET v7.4.5
                        // that ToBitmap() function will return wrong colorspace:
                        // https://github.com/dlemstra/Magick.NET/issues/153#issuecomment-388080405
                        // ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                        // Hence, we need to export to BitmapSource then convert to Bitmap again
                        bmp = BitmapBooster.BitmapFromSource(magicImg.ToBitmapSource());
                    }
                    else
                    {
                        bmp = magicImg.ToBitmap();
                    }
                }
            }

            void GetBitmapFromWic()
            {
                var src = LoadImage(path);

                bmp = BitmapFromSource(src);
            }

            return(bmp);
        }
        public void UpdateDateTaken(Guid imageId, DateTime date)
        {
            var image = this.images.GetById(imageId);

            if (image != null)
            {
                var lowFileOld = this.appEnvironment.WebRootPath + Constants.MainContentFolder + "/" + image.AlbumId
                                 + "/" + Constants.ImageFolderLow + "/" + image.FileName;
                var middleFileOld = this.appEnvironment.WebRootPath + Constants.MainContentFolder + "/" + image.AlbumId
                                    + "/" + Constants.ImageFolderMiddle + "/" + image.FileName;
                var highFileOld = this.appEnvironment.WebRootPath + Constants.MainContentFolder + "/" + image.AlbumId
                                  + "/" + Constants.ImageFolderOriginal + "/" + image.FileName;

                var oldFilename = image.FileName;
                image.DateTaken = date;
                image.FileName  = date.ToString("yyyy-MM-dd-HH-mm-ss-") + Guid.NewGuid()
                                  + Path.GetExtension(oldFilename);
                this.Update(image);

                var format = "yyyy:MM:dd HH:mm:ss";

                var lowFile = this.appEnvironment.WebRootPath + Constants.MainContentFolder + "/" + image.AlbumId + "/"
                              + Constants.ImageFolderLow + "/" + image.FileName;
                var middleFile = this.appEnvironment.WebRootPath + Constants.MainContentFolder + "/" + image.AlbumId
                                 + "/" + Constants.ImageFolderMiddle + "/" + image.FileName;
                var highFile = this.appEnvironment.WebRootPath + Constants.MainContentFolder + "/" + image.AlbumId + "/"
                               + Constants.ImageFolderOriginal + "/" + image.FileName;

                using (var imageMagick = new MagickImage(lowFileOld))
                {
                    var exif = imageMagick.GetExifProfile() ?? new ExifProfile();
                    exif.SetValue(ExifTag.DateTimeOriginal, date.ToString(format));
                    imageMagick.AddProfile(exif, true);
                    imageMagick.Write(lowFile);
                }

                using (var imageMagick = new MagickImage(middleFileOld))
                {
                    var exif = imageMagick.GetExifProfile() ?? new ExifProfile();
                    exif.SetValue(ExifTag.DateTimeOriginal, date.ToString(format));
                    imageMagick.AddProfile(exif, true);
                    imageMagick.Write(middleFile);
                }

                using (var imageMagick = new MagickImage(highFileOld))
                {
                    var exif = imageMagick.GetExifProfile() ?? new ExifProfile();
                    exif.SetValue(ExifTag.DateTimeOriginal, date.ToString(format));
                    imageMagick.AddProfile(exif, true);
                    imageMagick.Write(highFile);
                }

                File.Delete(lowFileOld);
                File.Delete(middleFileOld);
                File.Delete(highFileOld);

                this.memoryCache.Remove(CacheKeys.AlbumsServiceCacheKey);
                this.memoryCache.Remove(CacheKeys.ImageServiceCacheKey);
                this.memoryCache.Remove(CacheKeys.FileServiceCacheKey);
            }
        }
Beispiel #26
0
        public void Test_SetValue()
        {
            Rational[] latitude = new Rational[] { new Rational(12.3), new Rational(4.56), new Rational(789.0) };

            using (MemoryStream memStream = new MemoryStream())
            {
                using (IMagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
                {
                    ExifProfile profile = image.GetExifProfile();
                    profile.SetValue(ExifTag.Software, "Magick.NET");

                    ExifValue value = profile.GetValue(ExifTag.Software);
                    TestValue(value, "Magick.NET");

                    ExceptionAssert.Throws <ArgumentException>(delegate()
                    {
                        value.Value = 15;
                    });

                    profile.SetValue(ExifTag.ShutterSpeedValue, new SignedRational(75.55));

                    value = profile.GetValue(ExifTag.ShutterSpeedValue);
                    TestRationalValue(value, "1511/20");

                    ExceptionAssert.Throws <ArgumentException>(delegate()
                    {
                        value.Value = 75;
                    });

                    profile.SetValue(ExifTag.XResolution, new Rational(150.0));

                    value = profile.GetValue(ExifTag.XResolution);
                    TestRationalValue(value, "150");

                    ExceptionAssert.Throws <ArgumentException>(delegate()
                    {
                        value.Value = "Magick.NET";
                    });

                    image.Density = new Density(72);

                    value = profile.GetValue(ExifTag.XResolution);
                    TestRationalValue(value, "150");

                    value = profile.GetValue(ExifTag.ReferenceBlackWhite);
                    Assert.IsNotNull(value);

                    profile.SetValue(ExifTag.ReferenceBlackWhite, null);

                    value = profile.GetValue(ExifTag.ReferenceBlackWhite);
                    TestValue(value, (string)null);

                    profile.SetValue(ExifTag.GPSLatitude, latitude);

                    value = profile.GetValue(ExifTag.GPSLatitude);
                    TestValue(value, latitude);

                    image.AddProfile(profile);

                    image.Write(memStream);
                }

                memStream.Position = 0;
                using (IMagickImage image = new MagickImage(memStream))
                {
                    ExifProfile profile = image.GetExifProfile();

                    Assert.IsNotNull(profile);
                    Assert.AreEqual(43, profile.Values.Count());

                    ExifValue value = profile.GetValue(ExifTag.Software);
                    TestValue(value, "Magick.NET");

                    value = profile.GetValue(ExifTag.ShutterSpeedValue);
                    TestRationalValue(value, "1511/20");

                    value = profile.GetValue(ExifTag.XResolution);
                    TestRationalValue(value, "72");

                    value = profile.GetValue(ExifTag.ReferenceBlackWhite);
                    Assert.IsNull(value);

                    value = profile.GetValue(ExifTag.GPSLatitude);
                    TestValue(value, latitude);

                    profile.Parts = ExifParts.ExifTags;

                    image.AddProfile(profile);

                    memStream.Position = 0;
                    image.Write(memStream);
                }

                memStream.Position = 0;
                using (IMagickImage image = new MagickImage(memStream))
                {
                    ExifProfile profile = image.GetExifProfile();

                    Assert.IsNotNull(profile);
                    Assert.AreEqual(24, profile.Values.Count());

                    Assert.IsNotNull(profile.GetValue(ExifTag.FNumber));
                    Assert.IsTrue(profile.RemoveValue(ExifTag.FNumber));
                    Assert.IsFalse(profile.RemoveValue(ExifTag.FNumber));
                    Assert.IsNull(profile.GetValue(ExifTag.FNumber));

                    Assert.AreEqual(23, profile.Values.Count());
                }
            }
        }
Beispiel #27
0
        //public DateTime s_局部高清_處理方式 = DateTime.Now;

        /// <summary>
        ///
        /// </summary>
        public void func_局部高清_初始化()
        {
            String s_path     = ""; //圖片路徑
            double d_倍率       = 1;  //縮放倍率
            double d_倍率_old   = 1;  //超過500毫秒沒有進行縮放才重新算圖
            double d_x        = 1;  //圖片位置
            double d_y        = 1;
            double d_window_w = 1;  //視窗寬度
            double d_window_h = 1;
            int    int_旋轉角度   = 0;
            bool   bool_剪裁    = false;

            DateTime time_避免捲動中算圖 = DateTime.Now;//



            //-------------

            new Thread(() => {
                while (bool_程式運行中)
                {
                    //-------------

                    Thread.Sleep(100);

                    if (u_大量瀏覽模式 != null)
                    {
                        s_path = "";
                        continue;
                    }

                    if (bool_啟動局部高清 == false)
                    {
                        s_path = "";
                        continue;
                    }

                    //避免同一張圖片重新載入後,就失去局部高清的功能
                    if (image_局部高清 == null)
                    {
                        s_path = "";
                    }

                    //在程式預設開啟的資料夾不啟用
                    if (int_目前圖片位置 < ar_path.Count)
                    {
                        if (ar_path[int_目前圖片位置].IndexOf(fun_執行檔路徑() + "\\data\\imgs") == 0)
                        {
                            s_path = "";
                            continue;
                        }
                    }

                    /*
                     * if (this.Visibility != Visibility.Visible) {
                     *  //s_path = "";
                     *  Thread.Sleep(100);
                     *  continue;
                     * }*/


                    /*
                     * if (s_img_type_附檔名 == "PNG" || s_img_type_附檔名 == "JPG" ||
                     *  s_img_type_附檔名 == "TIF" || s_img_type_附檔名 == "BMP" ||
                     *  image_局部高清 != null) {
                     *
                     * } else {
                     *  continue;
                     * }*/



                    bool bool_重新繪製      = false;
                    bool bool_新圖片       = false;
                    bool bool_不剪裁且不重新繪製 = false;


                    C_adapter.fun_UI執行緒(() => {
                        try {
                            if (d_倍率 == img.ActualWidth && bool_剪裁 == false)
                            {
                                //System.Console.WriteLine("不剪裁且不重新繪製: " + ar_path[int_目前圖片位置]);
                                bool_不剪裁且不重新繪製 = true;
                            }

                            if (s_path != ar_path[int_目前圖片位置])
                            {
                                //System.Console.WriteLine("新圖片: " + ar_path[int_目前圖片位置]);

                                s_path         = ar_path[int_目前圖片位置];
                                bool_新圖片       = true;
                                bool_不剪裁且不重新繪製 = false;
                                bool_重新繪製      = true;

                                //讓新圖片一定能立即運算
                                d_倍率     = 0.123456;
                                d_倍率_old = img.ActualWidth;
                            }

                            if (d_倍率_old == img.ActualWidth)
                            {
                                //bool_重新繪製 = false;

                                if (d_倍率 != img.ActualWidth ||
                                    d_x != scrollviewer_1.ContentHorizontalOffset || d_y != scrollviewer_1.ContentVerticalOffset ||
                                    d_window_w != this.ActualWidth || d_window_h != this.ActualHeight ||
                                    int_旋轉角度 != c_旋轉.int_旋轉)
                                {
                                    d_倍率 = img.ActualWidth;

                                    d_x        = scrollviewer_1.ContentHorizontalOffset;
                                    d_y        = scrollviewer_1.ContentVerticalOffset;
                                    d_window_w = this.ActualWidth;
                                    d_window_h = this.ActualHeight;
                                    int_旋轉角度   = c_旋轉.int_旋轉;

                                    bool_重新繪製 = true;
                                }
                            }

                            if (((TimeSpan)(DateTime.Now - time_避免捲動中算圖)).TotalMilliseconds < 800)  //連點低於400毫秒

                            {
                            }
                            else
                            {
                                d_倍率_old     = img.ActualWidth;
                                time_避免捲動中算圖 = DateTime.Now;
                            }
                        } catch {
                            s_path    = "";
                            bool_重新繪製 = false;
                            return;
                        }
                    });


                    if (bool_不剪裁且不重新繪製)
                    {
                        continue;
                    }
                    if (bool_重新繪製 == false)
                    {
                        continue;
                    }



                    if (bool_新圖片)
                    {
                        try {
                            if (File.Exists(ar_path[int_目前圖片位置]))
                            {
                                if (image_局部高清 == null)
                                {
                                    //MagickReadSettings mrs = new MagickReadSettings();
                                    //mrs.ColorSpace = ColorSpace.scRGB;


                                    MagickImage im5 = null;
                                    //
                                    try {
                                        im5 = new MagickImage(ar_path[int_目前圖片位置]);
                                    } catch (ImageMagick.MagickCorruptImageErrorException) {//某些BMP圖片會讀取失敗,所以先轉換成一般的 Bitmap
                                        im5 = new MagickImage(new System.Drawing.Bitmap(ar_path[int_目前圖片位置]));
                                    }


                                    //矯正顏色
                                    // Adding the second profile will transform the colorspace from CMYK to RGB
                                    if (im5.GetColorProfile() != null)
                                    {
                                        if (im5.GetColorProfile().Model != null)
                                        {
                                            //Log.print("***" + im5.GetColorProfile().Model + "***");
                                            im5.AddProfile(ColorProfile.SRGB);
                                        }
                                        else
                                        {
                                            // Log.print("無 GetColorProfile().Model");
                                        }
                                    }
                                    else
                                    {
                                        //Log.print("無2 GetColorProfile()");
                                        im5.AddProfile(ColorProfile.SRGB);
                                    }

                                    //Log.print(im5.ColorSpace + "  " + im5.ColorType);



                                    //如果讀取完圖片後,使用者已經切換到其他圖片,就不要寫入到「image_局部高清」,直接解析新圖片
                                    if (int_目前圖片位置 < 0 || int_目前圖片位置 >= ar_path.Count || s_path != ar_path[int_目前圖片位置])
                                    {
                                        image_局部高清 = null;
                                        s_path     = null;
                                        im5        = null;
                                        continue;
                                    }
                                    else
                                    {
                                        image_局部高清 = im5;
                                    }

                                    //System.Console.WriteLine("一般  " + s_path);
                                }
                                else
                                {
                                    //image_局部高清 = new ImageMagick.MagickImage((ar_path[int_目前圖片位置]));
                                    //System.Console.WriteLine("特殊 " + s_path);
                                }


                                //https://www.smashingmagazine.com/2015/06/efficient-image-resizing-with-imagemagick/
                                //不使用 漸進式渲染
                                image_局部高清.Interlace = Interlace.NoInterlace;


                                //剝離所有配置文件和註釋的圖像。
                                image_局部高清.Strip();

                                //雙線性插值
                                //image_局部高清.FilterType = FilterType.Hann;
                            }
                            else
                            {
                                s_path = "";
                                continue;
                            }
                        } catch (Exception e) {
                            s_path = "";
                            Log.print("*******局部高清 失敗 " + e);
                            continue;
                        }
                    }

                    //避免已經切換到其他圖片
                    if (int_目前圖片位置 < 0 || int_目前圖片位置 >= ar_path.Count)
                    {
                        continue;
                    }
                    if (d_倍率 != img.ActualWidth || s_path != ar_path[int_目前圖片位置])
                    {
                        continue;
                    }
                    if (bool_啟動局部高清 == false)
                    {
                        s_path = "";
                        continue;
                    }

                    double w03    = 1;
                    double h03    = 1;
                    double l03    = 1;
                    double t03    = 1;
                    double d_縮放倍率 = 1;

                    C_adapter.fun_UI執行緒(() => {
                        w03 = scrollviewer_1.ViewportWidth;
                        h03 = scrollviewer_1.ViewportHeight;
                        l03 = scrollviewer_1.ContentHorizontalOffset;
                        t03 = scrollviewer_1.ContentVerticalOffset;

                        if (c_旋轉.bool_垂直鏡像)
                        {
                            t03 = scrollviewer_1.ScrollableHeight - t03;
                        }
                        if (c_旋轉.bool_水平鏡像)
                        {
                            l03 = scrollviewer_1.ScrollableWidth - l03;
                        }

                        if (c_旋轉.int_旋轉 == 0)
                        {
                            if (w03 > grid_img.ActualWidth)
                            {
                                w03 = grid_img.ActualWidth;
                            }
                            if (h03 > grid_img.ActualHeight)
                            {
                                h03 = grid_img.ActualHeight;
                            }
                        }

                        if (c_旋轉.int_旋轉 == 180)
                        {
                            if (w03 > grid_img.ActualWidth)
                            {
                                w03 = grid_img.ActualWidth;
                            }
                            if (h03 > grid_img.ActualHeight)
                            {
                                h03 = grid_img.ActualHeight;
                            }
                            l03 = scrollviewer_1.ScrollableWidth - l03;
                            t03 = scrollviewer_1.ScrollableHeight - t03;
                        }

                        if (c_旋轉.int_旋轉 == 90)
                        {
                            if (w03 > grid_img.ActualWidth)
                            {
                                h03 = grid_img.ActualHeight;
                            }
                            else
                            {
                                h03 = scrollviewer_1.ViewportWidth;
                            }

                            if (h03 > grid_img.ActualHeight)
                            {
                                w03 = grid_img.ActualWidth;
                            }
                            else
                            {
                                w03 = scrollviewer_1.ViewportHeight;
                            }

                            var zzz2 = scrollviewer_1.ScrollableWidth - l03;
                            l03      = t03;
                            t03      = zzz2;
                        }

                        if (c_旋轉.int_旋轉 == 270)
                        {
                            if (w03 > grid_img.ActualWidth)
                            {
                                h03 = grid_img.ActualHeight;
                            }
                            else
                            {
                                h03 = scrollviewer_1.ViewportWidth;
                            }

                            if (h03 > grid_img.ActualHeight)
                            {
                                w03 = grid_img.ActualWidth;
                            }
                            else
                            {
                                w03 = scrollviewer_1.ViewportHeight;
                            }

                            var zzz2 = l03;
                            l03      = scrollviewer_1.ScrollableHeight - t03;
                            t03      = zzz2;
                        }
                    });


                    w03 += 50;
                    h03 += 50;

                    //避免圖片還沒完全載入
                    Thread.Sleep(30);


                    //複製物件
                    ImageMagick.IMagickImage ii = null;


                    try {
                        /*if (image_局部高清_50 != null && img.ActualWidth < int_img_w / 2) {
                         *  ii = image_局部高清_50.Clone();
                         * } else {*/
                        if (image_局部高清 == null)
                        {
                            continue;
                        }
                        ii = image_局部高清.Clone();
                        //}


                        //計算縮放比例
                        if (img.ActualWidth > img.ActualHeight)
                        {
                            d_縮放倍率 = img.ActualWidth / ii.Width;
                        }
                        else
                        {
                            d_縮放倍率 = img.ActualHeight / ii.Height;
                        }


                        bool_剪裁 = false;
                        if (d_縮放倍率 * int_img_w > 5000 || d_縮放倍率 * int_img_h > 5000)
                        {
                            bool_剪裁 = true;

                            //剪裁
                            ii.Crop(new MagickGeometry(
                                        (int)(l03 / d_縮放倍率),
                                        (int)(t03 / d_縮放倍率),
                                        (int)(w03 / d_縮放倍率),
                                        (int)(h03 / d_縮放倍率))
                                    );
                        }


                        //縮放
                        var mg    = new ImageMagick.MagickGeometry();
                        mg.Height = (int)(ii.Height * d_縮放倍率);
                        mg.Width  = (int)(ii.Width * d_縮放倍率);



                        if (int_高品質成像模式 == 1 || int_高品質成像模式 == 4)
                        {
                            ii.Resize(mg);//縮放圖片-快
                            if (d_縮放倍率 < 1)
                            {
                                ii.UnsharpMask(0.8, 0.8);//銳化-快速
                            }
                        }

                        if (int_高品質成像模式 == 2)
                        {
                            ii.Resize(mg);//縮放圖片-快
                            if (d_縮放倍率 < 1)
                            {
                                ii.RemoveWriteMask();     //沒有獨立顯卡的電腦,必須用這個語法來延遲,避免圖片顯示不出來
                                ii.UnsharpMask(0.8, 0.8); //銳化-快速
                            }
                        }

                        if (int_高品質成像模式 == 3 || int_高品質成像模式 == 3)
                        {
                            ii.Scale(mg);//縮放圖片-慢
                            if (d_縮放倍率 < 1)
                            {
                                ii.Sharpen();//銳化-慢
                            }
                        }



                        //ii.Sample(ii.Width,ii.Height);//品質差,速度極快
                        //ii.Extent(mg);//意義不明
                        //ii.Thumbnail(mg.Width, mg.Height);//某些情況下會很慢

                        //縮小圖片後進行銳化

                        /*if (d_縮放倍率 < 1) {
                         *  //ii.RemoveWriteMask();
                         *  //ii.UnsharpMask(0.8, 0.8);
                         *  //ii.UnsharpMask(0.25, 0.25,8,0.065);
                         * }*/


                        //System.Console.WriteLine($"mg {mg.Width}   ii {ii.Width}");

                        //避免已經切換到其他圖片
                        if (int_目前圖片位置 < 0 || int_目前圖片位置 >= ar_path.Count)
                        {
                            continue;
                        }
                        if (d_倍率 != img.ActualWidth || s_path != ar_path[int_目前圖片位置])
                        {
                            continue;
                        }
                        if (bool_啟動局部高清 == false)
                        {
                            s_path = "";
                            continue;
                        }


                        C_adapter.fun_UI執行緒(() => {
                            if (bool_剪裁)
                            {
                                img_局部高清.Margin = new Thickness(
                                    ((int)(l03 / d_縮放倍率)) * d_縮放倍率,
                                    ((int)(t03 / d_縮放倍率)) * d_縮放倍率,
                                    -((int)(l03 / d_縮放倍率)) * d_縮放倍率 - 5000,
                                    -((int)(t03 / d_縮放倍率)) * d_縮放倍率 - 5000
                                    );
                                img_局部高清.Width  = mg.Width;
                                img_局部高清.Height = mg.Height;
                                img_局部高清.Source = ii.ToBitmapSource();
                            }
                            else
                            {
                                img.Source = ii.ToBitmapSource();
                            }
                        });
                    } catch (Exception e) {
                        C_adapter.fun_UI執行緒(() => {
                            //MessageBox.Show("局部高清 錯誤 \n" + e.ToString());
                        });
                    }


                    Thread.Sleep(1);



                    C_adapter.fun_UI執行緒(() => {
                        //避免已經切換到其他圖片
                        if (int_目前圖片位置 < 0 || int_目前圖片位置 >= ar_path.Count)
                        {
                            return;
                        }
                        if (d_倍率 != img.ActualWidth || s_path != ar_path[int_目前圖片位置])
                        {
                            return;
                        }
                        if (bool_啟動局部高清 == false)
                        {
                            s_path = "";
                            return;
                        }

                        if (bool_剪裁)
                        {
                            img_局部高清.Visibility = Visibility.Visible;
                            if (ii.IsOpaque == false)
                            {
                                img.Visibility = Visibility.Hidden;
                                //System.Console.WriteLine($"透明");
                            }
                            //System.Console.WriteLine($"剪裁");
                        }
                        else
                        {
                            //System.Console.WriteLine($"原圖");
                            img_局部高清.Visibility = Visibility.Collapsed;
                            img.Visibility      = Visibility.Visible;
                        }
                    });


                    ii.Dispose();
                }
            }).Start();
        }