本文整理汇总了C#中ImageMagick.MagickImage.Read方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImage.Read方法的具体用法?C# MagickImage.Read怎么用?C# MagickImage.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageMagick.MagickImage
的用法示例。
在下文中一共展示了MagickImage.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例3: 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);
});
}
}
}
}
示例4: Test_Image_Read
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();
}
}
示例5: Test_Dimensions
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);
}
}
}
示例6: Test_ColorSpace
public void Test_ColorSpace()
{
using (MagickImage image = new MagickImage())
{
Assert.AreEqual(ColorSpace.Undefined, image.Settings.ColorSpace);
image.Read(Files.ImageMagickJPG);
ColorAssert.AreEqual(MagickColors.White, image, 0, 0);
image.Settings.ColorSpace = ColorSpace.Rec601YCbCr;
image.Read(Files.ImageMagickJPG);
ColorAssert.AreEqual(new MagickColor("#ff8080"), image, 0, 0);
}
}
示例7: Test_BackgroundColor
public void Test_BackgroundColor()
{
using (MagickImage image = new MagickImage())
{
ColorAssert.AreEqual(MagickColors.White, image.Settings.BackgroundColor);
image.Read(Files.Logos.MagickNETSVG);
ColorAssert.AreEqual(MagickColors.White, image, 0, 0);
image.Settings.BackgroundColor = MagickColors.Yellow;
image.Read(Files.Logos.MagickNETSVG);
ColorAssert.AreEqual(MagickColors.Yellow, image, 0, 0);
}
}
示例8: WhenCompareItToTheScreenshot
public void WhenCompareItToTheScreenshot(string screenshotName)
{
using (var leftImage = new MagickImage(new FileInfo(this.screenshotFileName)))
{
using (var rightImage = new MagickImage())
{
using (var extractResource = EmbeddedResources.ExtractResource(Assembly.GetExecutingAssembly().GetName().Name, "Screenshots", screenshotName))
{
rightImage.Read(extractResource);
}
MagickImage diffImage = null;
try
{
this.screenshotDistortion = this.screenShotService.Compare(leftImage, rightImage, out diffImage);
}
finally
{
if (diffImage != null)
{
var diffFileName = Path.GetFileNameWithoutExtension(this.screenshotFileName) + "_diff" + Path.GetExtension(this.screenshotFileName);
// ReSharper disable once AssignNullToNotNullAttribute
diffImage.Write(Path.Combine(Path.GetDirectoryName(this.screenshotFileName), diffFileName));
diffImage.Dispose();
}
}
}
}
}
示例9: Test_AlphaUnblend
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);
}
}
示例10: Test_Disabled
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);
});
}
}
}
}
示例11: Test_IgnoreTags
public void Test_IgnoreTags()
{
using (MagickImage image = new MagickImage())
{
image.SetDefine(MagickFormat.Tiff, "ignore-tags", "32934");
image.Read(Files.Coders.IgnoreTagTIF);
}
}
示例12: Test_IgnoreExifPoperties
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"));
}
}
示例13: ObtainWarningThatOccurredDuringRead
public static void ObtainWarningThatOccurredDuringRead()
{
using (MagickImage image = new MagickImage())
{
// Attach event handler to warning event
image.Warning += MagickImage_Warning;
// Read file that will raise a warning.
image.Read(SampleFiles.FileWithWarningJpg);
}
}
示例14: Test_SkipProfiles
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.Settings.GetDefine("profile:skip"));
}
}
示例15: ReadImage
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);
}
}
}