当前位置: 首页>>代码示例>>C#>>正文


C# ImageMagick.MagickImage类代码示例

本文整理汇总了C#中ImageMagick.MagickImage的典型用法代码示例。如果您正苦于以下问题:C# MagickImage类的具体用法?C# MagickImage怎么用?C# MagickImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MagickImage类属于ImageMagick命名空间,在下文中一共展示了MagickImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Process

        private static void Process(int width, int height, MagickImage image, int? quality)
        {
            image.Strip();

            if (quality.HasValue)
            {
                image.Quality = quality.Value;
            }

            //模版的宽高比例
            var templateRate = (double)width / height;

            //原图片的宽高比例
            var nowRate = (double)image.Width / image.Height;

            if (templateRate < nowRate)
            {
                //以高为准缩放
                // Resize each image in the collection to a width of 200. When zero is specified for the height
                // the height will be calculated with the aspect ratio.
                image.Resize(0, height);
                image.ChopHorizontal(width, image.Width - width);
            }
            else
            {
                //以宽为准缩放
                image.Resize(width, 0);
                image.ChopVertical(height, image.Height - height);
            }
        }
开发者ID:yongfa365,项目名称:ImageResizer,代码行数:30,代码来源:Helper.cs

示例2: Execute

        public async Task<ValidationResult> Execute(MediaInfo mediaInfo, Int32 x, Int32 y, Int32 width, Int32 height)
        {
            if (x < 0 || y < 0 || width <= 0 || height <= 0)
            {
                return new ValidationResult("サイズの指定が不正です。");
            }

            var mediaContent = await _mediaRepository.Get(mediaInfo);
            if (mediaContent == null)
            {
                return new ValidationResult("指定されたメディアが見つかりませんでした。");
            }

            var data = await mediaContent.GetContentAsync();
            var imageInfo = new MagickImageInfo(data);
            if (imageInfo.Width < (x + width) || imageInfo.Height < (y + height))
            {
                return new ValidationResult("指定されたサイズは画像のサイズを超えています。");
            }

            // リサイズするよ!
            using (var image = new MagickImage(data))
            {
                image.Crop(new MagickGeometry(x, y, width, height));
                image.Page = new MagickGeometry(0, 0, width, height);
                
                // そして更新
                await _mediaRepository.Update(mediaInfo, image.ToByteArray());
            }

            return ValidationResult.Success;
        }
开发者ID:gogosub77,项目名称:Kanae,代码行数:32,代码来源:Crop.cs

示例3: Execute

        public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new CropTransformViewModel(configData);
            using (MagickImage image = new MagickImage(infile))
            {
                if (conf.FromLiveView && ServiceProvider.DeviceManager.SelectedCameraDevice != null)
                {
                    var prop = ServiceProvider.DeviceManager.SelectedCameraDevice.LoadProperties();
                    conf.Left = (int) (image.Width*prop.LiveviewSettings.HorizontalMin/100);
                    conf.Width = (image.Width*
                                  (prop.LiveviewSettings.HorizontalMax - prop.LiveviewSettings.HorizontalMin)/100);
                    conf.Top = (image.Height*prop.LiveviewSettings.VerticalMin/100);
                    conf.Height = (image.Height*(prop.LiveviewSettings.VerticalMax - prop.LiveviewSettings.VerticalMin)/
                                   100);
                }
                if (conf.CropMargins)
                {
                    conf.Left = image.Width * conf.WidthProcent / 100;
                    conf.Width = image.Width - (conf.Left*2);
                    conf.Top = image.Height * conf.HeightProcent / 100;
                    conf.Height = image.Height - (conf.Top*2);
                }

                MagickGeometry geometry = new MagickGeometry();
                geometry.Width = conf.Width;
                geometry.Height = conf.Height;
                geometry.X = conf.Left;
                geometry.Y = conf.Top;
                image.Crop(geometry);
                image.Format = MagickFormat.Jpeg;
                image.Write(dest);
            }
            return dest;
        }
开发者ID:btugade,项目名称:digiCamControl,代码行数:34,代码来源:CropTransform.cs

示例4: Test_Image_ByteArray

    public void Test_Image_ByteArray()
    {
      using (Image img = Image.FromFile(Files.Coders.PageTIF))
      {
        byte[] bytes = null;
        using (MemoryStream memStream = new MemoryStream())
        {
          img.Save(memStream, ImageFormat.Tiff);
          bytes = memStream.GetBuffer();
        }

        using (MagickImage image = new MagickImage(bytes))
        {
          image.CompressionMethod = CompressionMethod.Group4;

          using (MemoryStream memStream = new MemoryStream())
          {
            image.Write(memStream);
            memStream.Position = 0;

            using (MagickImage before = new MagickImage(Files.Coders.PageTIF))
            {
              using (MagickImage after = new MagickImage(memStream))
              {
                Assert.AreEqual(0.0, before.Compare(after, ErrorMetric.RootMeanSquared));
              }
            }
          }
        }
      }
    }
开发者ID:levesque,项目名称:Magick.NET,代码行数:31,代码来源:TiffTests.cs

示例5: CreateSketchesPath

        /// <summary>
        /// Returns the path to the sketch image just created
        /// <param name="mask">Mask image of the button</param>
        /// <param name="texture">Texture image of the item</param>
        /// <param name="nameSketch">Name of the image to create</param>
        public static string CreateSketchesPath(string mask, string texture, string nameSketch)
        {
            MagickImage Mask = new MagickImage(mask);

            MagickImage Texture = new MagickImage(texture);

            Texture.Crop(Mask.Width, Mask.Height);

            Texture.Composite(Mask, CompositeOperator.CopyAlpha);
            Mask.Composite(Texture, CompositeOperator.Multiply);
            MagickImage sketch = Mask;

            try
            {
                // sketch.Write(Helpers.ResourcesHelper.SketchesPath() + nameSketch);
                string p = Helpers.ResourcesHelper.SketchesPath() + nameSketch;
                System.IO.Stream s = new System.IO.FileStream(p, System.IO.FileMode.Create);

                sketch.Write(s);
                s.Close();
            }
            catch (MagickException ex)
            {
                string s= ex.Message;
            }
            catch
            {

            }
            sketch.Dispose();
            sketch = null;
            string path = Helpers.ResourcesHelper.SketchesPath() + nameSketch;
            return path;
        }
开发者ID:Amebus,项目名称:KillersWearsPrada,代码行数:39,代码来源:SketchHelper.cs

示例6: Test_Constructor

    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");
        }
      }
    }
开发者ID:levesque,项目名称:Magick.NET,代码行数:33,代码来源:ExifProfileTests.cs

示例7: crop

 public static void crop(string image_path, string output_path, Tuple<int, int> from, Tuple<int, int> to)
 {
     using (MagickImage image = new MagickImage(image_path)) {
         image.Crop(new MagickGeometry(from.Item1, from.Item2, to.Item1 - from.Item1, to.Item2 - from.Item2));
         image.Write(output_path);
     }
 }
开发者ID:Neonarg,项目名称:TempestNotifier,代码行数:7,代码来源:Image.cs

示例8: sharpen

 public static void sharpen(string image_path, string output_path, double radius = 5, double sigma = 30)
 {
     using (MagickImage image = new MagickImage(image_path)) {
         image.Sharpen(radius, sigma);
         image.Write(output_path);
     }
 }
开发者ID:Neonarg,项目名称:TempestNotifier,代码行数:7,代码来源:Image.cs

示例9: Test_Disabled

    public void Test_Disabled()
    {
      using (MemoryStream memStream = new MemoryStream())
      {
        using (StreamWriter writer = new StreamWriter(memStream))
        {
          writer.Write(@"push graphic-context
              viewbox 0 0 640 480
              image over 0,0 0,0 ""label:Magick.NET""
              pop graphic-context");

          writer.Flush();

          memStream.Position = 0;

          using (MagickImage image = new MagickImage())
          {
            ExceptionAssert.Throws<MagickMissingDelegateErrorException>(delegate ()
            {
              image.Read(memStream);
            });

            ExceptionAssert.Throws<MagickPolicyErrorException>(delegate ()
            {
              MagickReadSettings settings = new MagickReadSettings()
              {
                Format = MagickFormat.Mvg
              };

              image.Read(memStream, settings);
            });
          }
        }
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:35,代码来源:MvgTests.cs

示例10: AreEqual

 public static void AreEqual(MagickColor expected, MagickImage image, int x, int y)
 {
   using (PixelCollection pixels = image.GetPixels())
   {
     AreEqual(expected, pixels.GetPixel(x, y));
   }
 }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:7,代码来源:ColorAssert.cs

示例11: ConvertImageFromOneFormatToAnother

    public static void ConvertImageFromOneFormatToAnother()
    {
      // Read first frame of gif image
      using (MagickImage image = new MagickImage(SampleFiles.SnakewareGif))
      {
        // Save frame as jpg
        image.Write(SampleFiles.OutputDirectory + "Snakeware.jpg");
      }

      MagickReadSettings settings = new MagickReadSettings();
      // Tells the xc: reader the image to create should be 800x600
      settings.Width = 800;
      settings.Height = 600;

      using (MemoryStream memStream = new MemoryStream())
      {
        // Create image that is completely purple and 800x600
        using (MagickImage image = new MagickImage("xc:purple", settings))
        {
          // Sets the output format to png
          image.Format = MagickFormat.Png;
          // Write the image to the memorystream
          image.Write(memStream);
        }
      }

      // Read image from file
      using (MagickImage image = new MagickImage(SampleFiles.SnakewarePng))
      {
        // Sets the output format to jpeg
        image.Format = MagickFormat.Jpeg;
        // Create byte array that contains a jpeg file
        byte[] data = image.ToByteArray();
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:35,代码来源:ConvertImage.cs

示例12: Test_RemoveAlpha

    public void Test_RemoveAlpha()
    {
      string tempFile = Path.GetTempPath() + Guid.NewGuid().ToString() + ".png";
      try
      {
        using (MagickImage image = new MagickImage(Files.MagickNETIconPNG))
        {
          Assert.IsTrue(image.HasAlpha);
          image.ColorAlpha(new MagickColor("yellow"));
          image.HasAlpha = true;
          image.Write(tempFile);

          image.Read(tempFile);

          // TODO: Figure out why this does not fail in a single run but does when all tests are run.
          //Assert.IsTrue(image.HasAlpha);

          PngOptimizer optimizer = new PngOptimizer();
          optimizer.LosslessCompress(tempFile);

          image.Read(tempFile);
          Assert.IsFalse(image.HasAlpha);
        }
      }
      finally
      {
        if (File.Exists(tempFile))
          File.Delete(tempFile);
      }
    }
开发者ID:levesque,项目名称:Magick.NET,代码行数:30,代码来源:PngOptimizerTests.cs

示例13: Test_Format

 public void Test_Format()
 {
   using (MagickImage image = new MagickImage(Files.Coders.CartoonNetworkStudiosLogoAI))
   {
     Test_Image(image);
   }
 }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:7,代码来源:PdfTests.cs

示例14: WriteExif

		//public PhotoInfo ReadExif2(string name)
		//{
		//	PhotoInfo info = new PhotoInfo() { FileName = name };

		//	using (MagickImage image = new MagickImage(name))
		//	{
		//		ExifProfile profile = image.GetExifProfile();

		//		ExifValue value = profile.GetValue(ExifTag.DateTimeDigitized);

		//		if (value.Value == null)
		//			throw new Exception("Неудалось считать дату и время файла");

		//		info.DateTimeDigitized = (DateTime)value.Value;

		//		value = profile.GetValue(ExifTag.Model);

		//		info.Model = (string)value.Value;

		//		if (info.Model == null)
		//			info.Model = "Неизвестная модель";

		//	}

		//	return info;
		//}

		public static void WriteExif(PhotoInfo info, int? quality)
        {
			// Для моего телефона не работает метод image.AddProfile. Т.к. для моего телефона дату менять ненадо, то пропускаем.
			if (info.Model.ToUpper().Contains("HUAWEI P7-L10"))
				return;

			using (MagickImage image = new MagickImage(info.FileName))
            {
				if (quality != null && quality < image.Quality)
					image.Quality = quality.Value;

                ExifProfile profile = image.GetExifProfile();

				if (profile == null)
					profile = new ExifProfile();

                profile.SetValue(ExifTag.DateTimeDigitized, info.DateTimeDigitized.ToString(DATE_TIME_FORMAT));
				profile.SetValue(ExifTag.DateTime, info.DateTimeDigitized.ToString(DATE_TIME_FORMAT));
				profile.SetValue(ExifTag.DateTimeOriginal, info.DateTimeDigitized.ToString(DATE_TIME_FORMAT));

				//try
				//{
					image.AddProfile(profile, true);

					image.Write(info.FileName);
				//}
				//catch (Exception exc)
				//{ 
				
				//}
            }
        }
开发者ID:SlidEnergy,项目名称:PhotoOrganizer,代码行数:59,代码来源:ExifFile.cs

示例15: Test_Log

    public void Test_Log()
    {
      using (MagickImage image = new MagickImage(Files.SnakewarePNG))
      {
        int count = 0;
        EventHandler<LogEventArgs> logDelegate = delegate (object sender, LogEventArgs arguments)
        {
          Assert.IsNull(sender);
          Assert.IsNotNull(arguments);
          Assert.AreNotEqual(LogEvents.None, arguments.EventType);
          Assert.IsNotNull(arguments.Message);
          Assert.AreNotEqual(0, arguments.Message.Length);

          count++;
        };

        MagickNET.Log += logDelegate;

        image.Flip();
        Assert.AreEqual(0, count);

        MagickNET.SetLogEvents(LogEvents.All);

        image.Flip();
        Assert.AreNotEqual(0, count);

        MagickNET.Log -= logDelegate;
        count = 0;

        image.Flip();
        Assert.AreEqual(0, count);
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:33,代码来源:MagickNETTests.cs


注:本文中的ImageMagick.MagickImage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。