//Gif effects return a new object public IImageWrapper Angry() { var gif = new GifWrapper(image); image.Dispose(); return(gif.Angry()); }
public void Dispose() { if (_image != null) { _image.Dispose(); _image = null; } }
public void Test_Constructor_Bitmap() { ExceptionAssert.Throws <ArgumentNullException>(delegate() { new MagickImage((Bitmap)null); }); using (Bitmap bitmap = new Bitmap(Files.SnakewarePNG)) { using (MagickImage image = new MagickImage(bitmap)) { Assert.AreEqual(286, image.Width); Assert.AreEqual(67, image.Height); Assert.AreEqual(MagickFormat.Png, image.Format); } } using (Bitmap bitmap = new Bitmap(50, 100, PixelFormat.Format24bppRgb)) { using (MagickImage image = new MagickImage(bitmap)) { Assert.AreEqual(50, image.Width); Assert.AreEqual(100, image.Height); Assert.AreEqual(MagickFormat.Bmp3, image.Format); image.Dispose(); } } }
public void Test_IComparable() { MagickImage first = new MagickImage(Color.Red, 10, 5); Assert.AreEqual(0, first.CompareTo(first)); Assert.AreEqual(1, first.CompareTo(null)); Assert.IsFalse(first < null); Assert.IsFalse(first <= null); Assert.IsTrue(first > null); Assert.IsTrue(first >= null); Assert.IsTrue(null < first); Assert.IsTrue(null <= first); Assert.IsFalse(null > first); Assert.IsFalse(null >= first); MagickImage second = new MagickImage(Color.Green, 5, 5); Assert.AreEqual(1, first.CompareTo(second)); Assert.IsFalse(first < second); Assert.IsFalse(first <= second); Assert.IsTrue(first > second); Assert.IsTrue(first >= second); second = new MagickImage(Color.Red, 5, 10); Assert.AreEqual(0, first.CompareTo(second)); Assert.IsFalse(first == second); Assert.IsFalse(first < second); Assert.IsTrue(first <= second); Assert.IsFalse(first > second); Assert.IsTrue(first >= second); first.Dispose(); second.Dispose(); }
private void OcrImage_Click(object sender, RoutedEventArgs e) { this.ScanResult.Text = string.Empty; this.ImageThumbnail.Source = this.GetThumbnail(); using (var ocrEngine = new TesseractEngine(string.Format(CultureInfo.InvariantCulture, "{0}\\tessdata", System.IO.Path.GetDirectoryName(this.GetType().Assembly.Location)), "eng", EngineMode.Default)) { var scannableImage = this.GetScannableImage(); var image = new MagickImage(scannableImage.ConvertToByteArray()); try { /* TextCleanerScript cleaner = new TextCleanerScript(); */ // have to load Pix via a bitmap since Pix doesn't support loading a stream. using (var pix = PixConverter.ToPix(scannableImage)) { using (var page = ocrEngine.Process(pix)) { // Console.WriteLine(page.GetMeanConfidence() + " : " + page.GetText()); this.ScanResult.Text += string.Format( CultureInfo.InvariantCulture, "Confidence {0} - #\"{1}\"#", page.GetMeanConfidence(), page.GetText()); } } } finally { image.Dispose(); } } }
static void PostProcessing(MagickImage img, string outPath) { Program.timer.Stop(); img.Dispose(); //long bytesPost = new FileInfo(outPath).Length; //Program.Print("-> Done. Size pre: " + Format.Filesize(bytesPre) + " - Size post: " + Format.Filesize(bytesPost) + " - Ratio: " + Format.Ratio(bytesPre, bytesPost)); }
private void MergeImage(string phase, string[] words) { var position = 1; using (MagickImageCollection images = new MagickImageCollection()) { foreach (var line in words) { foreach (var word in line) { MagickImage image = new MagickImage($"~/Words/{word}/{word}-{phase}.png"); //image.Extent(90, 400, position == 1 ? Gravity.Center : Gravity.South); image.Extent(-5, -90 * position, 90, 400); //image.Resize(500, 350); image.Transparent(new MagickColor("#ffffff")); images.Add(image); } position++; } using (MagickImage horizontal = images.AppendHorizontally()) { MagickImage background = new MagickImage("~/Words/background.png"); horizontal.Composite(background, CompositeOperator.DstAtop); Directory.CreateDirectory($"{OutputPath}/{FolderName}"); horizontal.Write($"{OutputPath}/{FolderName}/{FolderName}-{phase}.png"); background.Dispose(); } } }
public static string ImgFileToBase64(MagickImage _ImgFile, int maxedge = 0, int CompressionQuality = 70) { string thePictureDataAsString = ""; MemoryStream ms_mini = new MemoryStream(); _ImgFile.Format = MagickFormat.Jpeg; if (CompressionQuality <= 0) { _ImgFile.Quality = 70; } _ImgFile.CompressionMethod = CompressionMethod.JPEG; if (maxedge > 0) { if (_ImgFile.Width > maxedge || _ImgFile.Height > maxedge) { _ImgFile.Resize(new MagickGeometry(maxedge)); } _ImgFile.Sharpen(0, 0.8, Channels.All); } _ImgFile.Strip(); _ImgFile.Write(ms_mini); thePictureDataAsString = Convert.ToBase64String(ms_mini.ToArray()); ms_mini.Dispose(); _ImgFile.Dispose(); return(thePictureDataAsString); }
/// <summary> /// 아이콘 체인지 메서드 /// </summary> public CiconResult ChangeIco() { IconChanger Ic = new IconChanger(); string icoPath = ""; if (!Path.GetExtension(_icoPath).Equals(".ico")) { using (MagickImage image = new MagickImage(_icoPath)) { image.Settings.SetDefine("icon:auto-resize", "256,128,96,64,48,32,16"); //TODO:https://www.imagemagick.org/discourse-server/viewtopic.php?t=14080 image.Write(_tempPath + @"\tempico.ico"); image.Dispose(); } icoPath = _tempPath + @"\tempico.ico"; } else { icoPath = _icoPath; } if (_fileDestPath == null) //exe파일 저장 경로를 지정 안했을때 { return(Ic.ChangeIcon(Path.GetDirectoryName(_scriptPath) + @"\" + Path.GetFileNameWithoutExtension(_scriptPath) + ".exe", icoPath)); } else { return(Ic.ChangeIcon(Path.GetDirectoryName(_fileDestPath) + @"\" + Path.GetFileNameWithoutExtension(_fileDestPath) + ".exe", icoPath)); } }
// TODO LAH 2016-12-21: move this to Image private static void SaveResizedImage(Image image, int width, int height, string targetPath, bool skipIfNewer = true) { if (skipIfNewer && File.Exists(targetPath)) { var imageInfo = new FileInfo(image.Path); var existingInfo = new FileInfo(targetPath); if (imageInfo.LastWriteTime <= existingInfo.LastWriteTime) { MagickImage target = new MagickImage(targetPath); image.Width = target.Width; image.Height = target.Height; target.Dispose(); Console.WriteLine(string.Format("Skipping resizing for {0} (target file's last write time is newer than source", Path.GetFileName(targetPath))); return; } } var mi = new MagickImage(image.Path); Console.WriteLine(string.Format("Generating {0}x{1} for {2}", width, height, image.Name)); mi.Resize(width, height); image.Width = mi.Width; image.Height = mi.Height; mi.Write(targetPath); mi.Dispose(); }
private static bool GenerateThumb(string filename, string destname, int _LorS) { bool _returnStatus = false; if (File.Exists(destname)) { } using (MagickImage image = new MagickImage(filename)) { double dw = 1; if (_LorS == 1) { dw = (double)LargeThumbSize / image.Width; } if (_LorS == 0) { dw = (double)SmallThumbSize / 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(destname); image.Write(destname); image.Dispose(); _returnStatus = true; } return(_returnStatus); }
public void Test_Dispose() { MagickImage image = new MagickImage(); image.Dispose(); image.Verbose = true; }
// converting image in background private void backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { if (image_before != null) { if (image_after != null && !image_after.IsDisposed) { image_after.Dispose(); } try { image_after = profile.DoConversion(image_before); } catch (MagickCorruptImageErrorException ex) { MessageBox.Show("An error has occured during while preparing preview image!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if (!image_after.IsDisposed) { image_after.Dispose(); } image_after = null; return; } } }
public void Test_IEquatable() { MagickImage first = new MagickImage(Color.Red, 10, 10); Assert.IsFalse(first == null); Assert.IsFalse(first.Equals(null)); Assert.IsTrue(first.Equals(first)); Assert.IsTrue(first.Equals((object)first)); MagickImage second = new MagickImage(Color.Red, 10, 10); Assert.IsTrue(first == second); Assert.IsTrue(first.Equals(second)); Assert.IsTrue(first.Equals((object)second)); second = new MagickImage(Color.Green, 10, 10); Assert.IsTrue(first != second); Assert.IsFalse(first.Equals(second)); first.Dispose(); second.Dispose(); first = null; Assert.IsTrue(first == null); Assert.IsFalse(first != null); }
/// <summary> /// Dispose internal IDisposable. /// </summary> public void Dispose() { if (image != null && !image.IsDisposed) { image.Dispose(); } }
public static CompareResults CompareSessions(Session originalSession, Session newSession) { String outputPath = Properties.Settings.Default.DefaultPicturePath + "\\" + originalSession.Time.ToFileTimeUtc() + "_" + newSession.Time.ToFileTimeUtc(); Directory.CreateDirectory(outputPath); CompareResults results = new CompareResults(originalSession, newSession); List <UrlResults> ListOfUrlResults = new List <UrlResults>(); foreach (var url in originalSession.Urls) { if (url.Uri == null || url.Uri.Trim() == "") { continue; } UrlResults urlResults = new UrlResults(); urlResults.OriginalUrl = url; MagickImage image = new MagickImage(url.PicturePath); Url url2 = null; foreach (Url urla in newSession.Urls) { if (urla.Uri == url.Uri) { url2 = urla; } } if (url2 != null && url2.PicturePath != "") { urlResults.NewUrl = url2; MagickImage compareImage = new MagickImage(); MagickImage anotherImage = new MagickImage(url2.PicturePath); image.Compare(anotherImage, ErrorMetric.Absolute, compareImage); String compareImagePath = outputPath + "\\" + new FileInfo(url.PicturePath).Name; compareImage.Write(compareImagePath); urlResults.ResultPicturePath = compareImagePath; image.Dispose(); anotherImage.Dispose(); compareImage.Dispose(); } else { urlResults.Result = "No Matching Url In New Session Found"; } ListOfUrlResults.Add(urlResults); } results.UrlResults = ListOfUrlResults.ToArray(); // foreach (var url in newSession.Urls) // { // // } //Foreach url in the original session, compare source and images... return(results); }
public void Dispose() { if (0 == Interlocked.CompareExchange(ref _isDisposed, 1, 0)) { _native.Dispose(); } }
public void ShouldReturnTrueWhenTheImageIsDisposed() { IMagickImage image = new MagickImage(); image.Dispose(); Assert.IsTrue(image.IsDisposed); }
private void Save(MagickImage map, string name, string filepath) { string fileType = ".tga"; //map.Scale(384, 237); map.Write(filepath + "map_" + name + fileType); map.Dispose(); }
public GifWrapper(MagickImage frame) { image = new MagickImageCollection(); for (int i = 0; i < defaultFrameCount; i++) { image.Add(new MagickImage(frame)); } frame.Dispose(); }
//=========================================================================================== private static void Test_Clone(MagickImage first, MagickImage second) { Assert.AreEqual(first, second); second.Format = MagickFormat.Jp2; Assert.AreEqual(first.Format, MagickFormat.Png); Assert.AreEqual(second.Format, MagickFormat.Jp2); second.Dispose(); Assert.AreEqual(first.Format, MagickFormat.Png); }
/// <summary> /// Removes all the profiles and comments off an image /// </summary> /// <param name="filePath"></param> private void RemoveExif(string filePath) { using (MagickImage metaImage = new MagickImage()) { metaImage.Read(filePath); metaImage.Strip(); metaImage.Write(filePath); metaImage.Dispose(); } }
public void Haah() { MagickImage clone = new MagickImage(image); clone.Flip(); clone.Extent(clone.Width, clone.Height / 2); image.Composite(clone, CompositeOperator.Over); clone.Dispose(); }
public void Save(string path) { if (File.Exists(@path)) { File.Delete(path); } full_map.Write(@path, MagickFormat.Png); full_map.Dispose(); }
public void Waaw() { MagickImage clone = new MagickImage(image); clone.Flop(); clone.Extent(clone.Width / 2, clone.Height); image.Composite(clone, CompositeOperator.Over); clone.Dispose(); }
private string Process() { try { using (MagickImage srcMagickImage = new MagickImage(_inputFilePath)) { using (MagickImage sepiaImage = new MagickImage(new MagickColor(125, 125, 125, 55), srcMagickImage.Width, srcMagickImage.Height)) { sepiaImage.SepiaTone(new Percentage(92)); sepiaImage.Composite(srcMagickImage, CompositeOperator.Overlay); sepiaImage.BrightnessContrast(new Percentage(10), new Percentage(0)); using (Bitmap bitmap = new Bitmap(srcMagickImage.Width * 2, srcMagickImage.Height * 2)) { using (Graphics graphics = Graphics.FromImage(bitmap)) { Rectangle rectangle = new Rectangle(0, 0, srcMagickImage.Width * 2, srcMagickImage.Height * 2); GraphicsPath gp = new GraphicsPath(); gp.AddEllipse(rectangle); PathGradientBrush pgb = new PathGradientBrush(gp) { CenterPoint = new PointF(rectangle.Width / 2, rectangle.Height / 2), CenterColor = Color.White, SurroundColors = new Color[] { new MagickColor(0, 0, 0, 200) } }; graphics.FillPath(pgb, gp); bitmap.Save("gradientImage.jpg", ImageFormat.Jpeg); pgb.Dispose(); gp.Dispose(); } } using (MagickImage afterImage = new MagickImage("gradientImage.jpg")) { afterImage.Crop(afterImage.Width / 4, afterImage.Height / 4, afterImage.Width / 2, afterImage.Height / 2); sepiaImage.Composite(afterImage, CompositeOperator.ColorBurn); sepiaImage.Write(_outputFilePath); sepiaImage.Dispose(); return(string.Empty); } } } } catch (Exception e) { return(e.Message); } }
public void Test_Image_Read() { using (MagickImage image = new MagickImage()) { MagickReadSettings settings = new MagickReadSettings(); settings.Density = new PointD(300); image.Read(Files.SnakewarePNG, settings); Assert.AreEqual(300, image.Density.X); settings = null; image.Read(Files.ImageMagickJPG, settings); } using (MagickImage image = new MagickImage(Files.RoseSparkleGIF)) { MagickImage imageA = new MagickImage(); MagickImage imageB = new MagickImage(); MagickReadSettings settings = new MagickReadSettings(); imageA.Read(Files.RoseSparkleGIF, settings); Assert.AreEqual(image, imageA); settings = new MagickReadSettings(); settings.FrameIndex = 1; imageA.Read(Files.RoseSparkleGIF, settings); Assert.AreNotEqual(image, imageA); imageB.Read(Files.RoseSparkleGIF + "[1]"); Assert.AreEqual(imageA, imageB); settings = new MagickReadSettings(); settings.FrameIndex = 2; imageA.Read(Files.RoseSparkleGIF, settings); Assert.AreNotEqual(image, imageA); imageB.Read(Files.RoseSparkleGIF + "[2]"); Assert.AreEqual(imageA, imageB); ExceptionAssert.Throws <MagickOptionErrorException>(delegate() { settings = new MagickReadSettings(); settings.FrameIndex = 3; imageA.Read(Files.RoseSparkleGIF, settings); }); imageA.Dispose(); imageB.Dispose(); } }
public void ShouldThrowExceptionWhenImageIsDisposed() { IMagickImage image = new MagickImage(); image.Dispose(); ExceptionAssert.Throws <ObjectDisposedException>(() => { image.BackgroundColor = MagickColors.PaleGreen; }); }
public virtual void Dispose() { if (image1 != null) { image1.Dispose(); } if (image2 != null) { image2.Dispose(); } }
public void SetImage(Stream stream, int width = 4, int height = 4) { if (_image != null) { _image.Dispose(); } _image = new MagickImage(stream); _width = width; _height = height; }
public void Test_Read() { MagickImage image = new MagickImage(); ExceptionAssert.Throws<ArgumentException>(delegate() { image.Read(new byte[0]); }); ExceptionAssert.Throws<ArgumentNullException>(delegate() { image.Read((byte[])null); }); ExceptionAssert.Throws<ArgumentNullException>(delegate() { image.Read((Bitmap)null); }); ExceptionAssert.Throws<ArgumentNullException>(delegate() { image.Read((Stream)null); }); ExceptionAssert.Throws<ArgumentNullException>(delegate() { image.Read((string)null); }); ExceptionAssert.Throws<ArgumentException>(delegate() { image.Read(Files.Missing); }); ExceptionAssert.Throws<ArgumentException>(delegate() { image.Read("png:" + Files.Missing); }); image.Read(File.ReadAllBytes(Files.SnakewarePNG)); using (Bitmap bitmap = new Bitmap(Files.SnakewarePNG)) { image.Read(bitmap); Assert.AreEqual(MagickFormat.Png, image.Format); } using (Bitmap bitmap = new Bitmap(100, 100, PixelFormat.Format24bppRgb)) { image.Read(bitmap); Assert.AreEqual(MagickFormat.Bmp, image.Format); } using (FileStream fs = File.OpenRead(Files.SnakewarePNG)) { image.Read(fs); } image.Read(Files.SnakewarePNG); image.Read("rose:"); image.Read(Files.RoseSparkleGIF); Assert.AreEqual("RoseSparkle.gif", Path.GetFileName(image.FileName)); image.Read("png:" + Files.SnakewarePNG); MagickColor red = new MagickColor("red"); image.Read(red, 50, 50); Assert.AreEqual(50, image.Width); Assert.AreEqual(50, image.Height); Test_Pixel(image, 10, 10, red); image.Read("xc:red", 50, 50); Assert.AreEqual(50, image.Width); Assert.AreEqual(50, image.Height); Test_Pixel(image, 5, 5, red); image.Dispose(); ExceptionAssert.Throws<ObjectDisposedException>(delegate() { image.Read("logo:"); }); }