private static void readImageInfo(string fileName) { var info = new MagickImageInfo(fileName); // Read from stream using (var memStream = LoadMemoryStreamImage(fileName)) { info = new MagickImageInfo(memStream); } // Read from byte array var data = LoadImageBytes(fileName); info = new MagickImageInfo(data); info = new MagickImageInfo(); info.Read(fileName); using (var memStream = LoadMemoryStreamImage(fileName)) { info.Read(memStream); } info.Read(data); Console.WriteLine(info.Width); Console.WriteLine(info.Height); Console.WriteLine(info.ColorSpace); Console.WriteLine(info.Format); Console.WriteLine(info.Density.X); Console.WriteLine(info.Density.Y); Console.WriteLine(info.Density.Units); }
public static void ReadBasicImageInformation() { // Read from file MagickImageInfo info = new MagickImageInfo(SampleFiles.SnakewarePng); // Read from stream using (MemoryStream memStream = LoadMemoryStreamImage()) { info = new MagickImageInfo(memStream); } // Read from byte array byte[] data = LoadImageBytes(); info = new MagickImageInfo(data); info = new MagickImageInfo(); info.Read(SampleFiles.SnakewarePng); using (MemoryStream memStream = LoadMemoryStreamImage()) { info.Read(memStream); } info.Read(data); Console.WriteLine(info.Width); Console.WriteLine(info.Height); Console.WriteLine(info.ColorSpace); Console.WriteLine(info.Format); Console.WriteLine(info.Density.X); Console.WriteLine(info.Density.Y); Console.WriteLine(info.Density.Units); }
public void Test_Read() { IMagickImageInfo imageInfo = new MagickImageInfo(); ExceptionAssert.ThrowsArgumentException("data", () => { imageInfo.Read(new byte[0]); }); ExceptionAssert.ThrowsArgumentNullException("data", () => { imageInfo.Read((byte[])null); }); ExceptionAssert.ThrowsArgumentNullException("file", () => { imageInfo.Read((FileInfo)null); }); ExceptionAssert.ThrowsArgumentNullException("stream", () => { imageInfo.Read((Stream)null); }); ExceptionAssert.ThrowsArgumentNullException("fileName", () => { imageInfo.Read((string)null); }); ExceptionAssert.Throws <MagickBlobErrorException>(() => { imageInfo.Read(Files.Missing); }, "error/blob.c/OpenBlob"); imageInfo.Read(File.ReadAllBytes(Files.SnakewarePNG)); using (FileStream fs = File.OpenRead(Files.SnakewarePNG)) { imageInfo.Read(fs); } imageInfo.Read(Files.ImageMagickJPG); Assert.AreEqual(ColorSpace.sRGB, imageInfo.ColorSpace); Assert.AreEqual(CompressionMethod.JPEG, imageInfo.Compression); Assert.AreEqual(MagickFormat.Jpeg, imageInfo.Format); Assert.AreEqual(118, imageInfo.Height); Assert.AreEqual(72, imageInfo.Density.X); Assert.AreEqual(72, imageInfo.Density.Y); Assert.AreEqual(DensityUnit.PixelsPerInch, imageInfo.Density.Units); Assert.AreEqual(Interlace.NoInterlace, imageInfo.Interlace); Assert.AreEqual(100, imageInfo.Quality); Assert.AreEqual(123, imageInfo.Width); }
public void Test_Read() { MagickImageInfo imageInfo = new MagickImageInfo(); ExceptionAssert.Throws <ArgumentException>(delegate() { imageInfo.Read(new byte[0]); }); ExceptionAssert.Throws <ArgumentNullException>(delegate() { imageInfo.Read((byte[])null); }); ExceptionAssert.Throws <ArgumentNullException>(delegate() { imageInfo.Read((FileInfo)null); }); ExceptionAssert.Throws <ArgumentNullException>(delegate() { imageInfo.Read((Stream)null); }); ExceptionAssert.Throws <ArgumentNullException>(delegate() { imageInfo.Read((string)null); }); ExceptionAssert.Throws <ArgumentException>(delegate() { imageInfo.Read(Files.Missing); }); imageInfo.Read(File.ReadAllBytes(Files.SnakewarePNG)); using (FileStream fs = File.OpenRead(Files.SnakewarePNG)) { imageInfo.Read(fs); } imageInfo.Read(Files.ImageMagickJPG); Assert.AreEqual(ColorSpace.sRGB, imageInfo.ColorSpace); Assert.AreEqual(CompressionMethod.JPEG, imageInfo.CompressionMethod); Assert.AreEqual(MagickFormat.Jpeg, imageInfo.Format); Assert.AreEqual(118, imageInfo.Height); Assert.AreEqual(Interlace.NoInterlace, imageInfo.Interlace); Assert.AreEqual(72, imageInfo.ResolutionX); Assert.AreEqual(72, imageInfo.ResolutionY); Assert.AreEqual(Resolution.PixelsPerInch, imageInfo.ResolutionUnits); Assert.AreEqual(123, imageInfo.Width); }
private void bInputChoose_Click(object sender, EventArgs e) { if (ofdInput.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // show labels in case of error lBefore.Visible = true; lAfter.Visible = true; // try to open the selected file info_before = new MagickImageInfo(); try { info_before.Read(ofdInput.FileName); } catch (MagickErrorException ex) { MessageBox.Show("Input file is not an image!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // clear everything, just in case image_before = null; image_after = null; return; } // read the image and display it in PictureBox image_before = new MagickImage(); image_before.Read(ofdInput.FileName); pbBefore.Image = image_before.ToBitmap(); lBefore.Visible = false; // prepare the image after conversion // and display it in PictureBox // using a backgroundWorker backgroundWorker.RunWorkerAsync(); } }
/// <summary> /// Read image metadata details /// </summary> /// <param name="imagePath"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> private static bool IsResizeNeedsToApply(string imagePath, int width, int height) { // Read from file var info = new MagickImageInfo(imagePath); info.Read(imagePath); return(info.Width > width && info.Height > height); }
public void ShouldThrowExceptionWhenFileNameIsInvalid() { ExceptionAssert.Throws <MagickBlobErrorException>(() => { var imageInfo = new MagickImageInfo(); imageInfo.Read(Files.Missing); }, "error/blob.c/OpenBlob"); }
public void ShouldThrowExceptionWhenFileNameIsNull() { ExceptionAssert.ThrowsArgumentNullException("fileName", () => { var imageInfo = new MagickImageInfo(); imageInfo.Read((string)null); }); }
public void ShouldThrowExceptionWhenFileNameIsEmpty() { ExceptionAssert.ThrowsArgumentException("fileName", () => { var imageInfo = new MagickImageInfo(); imageInfo.Read(string.Empty); }); }
public void ShouldThrowExceptionWhenStreamIsNull() { ExceptionAssert.ThrowsArgumentNullException("stream", () => { var imageInfo = new MagickImageInfo(); imageInfo.Read((Stream)null); }); }
public void ShouldThrowExceptionWhenDataIsEmpty() { ExceptionAssert.ThrowsArgumentException("data", () => { var imageInfo = new MagickImageInfo(); imageInfo.Read(new byte[0]); }); }
public void ShouldThrowExceptionWhenDataIsNull() { ExceptionAssert.ThrowsArgumentNullException("data", () => { var imageInfo = new MagickImageInfo(); imageInfo.Read((byte[])null); }); }
public void ShouldThrowExceptionWhenFileNameIsInvalid() { IMagickImageInfo imageInfo = new MagickImageInfo(); var exception = Assert.Throws <MagickBlobErrorException>(() => { imageInfo.Read(Files.Missing); }); Assert.Contains("error/blob.c/OpenBlob", exception.Message); }
public void ShouldReturnTheCorrectInformation() { IMagickImageInfo imageInfo = new MagickImageInfo(); imageInfo.Read(Files.ImageMagickJPG); Assert.Equal(ColorSpace.sRGB, imageInfo.ColorSpace); Assert.Equal(CompressionMethod.JPEG, imageInfo.Compression); Assert.EndsWith("ImageMagick.jpg", imageInfo.FileName); Assert.Equal(MagickFormat.Jpeg, imageInfo.Format); Assert.Equal(118, imageInfo.Height); Assert.Equal(72, imageInfo.Density.X); Assert.Equal(72, imageInfo.Density.Y); Assert.Equal(DensityUnit.PixelsPerInch, imageInfo.Density.Units); Assert.Equal(Interlace.NoInterlace, imageInfo.Interlace); Assert.Equal(100, imageInfo.Quality); Assert.Equal(123, imageInfo.Width); }
public void Test_Read() { MagickImageInfo imageInfo = new MagickImageInfo(); ExceptionAssert.Throws<ArgumentException>(delegate () { imageInfo.Read(new byte[0]); }); ExceptionAssert.Throws<ArgumentNullException>(delegate () { imageInfo.Read((byte[])null); }); ExceptionAssert.Throws<ArgumentNullException>(delegate () { imageInfo.Read((FileInfo)null); }); ExceptionAssert.Throws<ArgumentNullException>(delegate () { imageInfo.Read((Stream)null); }); ExceptionAssert.Throws<ArgumentNullException>(delegate () { imageInfo.Read((string)null); }); ExceptionAssert.Throws<ArgumentException>(delegate () { imageInfo.Read(Files.Missing); }); imageInfo.Read(File.ReadAllBytes(Files.SnakewarePNG)); using (FileStream fs = File.OpenRead(Files.SnakewarePNG)) { imageInfo.Read(fs); } imageInfo.Read(Files.ImageMagickJPG); Assert.AreEqual(ColorSpace.sRGB, imageInfo.ColorSpace); Assert.AreEqual(MagickFormat.Jpeg, imageInfo.Format); Assert.AreEqual(123, imageInfo.Width); Assert.AreEqual(118, imageInfo.Height); Assert.AreEqual(72, imageInfo.ResolutionX); Assert.AreEqual(72, imageInfo.ResolutionY); Assert.AreEqual(Resolution.PixelsPerInch, imageInfo.ResolutionUnits); }
public void ShouldThrowExceptionWhenDataIsEmpty() { IMagickImageInfo imageInfo = new MagickImageInfo(); ExceptionAssert.Throws <ArgumentException>("data", () => imageInfo.Read(new byte[0])); }
public void ShouldThrowExceptionWhenDataIsNull() { IMagickImageInfo imageInfo = new MagickImageInfo(); Assert.Throws <ArgumentNullException>("data", () => imageInfo.Read((byte[])null)); }
public void ShouldThrowExceptionWhenFileNameIsEmpty() { IMagickImageInfo imageInfo = new MagickImageInfo(); Assert.Throws <ArgumentException>("fileName", () => imageInfo.Read(string.Empty)); }
private void GetFileItemFormat() { foreach (FileItem fileItem in Files) { string source = fileItem.FileName; MagickImageInfo info = new MagickImageInfo(); info.Read(source); string format = info.Format.ToString(); string format2 = info.CompressionMethod.ToString(); OnProgressChange(fileItem.Name + " format is: " + format + "____" + format2); } }
public void CopyFiles(bool preview) { int counter = 0; try { _filenames.Clear(); OnProgressChange("Copying files"); foreach (FileItem fileItem in Files) { OnProgressChange("Copying file " + fileItem.Name); string source = preview ? fileItem.LargeThumb : fileItem.FileName; MagickImageInfo info = new MagickImageInfo(); info.Read(source); string format = info.Format.ToString(); if (format == "Jpeg") { string randomFile = Path.Combine(_tempdir, "image_" + counter.ToString("0000") + ".jpg"); AutoExportPluginHelper.ExecuteTransformPlugins(fileItem, PluginSetting.AutoExportPluginConfig, source, randomFile); _filenames.Add(randomFile); counter++; } if (format == "Tiff") { string randomFile = Path.Combine(_tempdir, "image_" + counter.ToString("0000") + ".tif"); using (MagickImage image = new MagickImage(source)) { image.Format = MagickFormat.Tiff; image.Write(randomFile); } _filenames.Add(randomFile); counter++; } if (format != "Jpeg" && format != "Tiff") { OnProgressChange(fileItem.Name + "has invalid format, will not be copied"); } if (_shouldStop) { OnActionDone(); return; } } } catch (Exception exception) { OnProgressChange("Error copy files " + exception.Message); Log.Error("Error copy files ", exception); _shouldStop = true; } }
public void ShouldThrowExceptionWhenDataIsEmpty() { IMagickImageInfo imageInfo = new MagickImageInfo(); Assert.Throws <ArgumentException>("data", () => imageInfo.Read(Array.Empty <byte>())); }
public void ShouldThrowExceptionWhenArrayIsEmpty() { IMagickImageInfo imageInfo = new MagickImageInfo(); Assert.Throws <ArgumentException>("data", () => imageInfo.Read(new byte[] { }, 0, 0)); }
public void ShouldThrowExceptionWhenFileNameIsNull() { IMagickImageInfo imageInfo = new MagickImageInfo(); Assert.Throws <ArgumentNullException>("fileName", () => imageInfo.Read((string)null)); }
public void ShouldThrowExceptionWhenStreamIsNull() { IMagickImageInfo imageInfo = new MagickImageInfo(); Assert.Throws <ArgumentNullException>("stream", () => imageInfo.Read((Stream)null)); }
public void CopyFiles(bool preview) { int counter = 0; try { _filenames.Clear(); OnProgressChange("Copying files"); WriteLog("Copying files"); WriteShortLog("Copying files"); foreach (FileItem fileItem in Files) { string source = preview ? fileItem.LargeThumb : fileItem.FileName; MagickImageInfo info = new MagickImageInfo(); info.Read(source); string format = info.Format.ToString(); OnProgressChange(fileItem.Name + " format is: " + format); WriteLog(fileItem.Name + " format is: " + format); WriteShortLog(fileItem.Name + " format is: " + format); if (format == "Jpeg") { OnProgressChange("Copying file " + fileItem.Name); WriteLog("Copying file " + fileItem.Name); WriteShortLog("Copying file " + fileItem.Name); string randomFile = Path.Combine(ProjetFolder, "image_" + counter.ToString("0000") + ".jpg"); AutoExportPluginHelper.ExecuteTransformPlugins(fileItem, PluginSetting.AutoExportPluginConfig, source, randomFile); _filenames.Add(randomFile); counter++; } if (format == "Tiff") { OnProgressChange("Converting file " + fileItem.Name); WriteLog("Converting file " + fileItem.Name); WriteShortLog("Converting file " + fileItem.Name); string randomFile = Path.Combine(ProjetFolder, "image_" + counter.ToString("0000") + ".jpg"); try { using (MagickImage image = new MagickImage(source)) { image.Format = MagickFormat.Jpeg; image.Write(randomFile); } _filenames.Add(randomFile); counter++; } catch (Exception exception) { Log.Error("Error converting Tiff file", exception); } } if (format == "Nef" || format == "Cr2" || format == "Crw") { OnProgressChange("Converting file " + fileItem.Name); WriteLog("Converting file " + fileItem.Name); WriteShortLog("Converting file " + fileItem.Name); string randomFile = Path.Combine(ProjetFolder, "image_" + counter.ToString("0000") + ".jpg"); try { string dcraw_exe = Path.Combine(Settings.ApplicationFolder, "dcraw.exe"); if (File.Exists(dcraw_exe)) { PhotoUtils.RunAndWait(dcraw_exe, string.Format(" -e -O \"{0}\" \"{1}\"", randomFile, source)); _filenames.Add(randomFile); counter++; } } catch (Exception exception) { Log.Error("Error converting Raw file", exception); } } if (format != "Jpeg" && format != "Tiff" && format != "Nef" && format != "Cr2" && format != "Crw") { OnProgressChange(fileItem.Name + " has invalid format, will not be copied"); WriteLog(fileItem.Name + " has invalid format, will not be copied"); WriteShortLog(fileItem.Name + " has invalid format, will not be copied"); } if (_shouldStop) { OnActionDone(); return; } } } catch (Exception exception) { OnProgressChange("Error copy files " + exception.Message); WriteLog("Error copy files " + exception.Message); WriteShortLog("Error copy files " + exception.Message); Log.Error("Error copy files ", exception); _shouldStop = true; } }
public void ShouldThrowExceptionWhenArrayIsNull() { IMagickImageInfo imageInfo = new MagickImageInfo(); Assert.Throws <ArgumentNullException>("data", () => imageInfo.Read(null, 0, 0)); }
public void ShouldThrowExceptionWhenOffsetIsNegative() { IMagickImageInfo imageInfo = new MagickImageInfo(); ExceptionAssert.Throws <ArgumentException>("offset", () => imageInfo.Read(new byte[] { 215 }, -1, 0)); }
public void ShouldThrowExceptionWhenCountIsNegative() { IMagickImageInfo imageInfo = new MagickImageInfo(); Assert.Throws <ArgumentException>("count", () => imageInfo.Read(new byte[] { 215 }, 0, -1)); }
public static void ReadBasicImageInformation() { // Read from file MagickImageInfo info = new MagickImageInfo(SampleFiles.SnakewarePng); // Read from stream using (MemoryStream memStream = LoadMemoryStreamImage()) { info = new MagickImageInfo(memStream); } // Read from byte array byte[] data = LoadImageBytes(); info = new MagickImageInfo(data); info = new MagickImageInfo(); info.Read(SampleFiles.SnakewarePng); using (MemoryStream memStream = LoadMemoryStreamImage()) { info.Read(memStream); } info.Read(data); Console.WriteLine(info.Width); Console.WriteLine(info.Height); Console.WriteLine(info.ColorSpace); Console.WriteLine(info.Format); Console.WriteLine(info.ResolutionX); Console.WriteLine(info.ResolutionY); }
public void ShouldThrowExceptionWhenDataIsEmpty() { var imageInfo = new MagickImageInfo(); Assert.Throws <ArgumentException>("data", () => imageInfo.Read(Span <byte> .Empty)); }