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); } }
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); } }
/** * 指定されたディレクトリ内にある画像から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; }
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]"); }
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()); } } }
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); } }
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 } } } }