本文整理汇总了C#中MagickImage.Write方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImage.Write方法的具体用法?C# MagickImage.Write怎么用?C# MagickImage.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MagickImage
的用法示例。
在下文中一共展示了MagickImage.Write方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeCards
public void MakeCards()
{
var deck = JsonConvert.DeserializeObject<Deck>(File.ReadAllText(@"C:\temp\testdeck.cm"));
var cards = new List<MagickImage>();
foreach (var card in deck.Cards) {
var image = new MagickImage(new MagickColor("WhiteSmoke"), deck.Width, deck.Height);
image.Density = new MagickGeometry(300, 300);
image.Format = MagickFormat.Bmp;
foreach (var element in deck.Elements) {
var data = card.ElementData[element.Key];
if (File.Exists(data)) {
using (var overlayImage = new MagickImage(data)) {
image.Composite(overlayImage, (int)element.Value.X, (int)element.Value.Y, CompositeOperator.Over);
}
} else {
using (var textImage = new MagickImage(MagickColor.Transparent, deck.Width, deck.Height)) {
textImage.Density = new MagickGeometry(300, 300);
textImage.Font = "Arial";
textImage.FontPointsize = 12;
textImage.FillColor = new MagickColor("Black");
var drawableText = new DrawableText(element.Value.X, element.Value.Y, data);
textImage.Draw(drawableText);
image.Composite(textImage, CompositeOperator.Over);
}
}
}
image.Write(string.Format(@"c:\temp\CardMaker\{0}.png", card.Name));
cards.Add(image);
}
using (var doc = new Document()) {
PdfWriter.GetInstance(doc, new FileStream(@"C:\temp\CardMaker\cards.pdf", FileMode.Create));
doc.Open();
var columns = (int)Math.Floor(doc.PageSize.Width / (deck.Width + 10));
var table = new PdfPTable(columns) { WidthPercentage = 100, DefaultCell = { Border = 0, Padding = 5 } };
foreach (var card in cards) {
var instance = Image.GetInstance(card.ToByteArray());
instance.SetDpi(300, 300);
var cell = new PdfPCell(instance) {
HorizontalAlignment = Element.ALIGN_CENTER,
Border = 0,
Padding = 5,
};
table.AddCell(cell);
}
table.CompleteRow();
doc.Add(table);
}
}
示例2: CreateMagickImageInfo
//===========================================================================================
private MagickImageInfo CreateMagickImageInfo(Color color, int width, int height)
{
using (MemoryStream memStream = new MemoryStream())
{
using (MagickImage image = new MagickImage(color, width, height))
{
image.Format = MagickFormat.Png;
image.Write(memStream);
memStream.Position = 0;
return new MagickImageInfo(memStream);
}
}
}
示例3: DoLosslessCompress
private void DoLosslessCompress(FileInfo file)
{
using (MagickImage image = new MagickImage(file))
{
CheckFormat(image);
image.Strip();
image.SetDefine(MagickFormat.Png, "exclude-chunks", "all");
image.SetDefine(MagickFormat.Png, "include-chunks", "tRNS,gAMA");
CheckTransparency(image);
Collection<FileInfo> tempFiles = new Collection<FileInfo>();
try
{
FileInfo bestFile = null;
foreach (int quality in GetQualityList())
{
FileInfo tempFile = new FileInfo(Path.GetTempFileName());
tempFiles.Add(tempFile);
image.Quality = quality;
image.Write(tempFile);
tempFile.Refresh();
if (bestFile == null || bestFile.Length > tempFile.Length)
bestFile = tempFile;
else
tempFile.Delete();
}
if (bestFile.Length < file.Length)
bestFile.CopyTo(file.FullName, true);
}
finally
{
foreach (FileInfo tempFile in tempFiles)
{
if (tempFile.Exists)
tempFile.Delete();
}
}
}
}
示例4: WriteToCache
private void WriteToCache(MagickImage image, string cacheFileName)
{
string tempFile = GetTempFileName();
try
{
image.Write(tempFile);
if (CanOptimize(FormatInfo))
OptimizeFile(tempFile);
MoveToCache(tempFile, cacheFileName);
}
finally
{
if (File.Exists(tempFile))
File.Delete(tempFile);
}
}
示例5: DoLosslessCompress
private static void DoLosslessCompress(FileInfo file, MagickImage image)
{
CheckFormat(image);
image.Strip();
FileInfo tempFile = new FileInfo(Path.GetTempFileName());
try
{
image.Settings.Interlace = Interlace.NoInterlace;
image.Write(tempFile);
if (tempFile.Length < file.Length)
tempFile.CopyTo(file.FullName, true);
}
finally
{
FileHelper.Delete(tempFile);
}
}
示例6: Test_Constructor
public void Test_Constructor()
{
using (MemoryStream memStream = new MemoryStream())
{
using (MagickImage image = new MagickImage(Files.ImageMagickJPG))
{
ExifProfile profile = image.GetExifProfile();
Assert.IsNull(profile);
profile = new ExifProfile();
profile.SetValue(ExifTag.Copyright, "Dirk Lemstra");
image.AddProfile(profile);
profile = image.GetExifProfile();
Assert.IsNotNull(profile);
image.Write(memStream);
}
memStream.Position = 0;
using (MagickImage image = new MagickImage(memStream))
{
ExifProfile profile = image.GetExifProfile();
Assert.IsNotNull(profile);
Assert.AreEqual(1, profile.Values.Count());
ExifValue value = profile.Values.FirstOrDefault(val => val.Tag == ExifTag.Copyright);
TestValue(value, "Dirk Lemstra");
}
}
}
示例7: Test_SetValue
public void Test_SetValue()
{
double[] latitude = new double[] { 12.3, 4.56, 789.0 };
using (MemoryStream memStream = new MemoryStream())
{
using (MagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
{
ExifProfile profile = image.GetExifProfile();
profile.SetValue(ExifTag.Software, "GraphicsMagick.NET");
ExifValue value = profile.GetValue(ExifTag.Software);
TestValue(value, "GraphicsMagick.NET");
ExceptionAssert.Throws<ArgumentException>(delegate()
{
value.Value = 15;
});
profile.SetValue(ExifTag.ShutterSpeedValue, 75.55);
value = profile.GetValue(ExifTag.ShutterSpeedValue);
TestValue(value, 75.55);
ExceptionAssert.Throws<ArgumentException>(delegate()
{
value.Value = 75;
});
profile.SetValue(ExifTag.XResolution, 150.0);
value = profile.GetValue(ExifTag.XResolution);
TestValue(value, 150.0);
ExceptionAssert.Throws<ArgumentException>(delegate()
{
value.Value = "GraphicsMagick.NET";
});
image.Density = new MagickGeometry(72);
value = profile.GetValue(ExifTag.XResolution);
TestValue(value, 150.0);
value = profile.GetValue(ExifTag.ReferenceBlackWhite);
Assert.IsNotNull(value);
profile.SetValue(ExifTag.ReferenceBlackWhite, null);
value = profile.GetValue(ExifTag.ReferenceBlackWhite);
TestValue(value, (string)null);
profile.SetValue(ExifTag.GPSLatitude, latitude);
value = profile.GetValue(ExifTag.GPSLatitude);
TestValue(value, latitude);
image.AddProfile(profile);
image.Write(memStream);
}
memStream.Position = 0;
using (MagickImage image = new MagickImage(memStream))
{
ExifProfile profile = image.GetExifProfile();
Assert.IsNotNull(profile);
Assert.AreEqual(43, profile.Values.Count());
ExifValue value = profile.GetValue(ExifTag.Software);
TestValue(value, "GraphicsMagick.NET");
value = value = profile.GetValue(ExifTag.ShutterSpeedValue);
TestValue(value, 75.55);
value = value = profile.GetValue(ExifTag.XResolution);
TestValue(value, 150.0);
value = profile.GetValue(ExifTag.ReferenceBlackWhite);
Assert.IsNull(value);
value = profile.GetValue(ExifTag.GPSLatitude);
TestValue(value, latitude);
profile.Parts = ExifParts.ExifTags;
image.AddProfile(profile);
memStream.Position = 0;
image.Write(memStream);
}
memStream.Position = 0;
using (MagickImage image = new MagickImage(memStream))
{
ExifProfile profile = image.GetExifProfile();
Assert.IsNotNull(profile);
//.........这里部分代码省略.........
示例8: WriteToCache
//===========================================================================================
private static void WriteToCache(MagickImage image, string cacheFileName)
{
string tempFile = Path.GetTempFileName();
try
{
image.Write(tempFile);
_Lock.EnterWriteLock();
if (File.Exists(cacheFileName))
File.Delete(cacheFileName);
File.Move(tempFile, cacheFileName);
}
finally
{
_Lock.ExitWriteLock();
if (File.Exists(tempFile))
File.Delete(tempFile);
}
}
示例9: Test_SetValue
public void Test_SetValue()
{
using (MemoryStream memStream = new MemoryStream())
{
string credit = null;
for (int i = 0; i < 255; i++)
credit += i.ToString() + ".";
using (MagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
{
IptcProfile profile = image.GetIptcProfile();
TestProfileValues(profile);
IptcValue value = profile.GetValue(IptcTag.Title);
TestValue(value, "Communications");
profile.SetValue(IptcTag.Title, "Magick.NET Title");
TestValue(value, "Magick.NET Title");
value = profile.GetValue(IptcTag.Title);
TestValue(value, "Magick.NET Title");
value = profile.Values.FirstOrDefault(val => val.Tag == IptcTag.ReferenceNumber);
Assert.IsNull(value);
profile.SetValue(IptcTag.ReferenceNumber, "Magick.NET ReferenceNümber");
value = profile.GetValue(IptcTag.ReferenceNumber);
TestValue(value, "Magick.NET ReferenceNümber");
profile.SetValue(IptcTag.Credit, credit);
value = profile.GetValue(IptcTag.Credit);
TestValue(value, credit);
// Remove the 8bim profile so we can overwrite the iptc profile.
image.RemoveProfile("8bim");
image.AddProfile(profile);
image.Write(memStream);
memStream.Position = 0;
}
using (MagickImage image = new MagickImage(memStream))
{
IptcProfile profile = image.GetIptcProfile();
TestProfileValues(profile, 20);
IptcValue value = profile.GetValue(IptcTag.Title);
TestValue(value, "Magick.NET Title");
value = profile.GetValue(IptcTag.ReferenceNumber);
TestValue(value, "Magick.NET ReferenceNümber");
value = profile.GetValue(IptcTag.Credit);
TestValue(value, credit);
ExceptionAssert.Throws<ArgumentNullException>(delegate()
{
profile.SetValue(IptcTag.Caption, null, "Test");
});
profile.SetValue(IptcTag.Caption, "Test");
value = profile.Values.ElementAt(1);
Assert.AreEqual("Test", value.Value);
profile.SetValue(IptcTag.Caption, Encoding.UTF32, "Test");
Assert.AreEqual(Encoding.UTF32, value.Encoding);
Assert.AreEqual("Test", value.Value);
Assert.IsTrue(profile.RemoveValue(IptcTag.Caption));
Assert.IsFalse(profile.RemoveValue(IptcTag.Caption));
Assert.IsNull(profile.GetValue(IptcTag.Caption));
}
}
}
示例10: Test_Write
public void Test_Write()
{
using (MagickImage image = new MagickImage(Files.SnakewarePNG))
{
using (MemoryStream memStream = new MemoryStream())
{
image.Write(memStream);
Assert.AreEqual(image.FileSize, memStream.Length);
}
}
}
示例11: Test_Threshold
public void Test_Threshold()
{
using (MagickImage image = new MagickImage(Files.ImageMagickJPG))
{
using (MemoryStream memStream = new MemoryStream())
{
image.Threshold(80);
image.CompressionMethod = CompressionMethod.Group4;
image.Format = MagickFormat.Pdf;
image.Write(memStream);
}
}
}
示例12: Test_Profile
public void Test_Profile()
{
using (MagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
{
ImageProfile profile = image.GetExifProfile();
Assert.IsNotNull(profile);
image.RemoveProfile(profile.Name);
profile = image.GetExifProfile();
Assert.IsNull(profile);
using (MemoryStream memStream = new MemoryStream())
{
image.Write(memStream);
memStream.Position = 0;
using (MagickImage newImage = new MagickImage(memStream))
{
profile = newImage.GetExifProfile();
Assert.IsNull(profile);
}
}
}
}