本文整理汇总了C#中ImageMagick.MagickImageCollection.Write方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImageCollection.Write方法的具体用法?C# MagickImageCollection.Write怎么用?C# MagickImageCollection.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageMagick.MagickImageCollection
的用法示例。
在下文中一共展示了MagickImageCollection.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAnimatedGif
public static void CreateAnimatedGif()
{
using (MagickImageCollection collection = new MagickImageCollection())
{
// Add first image and set the animation delay to 100ms
collection.Add(SampleFiles.SnakewarePng);
collection[0].AnimationDelay = 100;
// Add second image, set the animation delay to 100ms and flip the image
collection.Add(SampleFiles.SnakewarePng);
collection[1].AnimationDelay = 100;
collection[1].Flip();
// Optionally reduce colors
QuantizeSettings settings = new QuantizeSettings();
settings.Colors = 256;
collection.Quantize(settings);
// Optionally optimize the images (images should have the same size).
collection.Optimize();
// Save gif
collection.Write(SampleFiles.OutputDirectory + "Snakeware.Animated.gif");
}
}
示例2: WriteAndCheckProfile
private static void WriteAndCheckProfile(MagickImageCollection images, PsdWriteDefines defines, int expectedLength)
{
using (MemoryStream memStream = new MemoryStream())
{
images.Write(memStream, defines);
memStream.Position = 0;
images.Read(memStream);
CheckProfile(images[1], expectedLength);
}
}
示例3: CreateIconFromPngFilesFromSvg
public void CreateIconFromPngFilesFromSvg(IconInfo iconInfo)
{
if (iconInfo.NeedUpdate())
{
using (var imageCollection = new MagickImageCollection())
{
foreach (var iconInfoPngFile in iconInfo.PngFiles)
{
var image = new MagickImage(iconInfoPngFile.FullName);
imageCollection.Add(image);
}
imageCollection.Write(iconInfo.IconFile.FullName);
}
}
}
示例4: ConvertPdfToOneTif
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);
}
}
示例5: ResizeAnimatedGif
public static void ResizeAnimatedGif()
{
// Read from file
using (MagickImageCollection collection = new MagickImageCollection(SampleFiles.SnakewareGif))
{
// This will remove the optimization and change the image to how it looks at that point
// during the animation. More info here: http://www.imagemagick.org/Usage/anim_basics/#coalesce
collection.Coalesce();
// Resize each image in the collection to a width of 200. When zero is specified for the height
// the height will be calculated with the aspect ratio.
foreach (MagickImage image in collection)
{
image.Resize(200, 0);
}
// Save the result
collection.Write(SampleFiles.OutputDirectory + "Snakeware.resized.gif");
}
}
示例6: Run
public static void Run(string oldFilePath, string newFilePath, int width, int height, int? quality)
{
if (!oldFilePath.EndsWith("gif", StringComparison.OrdinalIgnoreCase))
{
using (var image = new MagickImage(oldFilePath))
{
Process(width, height, image, quality);
image.Write(newFilePath);
}
}
else
{
using (var collection = new MagickImageCollection(oldFilePath))
{
foreach (var image in collection)
{
Process(width, height, image, quality);
}
collection.Write(newFilePath);
}
}
}
示例7: Test_Write
public void Test_Write()
{
long fileSize;
using (MagickImage image = new MagickImage(Files.RoseSparkleGIF))
{
fileSize = image.FileSize;
}
Assert.AreEqual(fileSize, 9891);
using (MagickImageCollection collection = new MagickImageCollection(Files.RoseSparkleGIF))
{
using (MemoryStream memStream = new MemoryStream())
{
collection.Write(memStream);
Assert.AreEqual(fileSize, memStream.Length);
}
}
FileInfo tempFile = new FileInfo(Path.GetTempFileName() + ".gif");
try
{
using (MagickImageCollection collection = new MagickImageCollection(Files.RoseSparkleGIF))
{
collection.Write(tempFile);
Assert.AreEqual(fileSize, tempFile.Length);
}
}
finally
{
if (tempFile.Exists)
tempFile.Delete();
}
}
示例8: Test_Write
public void Test_Write()
{
long fileSize;
using (MagickImage image = new MagickImage(Files.Builtin.Rose))
{
fileSize = image.FileSize;
}
using (MagickImageCollection collection = new MagickImageCollection(Files.Builtin.Rose))
{
using (MemoryStream memStream = new MemoryStream())
{
collection.Write(memStream);
Assert.AreEqual(fileSize, memStream.Length);
}
}
}
示例9: ConfigGA
public override void ConfigGA(GeneticAlgorithm ga)
{
base.ConfigGA(ga);
ga.MutationProbability = 0.4f;
ga.TerminationReached += (sender, args) =>
{
using (var collection = new MagickImageCollection())
{
var files = Directory.GetFiles(m_destFolder, "*.png");
foreach (var image in files)
{
collection.Add(image);
collection[0].AnimationDelay = 100;
}
var settings = new QuantizeSettings();
settings.Colors = 256;
collection.Quantize(settings);
collection.Optimize();
collection.Write(Path.Combine(m_destFolder, "result.gif"));
}
};
}
示例10: createGif
/*
* Create gif for this test packa4
* If there are more pics than the max (250), set the skip value slightly higher to skip extra images
*/
public void createGif()
{
if (this.pngToGifFiles == null || this.pd == null) return;
Console.WriteLine("[i] Creating gif for task " + this.taskIDNum);
using (MagickImageCollection pngs = new MagickImageCollection())
{
int skip = 1, maxPics = 250, extraPics;
if ((extraPics = pngToGifFiles.Length - maxPics) > 1) skip = (int)Math.Ceiling((double)pngToGifFiles.Length / maxPics);
for (int i = 0, count = 0; i < pngToGifFiles.Length; i += skip)
{
pngs.Add(pngToGifFiles[i]);
pngs[count++].AnimationDelay = 10;
}
pngs[0].AnimationIterations = 1;
QuantizeSettings sett = new QuantizeSettings();
sett.Colors = 256;
pngs.Quantize(sett);
pngs.Optimize();
pngs.Write(this.pd + "install_" + this.taskIDNum + ".gif");
foreach (string fileToDelete in this.pngToGifFiles) File.Delete(fileToDelete); // Delete the extra .png files
Console.WriteLine("[\u221A] Gif created for task " + this.taskIDNum + ".");
} // end pngs using
}
示例11: GetDeviceStatePic
private static string GetDeviceStatePic(GKDevice device, GKState state)
{
var deviceConfig =
GKManager.DeviceLibraryConfiguration.GKDevices.FirstOrDefault(d => d.DriverUID == device.DriverUID);
if (deviceConfig == null)
{
return null;
}
var stateWithPic =
deviceConfig.States.FirstOrDefault(s => s.StateClass == state.StateClass) ??
deviceConfig.States.FirstOrDefault(s => s.StateClass == XStateClass.No);
if (stateWithPic == null)
{
return null;
}
// Перебираем кадры в состоянии и генерируем gif картинку
byte[] bytes;
using (var collection = new MagickImageCollection())
{
foreach (var frame in stateWithPic.Frames)
{
var frame1 = frame;
frame1.Image = frame1.Image.Replace("#000000", "#FF0F0F0F");
Canvas surface;
var imageBytes = Encoding.Unicode.GetBytes(frame1.Image ?? "");
using (var stream = new MemoryStream(imageBytes))
{
surface = (Canvas)XamlServices.Load(stream);
}
var pngBitmap = surface != null ? InternalConverter.XamlCanvasToPngBitmap(surface) : null;
if (pngBitmap == null)
{
continue;
}
var img = new MagickImage(pngBitmap)
{
AnimationDelay = frame.Duration / 10,
HasAlpha = true
};
collection.Add(img);
}
if (collection.Count == 0)
{
return string.Empty;
}
//Optionally reduce colors
QuantizeSettings settings = new QuantizeSettings { Colors = 256 };
collection.Quantize(settings);
// Optionally optimize the images (images should have the same size).
collection.Optimize();
using (var str = new MemoryStream())
{
collection.Write(str, MagickFormat.Gif);
bytes = str.ToArray();
}
}
return Convert.ToBase64String(bytes);
}
示例12: CreatePDFFromTwoImages
public static void CreatePDFFromTwoImages()
{
using (MagickImageCollection collection = new MagickImageCollection())
{
// Add first page
collection.Add(new MagickImage(SampleFiles.SnakewareJpg));
// Add second page
collection.Add(new MagickImage(SampleFiles.SnakewareJpg));
// Create pdf file with two pages
collection.Write(SampleFiles.OutputDirectory + "Snakeware.pdf");
}
}
示例13: OnSelectedSourceFileChanged
private async void OnSelectedSourceFileChanged()
{
if (SelectedSourceFile == null ||
!SelectedSourceFile.Exists)
return;
var settings = new MagickReadSettings
{
Density = new Density(150, 150),
FrameIndex = 0,
FrameCount = 1
};
var filename = Path.GetTempFileName();
await Task.Run(() =>
{
try
{
using (var images = new MagickImageCollection())
{
images.Read(SelectedSourceFile, settings);
var image = images.First();
image.Format = MagickFormat.Jpeg;
images.Write(filename);
}
}
catch (Exception ex)
{
Log.Warn("Unable to preview document.", ex);
PreviewImage = null;
PreviewImageFilename = null;
SelectedFilePageCount = 0;
}
try
{
using (var pdfReader = new PdfReader(SelectedSourceFile.FullName))
SelectedFilePageCount = pdfReader.NumberOfPages;
}
catch (Exception ex)
{
Log.Warn("Unable to count pages.", ex);
SelectedFilePageCount = 0;
}
});
try
{
var uri = new Uri(filename);
var bitmap = new BitmapImage(uri);
PreviewImage = bitmap;
PreviewImageFilename = filename;
}
catch (Exception)
{
Log.Warn("Unable to preview selected document.");
try
{
var uri = new Uri("pack://application:,,,/PaperPusher;component/Art/unknown_icon_512.png");
var bitmap = new BitmapImage(uri);
PreviewImage = bitmap;
}
catch (Exception ex)
{
Log.Error("Error showing unknown file icon.", ex);
}
}
}
示例14: saveAsGifToolStripMenuItem_Click
private void saveAsGifToolStripMenuItem_Click(object sender, EventArgs e)
{
String savedgif = null;
saveFileDialog1.FileName = "animation.gif";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
savedgif = saveFileDialog1.FileName;
String[] images = new String[arrayOfImages.Length];
String log = "";
int i = 0;
String tmpDir = @"tmp\";
if(Directory.Exists(@"tmp\")){
} else {
Directory.CreateDirectory(@"tmp\");
}
using (ImageMagick.MagickImageCollection collection = new MagickImageCollection())
{
foreach (PictureBox image in arrayOfImages)
{
Bitmap temp = (Bitmap)image.Image;
String name = tmpDir +"img" + i + ".png";
temp.Save(name);
images[i] = name;
i += 1;
}
foreach (String s in images)
{
collection.Add(s);
collection.Write(savedgif);
log += s;
}
// MessageBox.Show(log);
ImageWindow pos = new ImageWindow(wind, savedgif);
}
}
}
示例15: saveToolStripMenuItem_Click
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog svd = new SaveFileDialog();
svd.Filter = "GIF|*.gif";
if (svd.ShowDialog() == DialogResult.OK)
{
using (MagickImageCollection collection = new MagickImageCollection())
{
foreach (PictureBox pim in images)
{
collection.Add(new MagickImage((Bitmap)pim.Image.Clone()));
collection[collection.Count - 1].AnimationDelay = 100;
}
// Optionally reduce colors
QuantizeSettings settings = new QuantizeSettings();
settings.Colors = 256;
collection.Quantize(settings);
// Optionally optimize the images (images should have the same size).
collection.Optimize();
// Save gif
collection.Write(svd.FileName);
}
}
else
{
svd.Dispose();
}
}