本文整理汇总了C#中ImageMagick.MagickImage.Thumbnail方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImage.Thumbnail方法的具体用法?C# MagickImage.Thumbnail怎么用?C# MagickImage.Thumbnail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageMagick.MagickImage
的用法示例。
在下文中一共展示了MagickImage.Thumbnail方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefinesThatNeedToBeSetBeforeReadingAnImage
public static void DefinesThatNeedToBeSetBeforeReadingAnImage()
{
MagickReadSettings settings = new MagickReadSettings();
// Set define that tells the jpeg coder that the output image will be 32x32
settings.SetDefine(MagickFormat.Jpeg, "size", "32x32");
// Read image from file
using (MagickImage image = new MagickImage(SampleFiles.SnakewareJpg))
{
// Create thumnail that is 32 pixels wide and 32 pixels high
image.Thumbnail(32, 32);
// Save image as tiff
image.Write(SampleFiles.OutputDirectory + "Snakeware.tiff");
}
}
示例2: GenerateCache
public void GenerateCache(FileItem fileItem)
{
bool deleteFile = false;
if (fileItem == null)
return;
if (!File.Exists(fileItem.FileName))
return;
if ((File.Exists(fileItem.LargeThumb) && File.Exists(fileItem.SmallThumb)) && File.Exists(fileItem.InfoFile))
return;
if (fileItem.Loading)
return;
fileItem.Loading = true;
PhotoUtils.WaitForFile(fileItem.FileName);
string filename = fileItem.FileName;
if (fileItem.IsMovie)
{
try
{
string ffmpeg_exe = Path.Combine(Settings.ApplicationFolder, "ffmpeg.exe");
if (File.Exists(ffmpeg_exe))
{
string thumb = Path.Combine(Path.GetDirectoryName(fileItem.FileName),
Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg");
PhotoUtils.RunAndWait(ffmpeg_exe, String.Format("-i \"{0}\" -ss 00:00:01.000 -f image2 -vframes 1 \"{1}\"", fileItem.FileName, thumb));
if (File.Exists(thumb))
{
deleteFile = true;
filename = thumb;
}
}
}
catch (Exception exception)
{
Log.Error("Error get video thumb", exception);
}
}
if (fileItem.IsRaw)
{
try
{
string dcraw_exe = Path.Combine(Settings.ApplicationFolder, "dcraw.exe");
if (File.Exists(dcraw_exe))
{
string thumb = Path.Combine(Path.GetTempPath(),
Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg");
PhotoUtils.RunAndWait(dcraw_exe,
string.Format(" -e -O \"{0}\" \"{1}\"", thumb, fileItem.FileName));
if (File.Exists(thumb))
{
deleteFile = true;
filename = thumb;
}
}
}
catch (Exception exception)
{
Log.Error("Error get dcraw thumb", exception);
}
}
GetMetadata(fileItem);
try
{
using (MagickImage image = new MagickImage(filename))
{
fileItem.FileInfo.SetSize(image.Width, image.Height);
double dw = (double)LargeThumbSize / image.Width;
image.FilterType = FilterType.Box;
image.Thumbnail((int)(image.Width * dw), (int)(image.Height * dw));
if (!ServiceProvider.Settings.DisableHardwareAccelerationNew)
image.UnsharpMask(1, 1, 0.5, 0.1);
PhotoUtils.CreateFolder(fileItem.LargeThumb);
image.Write(fileItem.LargeThumb);
fileItem.IsLoaded = true;
fileItem.Loading = false;
dw = (double)SmallThumbSize / image.Width;
image.Thumbnail((int)(image.Width * dw), (int)(image.Height * dw));
if (!ServiceProvider.Settings.DisableHardwareAccelerationNew)
image.UnsharpMask(1, 1, 0.5, 0.1);
PhotoUtils.CreateFolder(fileItem.SmallThumb);
image.Write(fileItem.SmallThumb);
fileItem.Thumbnail = LoadImage(fileItem.SmallThumb);
}
fileItem.SaveInfo();
SetImageInfo(fileItem);
if (deleteFile)
File.Delete(filename);
OnMetaDataUpdated(fileItem);
}
//.........这里部分代码省略.........
示例3: ExecuteThumbnail
private void ExecuteThumbnail(XmlElement element, MagickImage image)
{
Hashtable arguments = new Hashtable();
foreach (XmlAttribute attribute in element.Attributes)
{
if (attribute.Name == "geometry")
arguments["geometry"] = Variables.GetValue<MagickGeometry>(attribute);
else if (attribute.Name == "height")
arguments["height"] = Variables.GetValue<Int32>(attribute);
else if (attribute.Name == "percentage")
arguments["percentage"] = Variables.GetValue<Percentage>(attribute);
else if (attribute.Name == "percentageHeight")
arguments["percentageHeight"] = Variables.GetValue<Percentage>(attribute);
else if (attribute.Name == "percentageWidth")
arguments["percentageWidth"] = Variables.GetValue<Percentage>(attribute);
else if (attribute.Name == "width")
arguments["width"] = Variables.GetValue<Int32>(attribute);
}
if (OnlyContains(arguments, "geometry"))
image.Thumbnail((MagickGeometry)arguments["geometry"]);
else if (OnlyContains(arguments, "percentage"))
image.Thumbnail((Percentage)arguments["percentage"]);
else if (OnlyContains(arguments, "percentageWidth", "percentageHeight"))
image.Thumbnail((Percentage)arguments["percentageWidth"], (Percentage)arguments["percentageHeight"]);
else if (OnlyContains(arguments, "width", "height"))
image.Thumbnail((Int32)arguments["width"], (Int32)arguments["height"]);
else
throw new ArgumentException("Invalid argument combination for 'thumbnail', allowed combinations are: [geometry] [percentage] [percentageWidth, percentageHeight] [width, height]");
}
示例4: Test_Thumbnail
public void Test_Thumbnail()
{
using (MagickImage image = new MagickImage(Files.SnakewarePNG))
{
image.Thumbnail(100, 100);
Assert.AreEqual(100, image.Width);
Assert.AreEqual(23, image.Height);
}
}