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


C# MagickImage.Write方法代码示例

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


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

示例1: Execute

        public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new RotateTransformViewModel(configData);
            // Read from file
            using (MagickImage image = new MagickImage(infile))
            {

                image.BackgroundColor = new MagickColor(Color.Black);
                if (conf.AutoRotate)
                {
                    ExifProfile profile = image.GetExifProfile();
                    image.AutoOrient();
                    profile.SetValue(ExifTag.Orientation, (UInt16)0);
                }
                if (conf.Angle > 0)
                    image.Rotate(conf.Angle);

                if(conf.FlipHorizontal)
                    image.Flop();

                if (conf.FlipVertical)
                    image.Flip();

                image.Format = MagickFormat.Jpeg;
                // Save the result
                image.Write(dest);
            }
            return dest;
        }
开发者ID:btugade,项目名称:digiCamControl,代码行数:29,代码来源:RotateTransform.cs

示例2: DefinesThatNeedToBeSetBeforeReadingAnImage

    public static void DefinesThatNeedToBeSetBeforeReadingAnImage()
    {
      MagickReadSettings settings = new MagickReadSettings();
      // Set define that tells the jpeg coder that the output image will be 32x32
      settings.SetDefine(MagickFormat.Jpeg, "size", "32x32");

      // Read image from file
      using (MagickImage image = new MagickImage(SampleFiles.SnakewareJpg))
      {
        // Create thumnail that is 32 pixels wide and 32 pixels high
        image.Thumbnail(32, 32);
        // Save image as tiff
        image.Write(SampleFiles.OutputDirectory + "Snakeware.tiff");
      }
    }
开发者ID:levesque,项目名称:Magick.NET,代码行数:15,代码来源:CommandLineOptionDefine.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: Test_IptcProfile

    public void Test_IptcProfile()
    {
      using (MagickImage input = new MagickImage(Files.MagickNETIconPNG))
      {
        IptcProfile profile = input.GetIptcProfile();
        Assert.IsNull(profile);

        profile = new IptcProfile();
        profile.SetValue(IptcTag.Headline, "Magick.NET");
        profile.SetValue(IptcTag.CopyrightNotice, "Copyright.NET");

        input.AddProfile(profile);

        using (MemoryStream memStream = new MemoryStream())
        {
          input.Format = MagickFormat.Tiff;
          input.Write(memStream);

          memStream.Position = 0;
          using (MagickImage output = new MagickImage(memStream))
          {
            profile = output.GetIptcProfile();
            Assert.IsNotNull(profile);
            TestValue(profile, IptcTag.Headline, "Magick.NET");
            TestValue(profile, IptcTag.CopyrightNotice, "Copyright.NET");
          }
        }
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:29,代码来源:TiffTests.cs

示例6: scale

 public static void scale(string image_path, string output_path, int width_mul = 150, int height_mul = 150)
 {
     using (MagickImage image = new MagickImage(image_path)) {
         image.Scale(new Percentage(width_mul), new Percentage(height_mul));
         image.Write(output_path);
     }
 }
开发者ID:Neonarg,项目名称:TempestNotifier,代码行数:7,代码来源:Image.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: blur

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

示例9: 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

示例10: 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

示例11: Exec

 public override void Exec()
 {
     try
     {
         var img = new ImageMagick.MagickImage(this.AsSrc);
         img.BackgroundColor = new MagickColor(Color.White);
         if (".jpg".Equals(Path.GetExtension(this.DstF), StringComparison.OrdinalIgnoreCase))
         {
             img.HasAlpha = false;
         }
         img.Resize(this.size);
         var as_dst = String.Format(this.AsDstF, this.Beg);
         var as_dir = Path.GetDirectoryName(as_dst);
         if (!Directory.Exists(as_dir))
         {
             Directory.CreateDirectory(as_dir);
         }
         img.Write(as_dst);
         this.Result.Files.Add(String.Format(this.DstF, this.Beg));
         this.Result.Count += 1;
     }
     catch (Exception e)
     {
         this.Result.Code = 500;
         this.Fails.Add(e);
     }
 }
开发者ID:Centny,项目名称:cswf.doc,代码行数:27,代码来源:ImgCov.cs

示例12: 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

示例13: Test_RemoveAlpha

    public void Test_RemoveAlpha()
    {
      string tempFile = GetTemporaryFileName(".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);

          Assert.IsTrue(image.HasAlpha);

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

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

示例14: ConvertCR2ToJPG

 public static void ConvertCR2ToJPG()
 {
   using (MagickImage image = new MagickImage(SampleFiles.StillLifeCR2))
   {
     image.Write(SampleFiles.OutputDirectory + "StillLife.jpg");
   }
 }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:7,代码来源:ReadRawImageFromCamera.cs

示例15: TestPixels

    private static void TestPixels(MagickImage image, MagickColor firstRow, MagickColor secondRow)
    {
      using (PixelCollection pixels = image.GetPixels())
      {
        for (int y = 0; y < 2; y++)
          for (int x = 0; x < 10; x++)
            ColorAssert.AreEqual(y == 0 ? firstRow : secondRow, pixels.GetPixel(x, y).ToColor());
      }

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

        using (MagickImage output = new MagickImage(memStream))
        {
          using (PixelCollection pixels = output.GetPixels())
          {
            for (int y = 0; y < 2; y++)
              for (int x = 0; x < 10; x++)
                ColorAssert.AreEqual(y == 0 ? firstRow : secondRow, pixels.GetPixel(x, y).ToColor());
          }
        }
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:26,代码来源:PixelCollectionTests.cs


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