本文整理汇总了C#中ImageMagick.MagickImage.Scale方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImage.Scale方法的具体用法?C# MagickImage.Scale怎么用?C# MagickImage.Scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageMagick.MagickImage
的用法示例。
在下文中一共展示了MagickImage.Scale方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: scale
public static void scale(string image_path, string output_path, int width_mul = 150, int height_mul = 150)
{
using (MagickImage image = new MagickImage(image_path)) {
image.Scale(new Percentage(width_mul), new Percentage(height_mul));
image.Write(output_path);
}
}
示例2: CreateScaledImage
private void CreateScaledImage()
{
using (MagickImage image = new MagickImage(imagePath))
{
//TODO: Perhaps see what the original size is then scale based on that
//Keeping it at 25% may "punish" those images that are barely over the limit
image.Scale(new Percentage(25));
image.Write(Constants.ScaledImgFile);
}
}
示例3: GenerateAnimationGIF
/**
* 指定されたディレクトリ内にある画像からGIFアニメーションを生成する
* @param {String} コマ画像が入っているディレクトリのパス
* @return {Boolean} 成功した場合はtrue
*/
Boolean GenerateAnimationGIF(String tmpDir, String dstPath) {
String[] files = Directory.GetFiles(tmpDir);
if (files.Length == 0) return false;
using (MagickImageCollection collection = new MagickImageCollection()) {
MagickImage canvas = new MagickImage(files[files.Length - 1]);
canvas.AnimationDelay = 250;
canvas.Scale((int)(canvas.Width * 0.5), (int)(canvas.Height * 0.5));
collection.Add(canvas);
int perFrame = (int)Math.Ceiling(600.0 / files.Length);
foreach (String file in files) {
canvas = new MagickImage(file);
canvas.AnimationDelay = perFrame;
canvas.Scale((int)(canvas.Width * 0.5), (int)(canvas.Height * 0.5));
collection.Add(canvas);
}
collection.Optimize();
collection.Write(dstPath);
};
return true;
}
示例4: ExecuteScale
private void ExecuteScale(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.Scale((MagickGeometry)arguments["geometry"]);
else if (OnlyContains(arguments, "percentage"))
image.Scale((Percentage)arguments["percentage"]);
else if (OnlyContains(arguments, "percentageWidth", "percentageHeight"))
image.Scale((Percentage)arguments["percentageWidth"], (Percentage)arguments["percentageHeight"]);
else if (OnlyContains(arguments, "width", "height"))
image.Scale((Int32)arguments["width"], (Int32)arguments["height"]);
else
throw new ArgumentException("Invalid argument combination for 'scale', allowed combinations are: [geometry] [percentage] [percentageWidth, percentageHeight] [width, height]");
}
示例5: Test_Scale
public void Test_Scale()
{
using (MagickImage image = new MagickImage(Files.CirclePNG))
{
MagickColor color = Color.FromArgb(159, 255, 255, 255);
using (PixelCollection pixels = image.GetReadOnlyPixels())
{
ColorAssert.AreEqual(color, pixels.GetPixel(image.Width / 2, image.Height / 2).ToColor());
}
image.Scale((Percentage)400);
using (PixelCollection pixels = image.GetReadOnlyPixels())
{
ColorAssert.AreEqual(color, pixels.GetPixel(image.Width / 2, image.Height / 2).ToColor());
}
}
}
示例6: Test_Scale
public void Test_Scale()
{
using (MagickImage image = new MagickImage(Files.CirclePNG))
{
MagickColor color = MagickColor.FromRgba(255, 255, 255, 159);
ColorAssert.AreEqual(color, image, image.Width / 2, image.Height / 2);
image.Scale((Percentage)400);
ColorAssert.AreEqual(color, image, image.Width / 2, image.Height / 2);
}
}
示例7: Test_LinearStretch
public void Test_LinearStretch()
{
using (MagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
{
image.Scale(100, 100);
image.LinearStretch((Percentage)1, (Percentage)1);
using (MemoryStream memStream = new MemoryStream())
{
image.Format = MagickFormat.Histogram;
image.Write(memStream);
memStream.Position = 0;
using (MagickImage histogram = new MagickImage(memStream))
{
#if Q8
ColorAssert.AreEqual(MagickColors.Red, histogram, 66, 11);
ColorAssert.AreEqual(MagickColors.Lime, histogram, 95, 122);
ColorAssert.AreEqual(MagickColors.Blue, histogram, 204, 80);
#elif Q16 || Q16HDRI
ColorAssert.AreEqual(MagickColors.Red, histogram, 34, 182);
ColorAssert.AreEqual(MagickColors.Lime, histogram, 122, 193);
ColorAssert.AreEqual(MagickColors.Blue, histogram, 210, 194);
#else
#error Not implemented!
#endif
}
}
image.LinearStretch((Percentage)10, (Percentage)90);
using (MemoryStream memStream = new MemoryStream())
{
image.Format = MagickFormat.Histogram;
image.Write(memStream);
memStream.Position = 0;
using (MagickImage histogram = new MagickImage(memStream))
{
#if Q8
ColorAssert.AreEqual(MagickColors.Red, histogram, 103, 183);
ColorAssert.AreEqual(MagickColors.Lime, histogram, 147, 188);
ColorAssert.AreEqual(MagickColors.Blue, histogram, 194, 190);
#elif Q16 || Q16HDRI
ColorAssert.AreEqual(MagickColors.Red, histogram, 221, 182);
ColorAssert.AreEqual(MagickColors.Lime, histogram, 12, 183);
ColorAssert.AreEqual(MagickColors.Blue, histogram, 45, 194);
#else
#error Not implemented!
#endif
}
}
}
}