本文整理汇总了C#中ImageMagick.MagickImage.GetReadOnlyPixels方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImage.GetReadOnlyPixels方法的具体用法?C# MagickImage.GetReadOnlyPixels怎么用?C# MagickImage.GetReadOnlyPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageMagick.MagickImage
的用法示例。
在下文中一共展示了MagickImage.GetReadOnlyPixels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Pixel_NotEqual
private static void Test_Pixel_NotEqual(MagickImage image, int x, int y, MagickColor color)
{
using (PixelCollection collection = image.GetReadOnlyPixels())
{
ColorAssert.AreNotEqual(color, collection.GetPixel(x, y));
}
}
示例2: Test_IEnumerable
public void Test_IEnumerable()
{
using (MagickImage image = new MagickImage(Color.Red, 5, 10))
{
PixelCollection pixels = image.GetReadOnlyPixels();
Assert.AreEqual(50, pixels.Count());
}
}
示例3: Test_Dimensions
public void Test_Dimensions()
{
using (MagickImage image = new MagickImage(Color.Red, 5, 10))
{
using (PixelCollection pixels = image.GetReadOnlyPixels())
{
Assert.AreEqual(5, pixels.Width);
Assert.AreEqual(10, pixels.Height);
Assert.AreEqual(5 * 10 * pixels.Channels, pixels.GetValues().Length);
}
}
}
示例4: Test_GetValues
public void Test_GetValues()
{
using (MagickImage image = new MagickImage(Color.PowderBlue, 1, 1))
{
using (PixelCollection pixels = image.GetReadOnlyPixels())
{
var values = pixels.GetValues();
Assert.AreEqual(3, values.Length);
MagickColor color = new MagickColor(values[0], values[1], values[2]);
ColorAssert.AreEqual(Color.PowderBlue, color);
}
}
}
示例5: Test_Colors
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());
}
}
}
示例6: TestPixels
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());
}
}
}
}
示例7: Test_Read_Bytes
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));
}
}
}
示例8: Test_IndexOutOfRange
public void Test_IndexOutOfRange()
{
using (MagickImage image = new MagickImage(Color.Red, 5, 10))
{
using (PixelCollection pixels = image.GetReadOnlyPixels())
{
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
pixels.GetValue(5, 0);
});
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
pixels.GetValue(-1, 0);
});
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
pixels.GetValue(0, -1);
});
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
pixels.GetValue(0, 10);
});
}
}
}
示例9: Test_Scale
public void Test_Scale()
{
using (MagickImage image = new MagickImage(Files.CirclePNG))
{
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());
}
}
}
示例10: Test_Execute_Variables
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));
}
}
}
示例11: Test_Separate_Composite
private static void Test_Separate_Composite(MagickImage image, ColorSpace colorSpace, int value)
{
Assert.AreEqual(colorSpace, image.ColorSpace);
using (PixelCollection pixels = image.GetReadOnlyPixels())
{
Pixel pixel = pixels.GetPixel(340, 260);
ColorAssert.AreEqual(Color.FromArgb(value, value, value), pixel.ToColor());
}
}
示例12: Test_FillColor
public void Test_FillColor()
{
using (MagickImage image = new MagickImage(MagickColor.Transparent, 100, 100))
{
image.FillColor = null;
Pixel pixelA;
image.FillColor = Color.Red;
image.Read("caption:Magick.NET");
using (PixelCollection pixels = image.GetReadOnlyPixels())
{
pixelA = pixels.GetPixel(69, 6);
}
Pixel pixelB;
image.FillColor = Color.Yellow;
image.Read("caption:Magick.NET");
using (PixelCollection pixels = image.GetReadOnlyPixels())
{
pixelB = pixels.GetPixel(69, 6);
}
ColorAssert.AreNotEqual(pixelA, pixelB);
}
}
示例13: Test_ColorAlpha
public void Test_ColorAlpha()
{
using (MagickImage image = new MagickImage(Files.MagickNETIconPNG))
{
MagickColor purple = new MagickColor("purple");
image.ColorAlpha(purple);
using (PixelCollection pixels = image.GetReadOnlyPixels())
{
ColorAssert.AreNotEqual(purple, pixels.GetPixel(45, 75).ToColor());
ColorAssert.AreEqual(purple, pixels.GetPixel(100, 60).ToColor());
}
}
}
示例14: Test_SparseColors
public void Test_SparseColors()
{
MagickReadSettings settings = new MagickReadSettings();
settings.Width = 600;
settings.Height = 60;
using (MagickImage image = new MagickImage("xc:", settings))
{
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
image.SparseColor(Channels.Red, SparseColorMethod.Barycentric, null);
});
List<SparseColorArg> args = new List<SparseColorArg>();
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
image.SparseColor(Channels.Blue, SparseColorMethod.Barycentric, args);
});
using (PixelCollection pixels = image.GetReadOnlyPixels())
{
ColorAssert.AreEqual(pixels.GetPixel(0, 0), pixels.GetPixel(599, 59));
}
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
args.Add(new SparseColorArg(0, 0, null));
});
args.Add(new SparseColorArg(0, 0, new MagickColor("skyblue")));
args.Add(new SparseColorArg(-600, 60, new MagickColor("skyblue")));
args.Add(new SparseColorArg(600, 60, new MagickColor("black")));
image.SparseColor(SparseColorMethod.Barycentric, args);
using (PixelCollection pixels = image.GetReadOnlyPixels())
{
ColorAssert.AreNotEqual(pixels.GetPixel(0, 0), pixels.GetPixel(599, 59));
}
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
image.SparseColor(Channels.Black, SparseColorMethod.Barycentric, args);
});
}
}
示例15: Test_Shadow
public void Test_Shadow()
{
using (MagickImage image = new MagickImage())
{
image.BackgroundColor = MagickColor.Transparent;
image.FontPointsize = 60;
image.Read("label:Magick.NET");
int width = image.Width;
int height = image.Height;
image.Shadow(2, 2, 1, new ImageMagick.Percentage(50), Color.Red);
Assert.AreEqual(width + 4, image.Width);
Assert.AreEqual(height + 4, image.Height);
using (PixelCollection pixels = image.GetReadOnlyPixels())
{
Pixel pixel = pixels.GetPixel(90, 9);
Assert.AreEqual(0, pixel.ToColor().A);
}
}
}