本文整理汇总了C#中ImageMagick.MagickImageCollection.Read方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImageCollection.Read方法的具体用法?C# MagickImageCollection.Read怎么用?C# MagickImageCollection.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageMagick.MagickImageCollection
的用法示例。
在下文中一共展示了MagickImageCollection.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Collection_Read
public void Test_Collection_Read()
{
using (MagickImageCollection collection = new MagickImageCollection())
{
MagickReadSettings settings = new MagickReadSettings();
settings.Density = new Density(150);
collection.Read(Files.RoseSparkleGIF, settings);
Assert.AreEqual(150, collection[0].Density.X);
settings = new MagickReadSettings();
settings.FrameIndex = 1;
collection.Read(Files.RoseSparkleGIF, settings);
Assert.AreEqual(1, collection.Count);
settings = new MagickReadSettings();
settings.FrameIndex = 1;
settings.FrameCount = 2;
collection.Read(Files.RoseSparkleGIF, settings);
Assert.AreEqual(2, collection.Count);
settings = null;
collection.Read(Files.RoseSparkleGIF, settings);
}
}
示例2: Pdf2imgProc
protected virtual int Pdf2imgProc(MagickImageCollection images, String pdf, int idx, int file_c)
{
images.Read(pdf, settings);
int pages = images.Count;
if (pages > this.MaxPage)
{
this.Result.Code = 413;
L.D("executing pdf2img by file({0}),destination format({1}) fail with too large code({2}),count({3})",
this.AsSrc, this.AsDstF, this.Result.Code, this.Result.Count);
return 0;
}
if (idx < 0)
{
this.Total = new int[pages];
this.Done = new int[pages];
Util.set(this.Total, 1);
Util.set(this.Done, 0);
}
else
{
this.Total[idx] = pages;
}
for (var i = 0; i < pages; i++)
{
this.Pdf2imgProc(images[i], idx, i, file_c);
}
return pages;
}
示例3: ConvertPDFTOneImage
public static void ConvertPDFTOneImage()
{
MagickReadSettings settings = new MagickReadSettings();
// Settings the density to 300 dpi will create an image with a better quality
settings.Density = new PointD(300, 300);
using (MagickImageCollection images = new MagickImageCollection())
{
// Add all the pages of the pdf file to the collection
images.Read(SampleFiles.SnakewarePdf, settings);
// Create new image that appends all the pages horizontally
using (MagickImage horizontal = images.AppendHorizontally())
{
// Save result as a png
horizontal.Write(SampleFiles.OutputDirectory + "Snakeware.horizontal.png");
}
// Create new image that appends all the pages horizontally
using (MagickImage vertical = images.AppendVertically())
{
// Save result as a png
vertical.Write(SampleFiles.OutputDirectory + "Snakeware.vertical.png");
}
}
}
示例4: 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);
}
}
示例5: Test_Collection_Exceptions
public void Test_Collection_Exceptions()
{
using (MagickImageCollection collection = new MagickImageCollection())
{
MagickReadSettings settings = new MagickReadSettings();
settings.PixelStorage = new PixelStorageSettings();
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
collection.Read(Files.RoseSparkleGIF, settings);
});
}
}
示例6: Convert2Jpeg
public void Convert2Jpeg(bool rotate = false)
{
try
{
MagickReadSettings settings = new MagickReadSettings();
// Settings the density to 300 dpi will create an image with a better quality
settings.Density = new PointD(300, 300);
using (MagickImageCollection images = new MagickImageCollection())
{
// Add all the pages of the pdf file to the collection
images.Read(_pdf.FullName, settings);
if (images.Count > 0 && images[0].Format == MagickFormat.Pdf)
{
_logger.InfoFormat("Handle {0}", _pdf.FullName);
int page = 1;
foreach (MagickImage image in images)
{
var newFileName = GetFilePageName(page) + ".jpg";
// Need page rotation?
if (rotate)
image.Rotate(90.0);
// Write page to file that contains the page number
image.Format = MagickFormat.Jpg;
image.CompressionMethod = CompressionMethod.JPEG;
image.Quality = 75;
image.Write(newFileName);
_logger.InfoFormat("-> {0}", newFileName);
// Writing to a specific format works the same as for a single image
page++;
}
}
}
}
catch (Exception ex)
{
_logger.Error(ex.Message, ex);
}
}
示例7: SplitIco
public int SplitIco(string icoFileName)
{
var fullName = Path.GetFullPath(icoFileName);
var folder = Path.GetDirectoryName(fullName);
var baseName = Path.GetFileNameWithoutExtension(fullName);
using (var imageCollection = new MagickImageCollection())
{
imageCollection.Read(icoFileName);
foreach (var image in imageCollection)
{
var pngFileName = baseName + "-" + image.Height + ".png";
var pngFile = Path.Combine(folder, pngFileName);
image.Write(pngFile);
}
}
return 0;
}
示例8: 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);
}
}
示例9: Test_AdditionalInfo
public void Test_AdditionalInfo()
{
using (MagickImageCollection images = new MagickImageCollection())
{
images.Read(Files.Coders.LayerStylesSamplePSD);
CheckProfile(images[1], 264);
var defines = new PsdWriteDefines()
{
AdditionalInfo = PsdAdditionalInfo.All
};
WriteAndCheckProfile(images, defines, 264);
defines.AdditionalInfo = PsdAdditionalInfo.Selective;
WriteAndCheckProfile(images, defines, 152);
defines.AdditionalInfo = PsdAdditionalInfo.None;
WriteAndCheckProfile(images, defines, 0);
}
}
示例10: ConvertPDFToMultipleImages
public static void ConvertPDFToMultipleImages()
{
MagickReadSettings settings = new MagickReadSettings();
// Settings the density to 300 dpi will create an image with a better quality
settings.Density = new PointD(300, 300);
using (MagickImageCollection images = new MagickImageCollection())
{
// Add all the pages of the pdf file to the collection
images.Read(SampleFiles.SnakewarePdf, settings);
int page = 1;
foreach (MagickImage image in images)
{
// Write page to file that contains the page number
image.Write(SampleFiles.OutputDirectory + "Snakeware.Page" + page + ".png");
// Writing to a specific format works the same as for a single image
image.Format = MagickFormat.Ptif;
image.Write(SampleFiles.OutputDirectory + "Snakeware.Page" + page + ".tif");
page++;
}
}
}
示例11: ConvertToGrayScale
public void ConvertToGrayScale(string sourceFile, string targetFile)
{
using (MagickImageCollection images = new MagickImageCollection())
{
string newTargetFile = @"D:\Development\Magik\Images\NewTiffs\New.tif";
MagickReadSettings settings = new MagickReadSettings();
images.Read(sourceFile, settings);
settings.FrameIndex = 0; // First page
settings.FrameCount = images.Count; // Number of pages
int count = images.Count;
foreach (MagickImage image in images)
{
image.ColorType = ColorType.Grayscale;
image.Quantize();
image.Write(newTargetFile + count.ToString() + ".tif");
++count;
}
}
Process proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = @"C:\Program Files (x86)\ImageMagick-6.8.6-Q8\convert.exe",
Arguments = @"D:\Development\Magik\Images\NewTiffs\*.tif D:\Development\Magik\Images\Combined\all-in-one.tif",
UseShellExecute = false,
RedirectStandardError = true,
CreateNoWindow = true
}
};
proc.Start();
}
示例12: Test_Warning
public void Test_Warning()
{
int count = 0;
EventHandler<WarningEventArgs> warningDelegate = delegate (object sender, WarningEventArgs arguments)
{
Assert.IsNotNull(sender);
Assert.IsNotNull(arguments);
Assert.IsNotNull(arguments.Message);
Assert.IsNotNull(arguments.Exception);
Assert.AreNotEqual("", arguments.Message);
count++;
};
using (MagickImageCollection collection = new MagickImageCollection())
{
collection.Warning += warningDelegate;
collection.Read(Files.EightBimTIF);
Assert.AreNotEqual(0, count);
int expectedCount = count;
collection.Warning -= warningDelegate;
collection.Read(Files.EightBimTIF);
Assert.AreEqual(expectedCount, count);
}
}
示例13: Test_ToBase64
public void Test_ToBase64()
{
using (MagickImageCollection collection = new MagickImageCollection())
{
Assert.AreEqual("", collection.ToBase64());
collection.Read(Files.Builtin.Logo);
Assert.AreEqual(1228800, collection.ToBase64(MagickFormat.Rgb).Length);
}
}
示例14: Test_Append
public void Test_Append()
{
int width = 70;
int height = 46;
using (MagickImageCollection collection = new MagickImageCollection())
{
ExceptionAssert.Throws<InvalidOperationException>(delegate ()
{
collection.AppendHorizontally();
});
ExceptionAssert.Throws<InvalidOperationException>(delegate ()
{
collection.AppendVertically();
});
collection.Read(Files.RoseSparkleGIF);
Assert.AreEqual(width, collection[0].Width);
Assert.AreEqual(height, collection[0].Height);
using (MagickImage image = collection.AppendHorizontally())
{
Assert.AreEqual(width * 3, image.Width);
Assert.AreEqual(height, image.Height);
}
using (MagickImage image = collection.AppendVertically())
{
Assert.AreEqual(width, image.Width);
Assert.AreEqual(height * 3, image.Height);
}
}
}
示例15: Test_Read
public void Test_Read()
{
MagickImageCollection collection = new MagickImageCollection();
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
collection.Read(new byte[0]);
});
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
collection.Read((byte[])null);
});
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
collection.Read((Stream)null);
});
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
collection.Read((string)null);
});
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
collection.Read(Files.Missing);
});
collection.Read(File.ReadAllBytes(Files.RoseSparkleGIF));
Assert.AreEqual(3, collection.Count);
using (FileStream fs = File.OpenRead(Files.RoseSparkleGIF))
{
collection.Read(fs);
Assert.AreEqual(3, collection.Count);
}
collection.Read(Files.RoseSparkleGIF);
Test_Read(collection);
collection.Read(new FileInfo(Files.RoseSparkleGIF));
collection.Dispose();
}