public void Test_Colors() { using (MagickImage image = new MagickImage(Files.Coders.PlayerPSD)) { using (PixelCollection pixels = image.GetReadOnlyPixels()) { Pixel pixel = pixels.GetPixel(0, 0); ColorAssert.AreEqual(MagickColor.Transparent, pixel.ToColor()); pixel = pixels.GetPixel(8, 6); ColorAssert.AreEqual(Color.FromArgb(15, 43, 255), pixel.ToColor()); } } }
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()); } } } } } }
public void Test_Coalesce() { using (IMagickImageCollection collection = new MagickImageCollection()) { ExceptionAssert.Throws <InvalidOperationException>(delegate() { collection.Coalesce(); }); collection.Read(Files.RoseSparkleGIF); using (PixelCollection pixels = collection[1].GetPixels()) { MagickColor color = pixels.GetPixel(53, 3).ToColor(); Assert.AreEqual(0, color.A); } collection.Coalesce(); using (PixelCollection pixels = collection[1].GetPixels()) { MagickColor color = pixels.GetPixel(53, 3).ToColor(); Assert.AreEqual(Quantum.Max, color.A); } } }
public void Test_FillColor() { using (MagickImage image = new MagickImage(MagickColors.Transparent, 100, 100)) { ColorAssert.AreEqual(MagickColors.Black, image.Settings.FillColor); Pixel pixelA; image.Settings.FillColor = MagickColors.Red; image.Read("caption:Magick.NET"); Assert.AreEqual(100, image.Width); Assert.AreEqual(100, image.Height); using (PixelCollection pixels = image.GetPixels()) { pixelA = pixels.GetPixel(69, 6); } Pixel pixelB; image.Settings.FillColor = MagickColors.Yellow; image.Read("caption:Magick.NET"); using (PixelCollection pixels = image.GetPixels()) { pixelB = pixels.GetPixel(69, 6); } ColorAssert.AreNotEqual(pixelA.ToColor(), pixelB.ToColor()); } }
public static void AreEqual(MagickColor expected, IMagickImage image, int x, int y) { using (PixelCollection pixels = image.GetPixels()) { AreEqual(expected, pixels.GetPixel(x, y)); } }
public static void AreNotEqual(MagickColor notExpected, IMagickImage image, int x, int y) { using (PixelCollection collection = image.GetPixels()) { AreNotEqual(notExpected, collection.GetPixel(x, y)); } }
private MagickColor GetBorderColor(MagickImage image) { using (PixelCollection pixels = image.GetReadOnlyPixels()) { return(pixels.GetPixel((int)BorderColorLocation.X, (int)BorderColorLocation.Y).ToColor()); } }
public PixelCollection Draw(PixelCollection pixels, IList <Point> drawingPoints, DrawingItemProperties properties) { var fillPixel = pixels.GetPixel(drawingPoints.First()); FloodFill(pixels, fillPixel, fillPixel.Color, properties.Color); return(pixels); }
//=========================================================================================== private static void Test_Pixel(MagickImage image, int x, int y, MagickColor color) { using (PixelCollection collection = image.GetReadOnlyPixels()) { ColorAssert.AreEqual(color, collection.GetPixel(x, y)); } }
public void Test_Image_Read() { MagickReadSettings settings = CreateSettings(); using (MagickImage image = new MagickImage()) { byte[] data = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xf0, 0x3f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xf0, 0x3f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; image.Read(data, settings); Assert.AreEqual(2, image.Width); Assert.AreEqual(1, image.Height); using (PixelCollection pixels = image.GetReadOnlyPixels()) { Pixel pixel = pixels.GetPixel(0, 0); Assert.AreEqual(4, pixel.Channels); Assert.AreEqual(0, pixel.GetChannel(0)); Assert.AreEqual(0, pixel.GetChannel(1)); Assert.AreEqual(0, pixel.GetChannel(2)); Assert.AreEqual(Quantum.Max, pixel.GetChannel(3)); pixel = pixels.GetPixel(1, 0); Assert.AreEqual(4, pixel.Channels); Assert.AreEqual(0, pixel.GetChannel(0)); Assert.AreEqual(Quantum.Max, pixel.GetChannel(1)); Assert.AreEqual(0, pixel.GetChannel(2)); Assert.AreEqual(0, pixel.GetChannel(3)); ExceptionAssert.Throws <ArgumentException>(delegate() { pixels.GetPixel(0, 1); }); } } }
public void Test_Execute_Variables() { MagickScript script = new MagickScript(Files.Scripts.Variables); string[] names = script.Variables.Names.ToArray(); Assert.AreEqual(3, names.Length); Assert.AreEqual("width", names[0]); Assert.AreEqual("height", names[1]); Assert.AreEqual("color", names[2]); using (MagickImage image = new MagickImage(Files.MagickNETIconPNG)) { ExceptionAssert.Throws <ArgumentNullException>(delegate() { script.Execute(image); }); script.Variables["width"] = "test"; ExceptionAssert.Throws <FormatException>(delegate() { script.Execute(image); }); script.Variables.Set("width", 100); ExceptionAssert.Throws <ArgumentNullException>(delegate() { script.Execute(image); }); script.Variables["height"] = "100"; Assert.AreEqual("100", script.Variables.Get("height")); script.Variables["color"] = Color.Yellow; script.Execute(image); Assert.AreEqual(100, image.Width); Assert.AreEqual(100, image.Height); using (PixelCollection pixels = image.GetReadOnlyPixels()) { ColorAssert.AreEqual(Color.Yellow, pixels.GetPixel(0, 0)); } } }
public void Test_Scale() { using (MagickImage image = new MagickImage(Files.Circle)) { MagickColor color = Color.FromArgb(159, 255, 255, 255); using (PixelCollection pixels = image.GetReadOnlyPixels()) { ColorAssert.AreEqual(color, pixels.GetPixel(image.Width / 2, image.Height / 2).ToColor()); } image.Scale((Percentage)400); using (PixelCollection pixels = image.GetReadOnlyPixels()) { ColorAssert.AreEqual(color, pixels.GetPixel(image.Width / 2, image.Height / 2).ToColor()); } } }
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.Bgra; using (IMagickImage image = new MagickImage(bytes, settings)) { using (PixelCollection pixels = image.GetPixels()) { Pixel pixel = pixels.GetPixel(0, 0); Assert.AreEqual(4, pixel.Channels); Assert.AreEqual(3, pixel.GetChannel(0)); Assert.AreEqual(2, pixel.GetChannel(1)); Assert.AreEqual(1, pixel.GetChannel(2)); Assert.AreEqual(4, pixel.GetChannel(3)); } } settings.Format = MagickFormat.Bgro; using (IMagickImage image = new MagickImage(bytes, settings)) { using (PixelCollection pixels = image.GetPixels()) { Pixel pixel = pixels.GetPixel(0, 0); Assert.AreEqual(4, pixel.Channels); Assert.AreEqual(3, pixel.GetChannel(0)); Assert.AreEqual(2, pixel.GetChannel(1)); Assert.AreEqual(1, pixel.GetChannel(2)); Assert.AreEqual(Quantum.Max - 4, pixel.GetChannel(3)); } } }
public void Test_Extent() { using (MagickImage image = new MagickImage()) { image.Read(Files.RedPNG); image.Resize(new MagickGeometry(100, 100)); Assert.AreEqual(100, image.Width); Assert.AreEqual(33, image.Height); image.BackgroundColor = MagickColor.Transparent; image.Extent(100, 100, Gravity.Center); Assert.AreEqual(100, image.Width); Assert.AreEqual(100, image.Height); using (PixelCollection pixels = image.GetReadOnlyPixels()) { Assert.IsTrue(pixels.GetPixel(0, 0).ToColor() == MagickColor.Transparent); } } }
private static void TestPixels(MagickImage image, MagickColor color) { using (MemoryStream memStream = new MemoryStream()) { image.Format = MagickFormat.Png; image.Write(memStream); memStream.Position = 0; using (MagickImage output = new MagickImage(memStream)) { using (PixelCollection pixels = image.GetReadOnlyPixels()) { for (int i = 0; i < 10; i++) { ColorAssert.AreEqual(color, pixels.GetPixel(i, 0).ToColor()); } } } } }
private bool IsBorderColor(PixelCollection pixels, int x, int y) { MagickColor color = pixels.GetPixel(x, y).ToColor(); return(color.FuzzyEquals(_BorderColor, ColorFuzz)); }