Class that contains setting for when an image is being read.
Ejemplo n.º 1
2
    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");
      }
    }
Ejemplo n.º 2
0
    public void Test_Collection_Read()
    {
      using (MagickImageCollection collection = new MagickImageCollection())
      {
        MagickReadSettings settings = new MagickReadSettings();
        settings.Density = new Density(150);

        collection.Read(Files.RoseSparkleGIF, settings);

        Assert.AreEqual(150, collection[0].Density.X);

        settings = new MagickReadSettings();
        settings.FrameIndex = 1;

        collection.Read(Files.RoseSparkleGIF, settings);

        Assert.AreEqual(1, collection.Count);

        settings = new MagickReadSettings();
        settings.FrameIndex = 1;
        settings.FrameCount = 2;

        collection.Read(Files.RoseSparkleGIF, settings);

        Assert.AreEqual(2, collection.Count);

        settings = null;
        collection.Read(Files.RoseSparkleGIF, settings);
      }
    }
Ejemplo n.º 3
0
 public void Test_Constructor()
 {
   ExceptionAssert.Throws<ArgumentNullException>(() =>
   {
     MagickReadSettings settings = new MagickReadSettings(null);
   });
 }
Ejemplo n.º 4
0
    public void Test_Disabled()
    {
      using (MemoryStream memStream = new MemoryStream())
      {
        using (StreamWriter writer = new StreamWriter(memStream))
        {
          writer.Write(@"
            <?xml version=""1.0"" encoding=""UTF-8""?>
            <image>
              <read filename=""/tmp/text.gif"" />
            </image>");

          writer.Flush();

          memStream.Position = 0;

          using (MagickImage image = new MagickImage())
          {
            MagickReadSettings readSettings = new MagickReadSettings()
            {
              Format = MagickFormat.Msl
            };

            ExceptionAssert.Throws<MagickPolicyErrorException>(delegate ()
            {
              image.Read(memStream, readSettings);
            });
          }
        }
      }
    }
Ejemplo n.º 5
0
 private MagickReadSettings CreateMagickReadSettings(XmlElement element)
 {
   if (element == null)
     return null;
   MagickReadSettings result = new MagickReadSettings();
   result.ColorSpace = Variables.GetValue<Nullable<ColorSpace>>(element, "colorSpace");
   result.Defines = CreateIReadDefines(element["defines"]);
   result.Density = Variables.GetValue<Nullable<PointD>>(element, "density");
   result.Format = Variables.GetValue<Nullable<MagickFormat>>(element, "format");
   result.FrameCount = Variables.GetValue<Nullable<Int32>>(element, "frameCount");
   result.FrameIndex = Variables.GetValue<Nullable<Int32>>(element, "frameIndex");
   result.Height = Variables.GetValue<Nullable<Int32>>(element, "height");
   result.PixelStorage = CreatePixelStorageSettings(element["pixelStorage"]);
   result.UseMonochrome = Variables.GetValue<Nullable<Boolean>>(element, "useMonochrome");
   result.Width = Variables.GetValue<Nullable<Int32>>(element, "width");
   XmlElement setDefine = (XmlElement)element.SelectSingleNode("setDefine");
   if (setDefine != null)
   {
     MagickFormat format_ = XmlHelper.GetAttribute<MagickFormat>(setDefine, "format");
     String name_ = XmlHelper.GetAttribute<String>(setDefine, "name");
     String value_ = XmlHelper.GetAttribute<String>(setDefine, "value");
     result.SetDefine(format_,name_,value_);
   }
   return result;
 }
Ejemplo n.º 6
0
    public static void ConvertPDFTOneImage()
    {
      MagickReadSettings settings = new MagickReadSettings();
      // Settings the density to 300 dpi will create an image with a better quality
      settings.Density = new PointD(300, 300);

      using (MagickImageCollection images = new MagickImageCollection())
      {
        // Add all the pages of the pdf file to the collection
        images.Read(SampleFiles.SnakewarePdf, settings);

        // Create new image that appends all the pages horizontally
        using (MagickImage horizontal = images.AppendHorizontally())
        {
          // Save result as a png
          horizontal.Write(SampleFiles.OutputDirectory + "Snakeware.horizontal.png");
        }

        // Create new image that appends all the pages horizontally
        using (MagickImage vertical = images.AppendVertically())
        {
          // Save result as a png
          vertical.Write(SampleFiles.OutputDirectory + "Snakeware.vertical.png");
        }
      }
    }
Ejemplo n.º 7
0
    public void Test_AlphaUnblend()
    {
      MagickReadSettings settings = new MagickReadSettings()
      {
        Defines = new PsdReadDefines()
        {
          AlphaUnblend = false
        }
      };

      using (MagickImage image = new MagickImage())
      {
        image.Read(Files.Coders.PlayerPSD, settings);

        string define = image.Settings.GetDefine(MagickFormat.Psd, "alpha-unblend");
        Assert.AreEqual("False", define);
      }

      using (MagickImage image = new MagickImage())
      {
        settings.Defines = new PsdReadDefines()
        {
          AlphaUnblend = true
        };

        image.Read(Files.Coders.PlayerPSD, settings);

        string define = image.Settings.GetDefine(MagickFormat.Psd, "alpha-unblend");
        Assert.IsNull(define);
      }
    }
Ejemplo n.º 8
0
    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();
      }
    }
Ejemplo n.º 9
0
    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);
            });
          }
        }
      }
    }
Ejemplo n.º 10
0
 public void Test_Image_Exceptions()
 {
   ExceptionAssert.Throws<ArgumentException>(delegate ()
   {
     MagickReadSettings settings = new MagickReadSettings();
     settings.FrameCount = 2;
     new MagickImage(Files.RoseSparkleGIF, settings);
   });
 }
Ejemplo n.º 11
0
 private void ApplyDimensions(MagickReadSettings settings)
 {
   if (settings.Width.HasValue && settings.Height.HasValue)
     Size = settings.Width + "x" + settings.Height;
   else if (settings.Width.HasValue)
     Size = settings.Width + "x";
   else if (settings.Height.HasValue)
     Size = "x" + settings.Height;
 }
Ejemplo n.º 12
0
    private void ApplyFrame(MagickReadSettings settings)
    {
      if (!settings.FrameIndex.HasValue && !settings.FrameCount.HasValue)
        return;

      Scenes = settings.GetScenes();
      Scene = settings.FrameIndex.HasValue ? settings.FrameIndex.Value : 0;
      NumberScenes = settings.FrameCount.HasValue ? settings.FrameCount.Value : 1;
    }
    private static MagickReadSettings CreateSettings()
    {
      MagickReadSettings settings = new MagickReadSettings();
      settings.PixelStorage = new PixelStorageSettings(StorageType.Double, "RGBA");
      settings.Width = 2;
      settings.Height = 1;

      return settings;
    }
Ejemplo n.º 14
0
    internal MagickReadSettings(MagickReadSettings settings)
    {
      Copy(settings);

      ApplyDefines(settings);
      ApplyDimensions(settings);
      ApplyFrame(settings);

      PixelStorage = settings.PixelStorage?.Clone();
    }
Ejemplo n.º 15
0
    private void ApplyDefines(MagickReadSettings settings)
    {
      if (settings.Defines == null)
        return;

      foreach (IDefine define in settings.Defines.Defines)
      {
        SetOption(GetDefineKey(define), define.Value);
      }
    }
Ejemplo n.º 16
0
        public PdfCov(String src, String dst_f, int maxw = 768, int maxh = 1024, double densityx = 96, double densityy = 96, int beg = 0) : base(src, dst_f, maxw, maxh, beg)
        {

            this.DensityX = densityx;
            this.DensityY = densityy;
            this.size = new MagickGeometry(maxw, maxh);
            this.size.Greater = true;
            this.settings = new MagickReadSettings();
            this.settings.Density = new PointD(this.DensityX, this.DensityY);
        }
Ejemplo n.º 17
0
    public void Test_Image_Read()
    {
      using (MagickImage image = new MagickImage())
      {
        MagickReadSettings settings = new MagickReadSettings();
        settings.Density = new PointD(300);

        image.Read(Files.SnakewarePNG, settings);

        Assert.AreEqual(300, image.Density.X);

        settings = null;
        image.Read(Files.ImageMagickJPG, settings);
      }

      using (MagickImage image = new MagickImage(Files.RoseSparkleGIF))
      {
        MagickImage imageA = new MagickImage();
        MagickImage imageB = new MagickImage();

        MagickReadSettings settings = new MagickReadSettings();

        imageA.Read(Files.RoseSparkleGIF, settings);
        Assert.AreEqual(image, imageA);

        settings = new MagickReadSettings();
        settings.FrameIndex = 1;

        imageA.Read(Files.RoseSparkleGIF, settings);
        Assert.AreNotEqual(image, imageA);

        imageB.Read(Files.RoseSparkleGIF + "[1]");
        Assert.AreEqual(imageA, imageB);

        settings = new MagickReadSettings();
        settings.FrameIndex = 2;

        imageA.Read(Files.RoseSparkleGIF, settings);
        Assert.AreNotEqual(image, imageA);

        imageB.Read(Files.RoseSparkleGIF + "[2]");
        Assert.AreEqual(imageA, imageB);

        ExceptionAssert.Throws<MagickOptionErrorException>(delegate ()
        {
          settings = new MagickReadSettings();
          settings.FrameIndex = 3;

          imageA.Read(Files.RoseSparkleGIF, settings);
        });

        imageA.Dispose();
        imageB.Dispose();
      }
    }
Ejemplo n.º 18
0
			// Get image from Imagick
			protected byte[] GetImageFromImagick(Dictionary<string, string> chart)
			{
				string svgdata = chart["stream"];
				if (Empty(svgdata))
					return null;
				svgdata = svgdata.Replace("+", " "); // Replace + to ' '

				// IMPORTANT NOTE: Magick.NET does not support SVG syntax: fill="url('#id')". Need to replace the attributes:
				// - fill="url('#id')" style="fill-opacity: n1; ..."
				// to:
				// - fill="color" style="fill-opacity: n2; ..."
				// from xml below:
				// <linearGradient ... id="id">
				// <stop stop-opacity="0.5" stop-color="#ff0000" offset="0%"></stop>
				// ...</linearGradient>

				var doc = new XmlDocument();
				doc.LoadXml(svgdata);
				var nodes = doc.SelectNodes("//*[@fill]");
				foreach (XmlElement node in nodes) {
					string fill = node.GetAttribute("fill");
					string style = node.GetAttribute("style");
					if (fill.StartsWith("url(") && fill.Substring(5, 1) == "#") {
						var id = fill.Substring(6, fill.Length - 8);
						var nsmgr = new XmlNamespaceManager(doc.NameTable);
						nsmgr.AddNamespace("ns", "http://www.w3.org/2000/svg");
						var gnode = doc.SelectSingleNode("//*/ns:linearGradient[@id='" + id + "']", nsmgr);
						if (gnode != null) {
							XmlElement snode = (XmlElement)gnode.SelectSingleNode("ns:stop[@offset='0%']", nsmgr);
							if (snode != null) {
								var fillcolor = snode.GetAttribute("stop-color");
								var fillopacity = snode.GetAttribute("stop-opacity");
								if (!Empty(fillcolor))
									node.SetAttribute("fill", fillcolor);
								if (!Empty(fillopacity) && !Empty(style)) {
									style = Regex.Replace(style, @"fill-opacity:\s*\S*;", "fill-opacity: " + fillopacity + ";");
									node.SetAttribute("style", style);
								}
							}
						}
					}
				}
				svgdata = doc.DocumentElement.OuterXml;
				ImageMagick.MagickNET.SetLogEvents(ImageMagick.LogEvents.All);
				ImageMagick.MagickReadSettings settings = new ImageMagick.MagickReadSettings();
				settings.ColorSpace = ImageMagick.ColorSpace.RGB;
				settings.Format = ImageMagick.MagickFormat.Svg;
				using var image = new ImageMagick.MagickImage(Encoding.UTF8.GetBytes(svgdata), settings);

				//image.BackgroundColor = new ImageMagick.MagickColor(System.Drawing.Color.Transparent);
				image.Format = ImageMagick.MagickFormat.Png;
				return image.ToByteArray();
			}
Ejemplo n.º 19
0
    public void Test_Dimensions()
    {
      using (MagickImage image = new MagickImage())
      {
        MagickReadSettings settings = new MagickReadSettings();
        settings.Width = 100;

        image.Read(Files.Logos.MagickNETSVG, settings);

        Assert.AreEqual(100, image.Width);
        Assert.AreEqual(48, image.Height);

        settings.Width = null;
        settings.Height = 200;

        image.Read(Files.Logos.MagickNETSVG, settings);

        Assert.AreEqual(415, image.Width);
        Assert.AreEqual(200, image.Height);

        settings.Width = 300;
        settings.Height = 300;

        image.Read(Files.Logos.MagickNETSVG, settings);

        Assert.AreEqual(300, image.Width);
        Assert.AreEqual(144, image.Height);

        image.Ping(Files.Logos.MagickNETSVG, settings);

        Assert.AreEqual(300, image.Width);
        Assert.AreEqual(144, image.Height);

        using (FileStream fs = File.OpenRead(Files.Logos.MagickNETSVG))
        {
          fs.Seek(55, SeekOrigin.Begin);

          ExceptionAssert.Throws<MagickMissingDelegateErrorException>(() =>
          {
            new MagickImageInfo(fs, settings);
          });

          fs.Seek(55, SeekOrigin.Begin);

          settings.Format = MagickFormat.Svg;

          MagickImageInfo info = new MagickImageInfo(fs, settings);
          Assert.AreEqual(300, info.Width);
          Assert.AreEqual(144, info.Height);
        }
      }
    }
    public void Test_Collection_Exceptions()
    {
      using (MagickImageCollection collection = new MagickImageCollection())
      {
        MagickReadSettings settings = new MagickReadSettings();
        settings.PixelStorage = new PixelStorageSettings();

        ExceptionAssert.Throws<ArgumentException>(delegate ()
        {
          collection.Read(Files.RoseSparkleGIF, settings);
        });
      }
    }
Ejemplo n.º 21
0
    public void Test_Image_Read_Density()
    {
      using (MagickImage image = new MagickImage())
      {
        MagickReadSettings settings = new MagickReadSettings();
        settings.Density = new Density(300);

        image.Read(Files.SnakewarePNG, settings);

        Assert.AreEqual(300, image.Density.X);

        settings = null;
        image.Read(Files.ImageMagickJPG, settings);
      }
    }
Ejemplo n.º 22
0
        public void Convert2Jpeg(bool rotate = false)
        {
            try
            {
                MagickReadSettings settings = new MagickReadSettings();

                // Settings the density to 300 dpi will create an image with a better quality
                settings.Density = new PointD(300, 300);

                using (MagickImageCollection images = new MagickImageCollection())
                {
                    // Add all the pages of the pdf file to the collection
                    images.Read(_pdf.FullName, settings);

                    if (images.Count > 0 && images[0].Format == MagickFormat.Pdf)
                    {
                        _logger.InfoFormat("Handle {0}", _pdf.FullName);

                        int page = 1;
                        foreach (MagickImage image in images)
                        {
                            var newFileName = GetFilePageName(page) + ".jpg";

                            // Need page rotation?
                            if (rotate)
                                image.Rotate(90.0);

                            // Write page to file that contains the page number
                            image.Format = MagickFormat.Jpg;
                            image.CompressionMethod = CompressionMethod.JPEG;
                            image.Quality = 75;
                            image.Write(newFileName);

                            _logger.InfoFormat("-> {0}", newFileName);

                            // Writing to a specific format works the same as for a single image
                            page++;
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex);
            }
        }
Ejemplo n.º 23
0
    public void Test_IgnoreTags()
    {
      using (MagickImage image = new MagickImage())
      {
        image.Settings.SetDefine(MagickFormat.Tiff, "ignore-tags", "32934");
        image.Read(Files.Coders.IgnoreTagTIF);
      }

      using (MagickImage image = new MagickImage())
      {
        MagickReadSettings readSettings = new MagickReadSettings(new TiffReadDefines()
        {
          IgnoreTags = new string[] { "32934" }
        });
        image.Read(Files.Coders.IgnoreTagTIF, readSettings);
      }
    }
Ejemplo n.º 24
0
    public void Test_FitPage()
    {
      MagickReadSettings settings = new MagickReadSettings()
      {
        Defines = new PdfReadDefines()
        {
          FitPage = new MagickGeometry(50, 40)
        }
      };

      using (MagickImage image = new MagickImage())
      {
        image.Read(Files.Coders.CartoonNetworkStudiosLogoAI, settings);

        Assert.IsTrue(image.Width <= 50);
        Assert.IsTrue(image.Height <= 40);
      }
    }
        public override Stream CompressImageData(Image image, Stream imageData, out string optimizedExtension)
        {
            var settings = _config.Optimizers["ImageMagickImageOptimizer"].Parameters;

            int _imageQuality = Int32.Parse(settings["imageQuality"]);

            MagickReadSettings magickSettings = new MagickReadSettings();

            switch (image.Extension.ToLower())
            {
                case ".png":
                    magickSettings.Format = MagickFormat.Png;
                    break;
                case ".jpg":
                    magickSettings.Format = MagickFormat.Jpg;
                    break;
                case ".jpeg":
                    magickSettings.Format = MagickFormat.Jpeg;
                    break;
                case ".bmp":
                    magickSettings.Format = MagickFormat.Bmp;
                    break;
                default:
                    magickSettings.Format = MagickFormat.Jpg;
                    break;
            }

            using (MagickImage img = new MagickImage(imageData, magickSettings))
            {
                MemoryStream compressed = new MemoryStream();

                img.Quality = _imageQuality;
                img.Write(compressed);

                if (compressed == null)
                {
                    optimizedExtension = "";
                    return null;
                }

                optimizedExtension = Path.GetExtension(image.FilePath);
                return compressed;
            }
        }
Ejemplo n.º 26
0
    public void Test_Read_Bytes()
    {
#if Q8
      var bytes = new byte[] { 1, 2, 3, 4 };
#elif Q16 || Q16HDRI
      var bytes = new byte[] { 1, 0, 2, 0, 3, 0, 4, 0 };
#else
#error Not implemented!
#endif

      MagickReadSettings settings = new MagickReadSettings()
      {
        Width = 1,
        Height = 1
      };

      settings.Format = MagickFormat.Rgba;
      using (MagickImage image = new MagickImage(bytes, settings))
      {
        using (PixelCollection pixels = image.GetReadOnlyPixels())
        {
          Pixel pixel = pixels.GetPixel(0, 0);
          Assert.AreEqual(4, pixel.Channels);
          Assert.AreEqual(1, pixel.GetChannel(0));
          Assert.AreEqual(2, pixel.GetChannel(1));
          Assert.AreEqual(3, pixel.GetChannel(2));
          Assert.AreEqual(4, pixel.GetChannel(3));
        }
      }

      settings.Format = MagickFormat.Rgbo;
      using (MagickImage image = new MagickImage(bytes, settings))
      {
        using (PixelCollection pixels = image.GetReadOnlyPixels())
        {
          Pixel pixel = pixels.GetPixel(0, 0);
          Assert.AreEqual(4, pixel.Channels);
          Assert.AreEqual(1, pixel.GetChannel(0));
          Assert.AreEqual(2, pixel.GetChannel(1));
          Assert.AreEqual(3, pixel.GetChannel(2));
          Assert.AreEqual(Quantum.Max - 4, pixel.GetChannel(3));
        }
      }
    }
Ejemplo n.º 27
0
		private static void ConvertPdfToOneTif()
		{
			// Log all events
			//MagickNET.SetLogEvents(LogEvents.All | LogEvents.Trace);
			// Set the log handler (all threads use the same handler)
			//MagickNET.Log += DetailedDebugInformationSamples.MagickNET_Log;

			string sampleDocsDirectory = @"E:\projects\ImageProcessing\sampledocs\";
			string sampleFile = "sample6.pdf";

			try
			{
				MagickReadSettings settings = new MagickReadSettings();
				settings.Density = new PointD(300, 300);

				using (MagickImageCollection images = new MagickImageCollection())
				{
					// Add all the pages of the source file to the collection
					images.Read(Path.Combine(sampleDocsDirectory, sampleFile), settings);

					//Show page count
					Console.WriteLine("page count for {0} {1}", sampleFile, images.Count);

					string baseFileName = Path.GetFileNameWithoutExtension(sampleFile);

					// Create new image that appends all the pages horizontally
					//using (MagickImage vertical = images.AppendVertically())
					//{
					//	vertical.CompressionMethod = CompressionMethod.Group4;
					//	Console.WriteLine("saving file: {0}", baseFileName + ".tif");
					//	vertical.Write(sampleDocsDirectory + baseFileName + ".tif");
					//}

					Console.WriteLine("saving file: {0}", baseFileName + ".tif");
					images.Write(sampleDocsDirectory + baseFileName + ".tif");
				}

			}
			catch (Exception ex)
			{
				Console.WriteLine("ConvertPdfToOneTif {0}", ex.Message);
			}
		}
Ejemplo n.º 28
0
    public void Test_IgnoreExifPoperties()
    {
      MagickReadSettings settings = new MagickReadSettings()
      {
        Defines = new TiffReadDefines()
        {
          IgnoreExifPoperties = true
        }
      };

      using (MagickImage image = new MagickImage())
      {
        image.Read(Files.InvitationTif);
        Assert.IsNotNull(image.GetAttribute("exif:PixelXDimension"));

        image.Read(Files.InvitationTif, settings);
        Assert.IsNull(image.GetAttribute("exif:PixelXDimension"));
      }
    }
Ejemplo n.º 29
0
    public void Test_SkipProfiles()
    {
      MagickReadSettings settings = new MagickReadSettings()
      {
        Defines = new JpegReadDefines()
        {
          SkipProfiles = ProfileTypes.Iptc | ProfileTypes.Icc
        }
      };

      using (MagickImage image = new MagickImage())
      {
        image.Read(Files.FujiFilmFinePixS1ProJPG);
        Assert.IsNotNull(image.GetIptcProfile());

        image.Read(Files.FujiFilmFinePixS1ProJPG, settings);
        Assert.IsNull(image.GetIptcProfile());
        Assert.AreEqual("Icc,Iptc", image.GetDefine(MagickFormat.Unknown, "profile:skip"));
      }
    }
Ejemplo n.º 30
0
        /// <summary>
        /// Returns a decoded image from ImageMagick - assumes only a singal frame,
        /// as many methods I need are internal to ImageSharp
        /// </summary>
        /// <typeparam name="TPixel"></typeparam>
        /// <param name="configuration"></param>
        /// <param name="stream"></param>
        /// <returns></returns>
        public Image <TPixel> Decode <TPixel>(Configuration configuration, Stream stream)
            where TPixel : unmanaged, SixLabors.ImageSharp.PixelFormats.IPixel <TPixel>
        {
            var settings = new Magick.MagickReadSettings();

            using var magickImageCollection = new Magick.MagickImageCollection(stream, settings);

            if (magickImageCollection.Count == 0)
            {
                throw new Exception("No images found");
            }

            Magick.IMagickImage <ushort> magickImage = magickImageCollection[0];
            var width  = magickImage.Width;
            var height = magickImage.Height;

            var image = new Image <TPixel>(configuration, width, height);


            var framePixels = image.GetPixelMemoryGroup();


            using Magick.IUnsafePixelCollection <ushort> pixels = magickImage.GetPixelsUnsafe();
            if (magickImage.Depth == 8 || magickImage.Depth == 6 || magickImage.Depth == 4 || magickImage.Depth == 2 || magickImage.Depth == 1 || magickImage.Depth == 10 || magickImage.Depth == 12)
            {
                byte[]? data = pixels.ToByteArray(Magick.PixelMapping.RGBA);

                FromRgba32Bytes(configuration, data, framePixels);
            }
            else if (magickImage.Depth == 16 || magickImage.Depth == 14)
            {
                ushort[]? data = pixels.ToShortArray(Magick.PixelMapping.RGBA);
                Span <byte> bytes = MemoryMarshal.Cast <ushort, byte>(data.AsSpan());
                FromRgba64Bytes(configuration, bytes, framePixels);
            }
            else
            {
                throw new InvalidOperationException();
            }
            return(image);
        }
Ejemplo n.º 31
0
    public static void ReadImage()
    {
      // Read from file.
      using (MagickImage image = new MagickImage(SampleFiles.SnakewareJpg))
      {
      }

      // Read from stream.
      using (MemoryStream memStream = LoadMemoryStreamImage())
      {
        using (MagickImage image = new MagickImage(memStream))
        {
        }
      }

      // Read from byte array.
      byte[] data = LoadImageBytes();
      using (MagickImage image = new MagickImage(data))
      {
      }

      // Read image that has no predefined dimensions.
      MagickReadSettings settings = new MagickReadSettings();
      settings.Width = 800;
      settings.Height = 600;
      using (MagickImage image = new MagickImage("xc:yellow", settings))
      {
      }

      using (MagickImage image = new MagickImage())
      {
        image.Read(SampleFiles.SnakewareJpg);
        image.Read(data);
        image.Read("xc:yellow", settings);

        using (MemoryStream memStream = LoadMemoryStreamImage())
        {
          image.Read(memStream);
        }
      }
    }
Ejemplo n.º 32
0
    public void Test_Colors_Size()
    {
      MagickReadSettings settings = new MagickReadSettings()
      {
        Defines = new JpegReadDefines()
        {
          Colors = 100,
          Size = new MagickGeometry(61, 59)
        }
      };

      using (MagickImage image = new MagickImage())
      {
        image.Read(Files.ImageMagickJPG, settings);

        Assert.IsTrue(image.TotalColors <= 100);
        Assert.AreEqual(100, image.TotalColors, 1);
        Assert.AreEqual(62, image.Width);
        Assert.AreEqual(59, image.Height);
      }
    }
Ejemplo n.º 33
0
 private void ExecuteFrameIndex(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.FrameIndex = GetValue <Nullable <Int32> >(element, "value");
 }
Ejemplo n.º 34
0
 private void ExecuteHeight(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.Height = GetValue <Nullable <Int32> >(element, "value");
 }
Ejemplo n.º 35
0
 private void ExecutePage(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.Page = GetValue <MagickGeometry>(element, "value");
 }
Ejemplo n.º 36
0
 private void ExecuteFontFamily(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.FontFamily = GetValue <String>(element, "value");
 }
Ejemplo n.º 37
0
 private void ExecuteTextGravity(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.TextGravity = GetValue <Gravity>(element, "value");
 }
Ejemplo n.º 38
0
 private void ExecuteDepth(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.Depth = GetValue <Int32>(element, "value");
 }
Ejemplo n.º 39
0
 private void ExecuteFontStyle(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.FontStyle = GetValue <FontStyleType>(element, "value");
 }
Ejemplo n.º 40
0
 private void ExecuteStrokeDashOffset(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.StrokeDashOffset = GetValue <double>(element, "value");
 }
Ejemplo n.º 41
0
 private void ExecuteExtractArea(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.ExtractArea = GetValue <MagickGeometry>(element, "value");
 }
Ejemplo n.º 42
0
 private void ExecuteTextAntiAlias(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.TextAntiAlias = GetValue <Boolean>(element, "value");
 }
Ejemplo n.º 43
0
 private void ExecuteUseMonochrome(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.UseMonochrome = GetValue <Boolean>(element, "value");
 }
Ejemplo n.º 44
0
 private void ExecuteStrokeMiterLimit(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.StrokeMiterLimit = GetValue <Int32>(element, "value");
 }
Ejemplo n.º 45
0
 private void ExecuteFormat(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.Format = GetValue <MagickFormat>(element, "value");
 }
Ejemplo n.º 46
0
 private void ExecuteTextEncoding(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.TextEncoding = GetValue <Encoding>(element, "value");
 }
Ejemplo n.º 47
0
 private void ExecuteFontWeight(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.FontWeight = GetValue <FontWeight>(element, "value");
 }
Ejemplo n.º 48
0
 private void ExecuteStrokeWidth(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.StrokeWidth = GetValue <double>(element, "value");
 }
Ejemplo n.º 49
0
 private void ExecuteFontPointsize(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.FontPointsize = GetValue <double>(element, "value");
 }
Ejemplo n.º 50
0
 private void ExecuteTextUnderColor(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.TextUnderColor = GetValue <MagickColor>(element, "value");
 }
Ejemplo n.º 51
0
 private void ExecuteFillRule(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.FillRule = GetValue <FillRule>(element, "value");
 }
Ejemplo n.º 52
0
 private void ExecuteTextKerning(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.TextKerning = GetValue <double>(element, "value");
 }
Ejemplo n.º 53
0
 private void ExecuteTextDirection(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.TextDirection = GetValue <TextDirection>(element, "value");
 }
Ejemplo n.º 54
0
 private void ExecuteStrokeLineJoin(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.StrokeLineJoin = GetValue <LineJoin>(element, "value");
 }
Ejemplo n.º 55
0
 private void ExecuteEndian(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.Endian = GetValue <Endian>(element, "value");
 }
Ejemplo n.º 56
0
 private void ExecuteStrokeDashArray(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.StrokeDashArray = GetDoubleArray(element);
 }
Ejemplo n.º 57
0
 private void ExecuteDensity(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.Density = GetValue <Density>(element, "value");
 }
Ejemplo n.º 58
0
 private void ExecuteStrokeColor(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.StrokeColor = GetValue <MagickColor>(element, "value");
 }
Ejemplo n.º 59
0
 private void ExecuteVerbose(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.Verbose = GetValue <Boolean>(element, "value");
 }
Ejemplo n.º 60
0
 private void ExecuteStrokePattern(XmlElement element, MagickReadSettings readSettings)
 {
     readSettings.StrokePattern = CreateMagickImage(element);
 }