public static void Run() { // ExStart:CreatingTIFFImageWithCompression // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages() + "SavingRasterImageToTIFFWithCompression_out.tiff"; // Create an instance of TiffOptions and set its various properties TiffOptions options = new TiffOptions(TiffExpectedFormat.Default); options.BitsPerSample = new ushort[] { 8, 8, 8 }; options.Photometric = TiffPhotometrics.Rgb; options.Xresolution = new TiffRational(72); options.Yresolution = new TiffRational(72); options.ResolutionUnit = TiffResolutionUnits.Inch; options.PlanarConfiguration = TiffPlanarConfigs.Contiguous; // Set the Compression to AdobeDeflate options.Compression = TiffCompressions.AdobeDeflate; // Or Deflate // Options.Compression = TiffCompressions.Deflate; // Create a new TiffImage with specific size and TiffOptions settings using (TiffImage tiffImage = new TiffImage(new TiffFrame(options, 100, 100))) { // Loop over the pixels to set the color to red for (int i = 0; i < 100; i++) { tiffImage.ActiveFrame.SetPixel(i, i, Color.Red); } // Save resultant image tiffImage.Save(dataDir); } // ExEnd:CreatingTIFFImageWithCompression }
public static void Run() { // To get proper output please apply a valid Aspose.Imaging License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); // ExStart:ConcatTIFFImages // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Create a copy of original image to avoid any alteration File.Copy(dataDir + "demo.tif", dataDir + "TestDemo.tif", true); // Create an instance of TiffImage and load the copied destination image using (TiffImage image = (TiffImage)Image.Load(dataDir + "TestDemo.tif")) { // Create an instance of TiffImage and load the source image using (TiffImage image1 = (TiffImage)Image.Load(dataDir + "sample.tif")) { // Create an instance of TIffFrame and copy active frame of source image TiffFrame frame = TiffFrame.CopyFrame(image1.ActiveFrame); // Add copied frame to destination image image.AddFrame(frame); // save the image with changes. image.Save(dataDir + "ConcatTIFFImages_out.tiff"); } } // ExEnd:ConcatTIFFImages // Display Status. Console.WriteLine("Concatenation of TIF files done successfully."); }
public static void Run() { // To get proper output please apply a valid Aspose.Imaging License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); // ExStart:SavingRasterImageToTIFFWithCompression // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Create an instance of TiffOptions and set its various properties TiffOptions options = new TiffOptions(TiffExpectedFormat.Default); options.BitsPerSample = new ushort[] { 8, 8, 8 }; options.Photometric = TiffPhotometrics.Rgb; options.Xresolution = new TiffRational(72); options.Yresolution = new TiffRational(72); options.ResolutionUnit = TiffResolutionUnits.Inch; options.PlanarConfiguration = TiffPlanarConfigs.Contiguous; // Set the Compression to AdobeDeflate options.Compression = TiffCompressions.AdobeDeflate; // Or Deflate // Options.Compression = TiffCompressions.Deflate; // Load an existing image in an instance of RasterImage using (RasterImage image = (RasterImage)Image.Load(dataDir + "SampleTiff1.tiff")) { // Create a new TiffImage from the RasterImage using (TiffImage tiffImage = new TiffImage(new TiffFrame(image))) { // Save the resultant image while passing the instance of TiffOptions tiffImage.Save(dataDir + "SavingRasterImage_out.tiff", options); } } // ExEnd:SavingRasterImageToTIFFWithCompression }
public static void Run() { Console.WriteLine("Running example SavingRasterImageToTIFFWithCompression"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Create an instance of TiffOptions and set its various properties TiffOptions options = new TiffOptions(TiffExpectedFormat.Default); options.BitsPerSample = new ushort[] { 8, 8, 8 }; options.Photometric = TiffPhotometrics.Rgb; options.Xresolution = new TiffRational(72); options.Yresolution = new TiffRational(72); options.ResolutionUnit = TiffResolutionUnits.Inch; options.PlanarConfiguration = TiffPlanarConfigs.Contiguous; // Set the Compression to AdobeDeflate options.Compression = TiffCompressions.AdobeDeflate; // Or Deflate // Options.Compression = TiffCompressions.Deflate; // Load an existing image in an instance of RasterImage using (RasterImage image = (RasterImage)Image.Load(dataDir + "SampleTiff1.tiff")) { // Create a new TiffImage from the RasterImage and Save the resultant image while passing the instance of TiffOptions using (TiffImage tiffImage = new TiffImage(new TiffFrame(image))) { tiffImage.Save(dataDir + "SavingRasterImage_out.tiff", options); } } Console.WriteLine("Finished example SavingRasterImageToTIFFWithCompression"); }
public static void Run() { // To get proper output please apply a valid Aspose.Imaging License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Create instances of FileStream and initialize with Tiff images FileStream fileStream = new FileStream(dataDir + "TestDemo.tif", FileMode.Open); FileStream fileStream1 = new FileStream(dataDir + "sample.tif", FileMode.Open); // Create an instance of TiffImage and load the destination image from filestream using (TiffImage image = (TiffImage)Image.Load(fileStream)) { // Create an instance of TiffImage and load the source image from filestream using (TiffImage image1 = (TiffImage)Image.Load(fileStream1)) { // Create an instance of TIffFrame and copy active frame of source image TiffFrame frame = TiffFrame.CopyFrame(image1.ActiveFrame); // Add copied frame to destination image image.AddFrame(frame); } // Save the image with changes image.Save(dataDir + "ConcatenatingTIFFImagesfromStream_out.tif"); // Close the FileStreams fileStream.Close(); fileStream1.Close(); } }
public static void Run() { Console.WriteLine("Running example ConcatenatingTIFFImagesfromStream"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Create instances of FileStream and initialize with Tiff images FileStream fileStream = new FileStream(dataDir + "TestDemo.tif", FileMode.Open); FileStream fileStream1 = new FileStream(dataDir + "sample.tif", FileMode.Open); // Create an instance of TiffImage and load the destination image from filestream using (TiffImage image = (TiffImage)Image.Load(fileStream)) { // Create an instance of TiffImage and load the source image from filestream using (TiffImage image1 = (TiffImage)Image.Load(fileStream1)) { // Create an instance of TIffFrame and copy active frame of source image TiffFrame frame = TiffFrame.CopyFrame(image1.ActiveFrame); // Add copied frame to destination image image.AddFrame(frame); } // Save the image with changes image.Save(dataDir + "ConcatenatingTIFFImagesfromStream_out.tif"); // Close the FileStreams fileStream.Close(); fileStream1.Close(); } Console.WriteLine("Finished example ConcatenatingTIFFImagesfromStream"); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Aspose.Imaging.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //Create a copy of original image to avoid any alteration File.Copy(dataDir + "demo.tif", dataDir + "TestDemo.tif", true); //Create an instance of TiffImage and load the copied destination image using (TiffImage image = (TiffImage)Aspose.Imaging.Image.Load(dataDir + "TestDemo.tif")) { //Create an instance of TiffImage and load the source image using (TiffImage image1 = (TiffImage)Aspose.Imaging.Image.Load(dataDir + "sample.tif")) { // Create an instance of TIffFrame and copy active frame of source image TiffFrame frame = TiffFrame.CopyFrame(image1.ActiveFrame); // Add copied frame to destination image image.AddFrame(frame); // save the image with changes. image.Save(); } } // Display Status. System.Console.WriteLine("Concatenation of TIF files done successfully."); }
public static void Run() { //ExStart:ConcatTIFFImages // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Create a copy of original image to avoid any alteration File.Copy(dataDir + "demo.tif", dataDir + "TestDemo.tif", true); // Create an instance of TiffImage and load the copied destination image using (TiffImage image = (TiffImage)Image.Load(dataDir + "TestDemo.tif")) { // Create an instance of TiffImage and load the source image using (TiffImage image1 = (TiffImage)Image.Load(dataDir + "sample.tif")) { // Create an instance of TIffFrame and copy active frame of source image, Add copied frame to destination image and Save the image with changes. TiffFrame frame = TiffFrame.CopyFrame(image1.ActiveFrame); image.AddFrame(frame); image.Save(dataDir + "ConcatTIFFImages_out.tiff"); } } //ExEnd:ConcatTIFFImages // Display Status. Console.WriteLine("Concatenation of TIF files done successfully."); }
public static void Run() { //ExStart:ExportToMultiPageTiff // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Load a PSD file as an image and cast it into PsdImage using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "layers.psd")) { // Initialize tiff frame list. List <TiffFrame> frames = new List <TiffFrame>(); // Iterate over each layer of PsdImage and convert it to Tiff frame. foreach (var layer in psdImage.Layers) { TiffFrame frame = new TiffFrame(layer, new TiffOptions(FileFormats.Tiff.Enums.TiffExpectedFormat.TiffLzwCmyk)); frames.Add(frame); } // Create a new TiffImage with frames created earlier and save to disk. TiffImage tiffImage = new TiffImage(frames.ToArray()); tiffImage.Save(dataDir + "ExportToMultiPageTiff_output.tif"); } //ExEnd:ExportToMultiPageTiff }
public static void Run() { // To get proper output please apply a valid Aspose.Imaging License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); // ExStart:AlignHorizontalAndVeticalResolutionsOfImage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load an image and convert the image instance to TiffImage using (TiffImage image = (TiffImage)Image.Load(dataDir + "SampleTiff1.tiff")) { // call the align resolution method image.AlignResolutions(); // Save the results to output path. image.Save(dataDir + "AlignHorizontalAndVeticalResolutionsOfImage_out.tiff"); int framesCount = image.Frames.Length; for (int i = 0; i < framesCount; i++) { TiffFrame frame = image.Frames[i]; // All resolutions after aligment must be equal Console.WriteLine("Horizontal and vertical resolutions are equal:" + ((int)frame.VerticalResolution == (int)frame.HorizontalResolution)); } } // ExEnd:AlignHorizontalAndVeticalResolutionsOfImage }
public static void Run() { // ExStart:SavingRasterImageToTIFFWithCompression // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Create an instance of TiffOptions and set its various properties TiffOptions options = new TiffOptions(TiffExpectedFormat.Default); options.BitsPerSample = new ushort[] { 8, 8, 8 }; options.Photometric = TiffPhotometrics.Rgb; options.Xresolution = new TiffRational(72); options.Yresolution = new TiffRational(72); options.ResolutionUnit = TiffResolutionUnits.Inch; options.PlanarConfiguration = TiffPlanarConfigs.Contiguous; // Set the Compression to AdobeDeflate options.Compression = TiffCompressions.AdobeDeflate; // Or Deflate // Options.Compression = TiffCompressions.Deflate; // Load an existing image in an instance of RasterImage using (RasterImage image = (RasterImage)Image.Load(dataDir + "SampleTiff1.tiff")) { // Create a new TiffImage from the RasterImage and Save the resultant image while passing the instance of TiffOptions using (TiffImage tiffImage = new TiffImage(new TiffFrame(image))) { tiffImage.Save(dataDir + "SavingRasterImage_out.tiff", options); } } // ExEnd:SavingRasterImageToTIFFWithCompression }
public static void Run() { Console.WriteLine("Running example AlignHorizontalAndVeticalResolutionsOfImage"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load an image and convert the image instance to TiffImage using (TiffImage image = (TiffImage)Image.Load(dataDir + "SampleTiff1.tiff")) { // Call the align resolution method and Save the results to output path. image.AlignResolutions(); image.Save(dataDir + "AlignHorizontalAndVeticalResolutionsOfImage_out.tiff"); int framesCount = image.Frames.Length; for (int i = 0; i < framesCount; i++) { TiffFrame frame = image.Frames[i]; // All resolutions after aligment must be equal Console.WriteLine( "Horizontal and vertical resolutions are equal:" + ((int)frame.VerticalResolution == (int)frame.HorizontalResolution)); } } Console.WriteLine("Finished example AlignHorizontalAndVeticalResolutionsOfImage"); }
public static void Run() { Console.WriteLine("Running example ExportTiffBatchMode"); string dataDir = RunExamples.GetDataDir_Tiff(); string fileName = "10MB_Tif.tif"; string inputFileName = Path.Combine(dataDir, fileName); string outputFileNameTif = Path.Combine(dataDir, "output.tif"); //The possibility of batch conversion before saving (exporting) Tiff images is implemented. using (TiffImage tiffImage = (TiffImage)Image.Load(inputFileName)) { // Set batch operation for pages tiffImage.PageExportingAction = delegate(int index, Image page) { // Fires garbage collection to avoid unnecessary garbage storage from previous pages GC.Collect(); ((RasterImage)page).Rotate(90); }; tiffImage.Save(outputFileNameTif); /* or export through tiffImage.Save("rotated.tif", new TiffOptions(TIFF_EXPECTED_FORMAT))*/ /* Attention! In batch mode all pages will be released in this line! * If you want to further perform operations on the original image, you should reload it from the source to another instance. */ } Console.WriteLine("Finished example ExportTiffBatchMode"); }
public static void Run() { //ExStart:CreatingTIFFImageWithCompression // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages() + "SavingRasterImageToTIFFWithCompression_out.tiff"; // Create an instance of TiffOptions and set its various properties TiffOptions options = new TiffOptions(TiffExpectedFormat.Default); options.BitsPerSample = new ushort[] { 8, 8, 8 }; options.Photometric = TiffPhotometrics.Rgb; options.Xresolution = new TiffRational(72); options.Yresolution = new TiffRational(72); options.ResolutionUnit = TiffResolutionUnits.Inch; options.PlanarConfiguration = TiffPlanarConfigs.Contiguous; // Set the Compression to AdobeDeflate options.Compression = TiffCompressions.AdobeDeflate; // Or Deflate // Options.Compression = TiffCompressions.Deflate; // Create a new TiffImage with specific size and TiffOptions settings using (TiffImage tiffImage = new TiffImage(new TiffFrame(options, 100, 100))) { // Loop over the pixels to set the color to red for (int i = 0; i < 100; i++) { tiffImage.ActiveFrame.SetPixel(i, i, Color.Red); } // Save resultant image tiffImage.Save(dataDir); } //ExEnd:CreatingTIFFImageWithCompression }
public static void Run() { Console.WriteLine("Running example AddFramesToTIFFImage"); // To get proper output please apply a valid Aspose.Imaging License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); TiffOptions outputSettings = new TiffOptions(TiffExpectedFormat.Default); outputSettings.BitsPerSample = new ushort[] { 1 }; outputSettings.Compression = TiffCompressions.CcittFax3; outputSettings.Photometric = TiffPhotometrics.MinIsWhite; outputSettings.Source = new StreamSource(new MemoryStream()); int newWidth = 500; int newHeight = 500; string path = dataDir + "AddFramesToTIFFImage_out.tif"; using (TiffImage tiffImage = (TiffImage)Image.Create(outputSettings, newWidth, newHeight)) { int index = 0; foreach (var file in Directory.GetFiles(dataDir, "*.jpg")) { using (RasterImage ri = (RasterImage)Image.Load(file)) { ri.Resize(newWidth, newHeight, ResizeType.NearestNeighbourResample); TiffFrame frame = tiffImage.ActiveFrame; if (index > 0) { frame = new TiffFrame(new TiffOptions(outputSettings) /*ensure options are cloned for each frame*/, newWidth, newHeight); // If there is a TIFF image loaded you need to enumerate the frames and perform the following // Frame = TiffFrame.CreateFrameFrom(sourceFrame, outputSettings); } frame.SavePixels(frame.Bounds, ri.LoadPixels(ri.Bounds)); if (index > 0) { tiffImage.AddFrame(frame); } index++; } } tiffImage.Save(path); } Console.WriteLine("Finished example AddFramesToTIFFImage"); }
public static void Run() { //ExStart:MultipleImagesToTIFF // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); //String path = @"C:\Imaging Data\IMG\"; int page = 0; var tempImage = Aspose.Imaging.Image.Load(dataDir + "Image1.png"); int width = 500; int height = 500; width = tempImage.Width; height = tempImage.Height; Aspose.Imaging.ImageOptions.TiffOptions tiffOptions = new Aspose.Imaging.ImageOptions.TiffOptions(TiffExpectedFormat.Default); tiffOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(dataDir + "MultiPage.tiff", false); //Create an instance of Image and initialize it with instance of BmpOptions by calling Create method using (TiffImage TiffImage = (TiffImage)Aspose.Imaging.Image.Create(tiffOptions, width, height)) { //do some image processing DirectoryInfo di = new DirectoryInfo(dataDir); FileInfo[] files = di.GetFiles("*.img"); int index = 0; foreach (var file in files) { using (Aspose.Imaging.Image inputImage = Aspose.Imaging.Image.Load(file.FullName)) { inputImage.Resize(width, height, ResizeType.NearestNeighbourResample); // var frame = TiffImage.ActiveFrame; if (index > 0) { var newframe = new TiffFrame(tiffOptions, width, height); TiffImage.AddFrame(newframe); int cnt = TiffImage.Frames.Count(); } var frame = TiffImage.Frames[index]; frame.SavePixels(frame.Bounds, ((RasterImage)inputImage).LoadPixels(inputImage.Bounds)); index += 1; } } // save all changes TiffImage.Save(dataDir + "output.tiff"); } }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Aspose.Imaging.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); TiffOptions outputSettings = new TiffOptions(); outputSettings.BitsPerSample = new ushort[] { 1 }; outputSettings.Compression = TiffCompressions.CcittFax3; outputSettings.Photometric = TiffPhotometrics.MinIsWhite; outputSettings.Source = new StreamSource(new MemoryStream()); int newWidth = 500; int newHeight = 500; string path = dataDir + "output.tif"; using (TiffImage tiffImage = (TiffImage)Image.Create(outputSettings, newWidth, newHeight)) { int index = 0; foreach (var file in Directory.GetFiles(dataDir, "*.jpg")) { using (RasterImage ri = (RasterImage)Image.Load(file)) { ri.Resize(newWidth, newHeight, ResizeType.NearestNeighbourResample); TiffFrame frame = tiffImage.ActiveFrame; if (index > 0) { frame = new TiffFrame(new TiffOptions(outputSettings) /*ensure options are cloned for each frame*/, newWidth, newHeight); // If there is a TIFF image loaded you need to enumerate the frames and perform the following // frame = TiffFrame.CreateFrameFrom(sourceFrame, outputSettings); } frame.SavePixels(frame.Bounds, ri.LoadPixels(ri.Bounds)); if (index > 0) { tiffImage.AddFrame(frame); } index++; } } tiffImage.Save(path); } }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:TIFFwithAdobeDeflateCompression // Create an instance of TiffOptions and set its various properties TiffOptions options = new TiffOptions(TiffExpectedFormat.Default); options.BitsPerSample = new ushort[] { 8, 8, 8 }; options.Photometric = TiffPhotometrics.Rgb; options.Xresolution = new TiffRational(72); options.Yresolution = new TiffRational(72); options.ResolutionUnit = TiffResolutionUnits.Inch; options.PlanarConfiguration = TiffPlanarConfigs.Contiguous; // Set the Compression to AdobeDeflate options.Compression = TiffCompressions.AdobeDeflate; // Create a new TiffImage with specific size and TiffOptions settings using (TiffImage tiffImage = new TiffImage(new TiffFrame(options, 100, 100))) { // Loop over the pixels to set the color to red for (int j = 0; j < tiffImage.Height; j++) { for (int i = 0; i < tiffImage.Width; i++) { tiffImage.ActiveFrame.SetPixel(i, j, Color.Red); } } // Save resultant image tiffImage.Save(dataDir + "TIFFwithAdobeDeflateCompression_output.tif"); } //ExEnd:TIFFwithAdobeDeflateCompression }
public static void Run() { Console.WriteLine("Running example SupportExtractingPathsFromTiff"); var filePath = Path.GetTempFileName() + ".tif"; var pathResources = new List <PathResource> { new PathResource { BlockId = 2000, Name = "Name", Records = new List <VectorPathRecord>() } }; using (var image = new TiffImage(new TiffFrame(new TiffOptions(TiffExpectedFormat.Default), 10, 10))) { image.ActiveFrame.PathResources = pathResources; image.Save(filePath); } using (var image = (TiffImage)Image.Load(filePath)) { var actual = image.ActiveFrame.PathResources; if (pathResources.Count != actual.Count) { Console.WriteLine("Resources count not equal"); } if (pathResources[0].BlockId != actual[0].BlockId) { Console.WriteLine("BlockId not equal"); } if (!pathResources[0].Name.Equals(actual[0].Name)) { Console.WriteLine("Resource name not equal"); } } File.Delete(filePath); Console.WriteLine("Finished example SupportExtractingPathsFromTiff"); }
///<Summary> /// ConvertImageFormat method to convert image to different image formats ///</Summary> public Response ConvertImageFormat(string fileName, string folderName, string outputType) { if (outputType.Equals("gif") || outputType.Equals("bmp") || outputType.Equals("jpg") || outputType.Equals("png") || outputType.Equals("psd") || outputType.Equals("emf") || outputType.Equals("svg") || outputType.Equals("wmf")) { ImageOptionsBase optionsBase = new BmpOptions(); if (outputType.Equals("jpg")) { optionsBase = new JpegOptions(); } else if (outputType.Equals("png")) { optionsBase = new PngOptions(); } else if (outputType.Equals("gif")) { optionsBase = new GifOptions(); } else if (outputType.Equals("psd")) { optionsBase = new PsdOptions(); } else if (outputType.Equals("emf")) { optionsBase = new EmfOptions(); } else if (outputType.Equals("svg")) { optionsBase = new SvgOptions(); } else if (outputType.Equals("wmf")) { optionsBase = new WmfOptions(); } return(ProcessTask(fileName, folderName, "." + outputType, true, true, delegate(string inFilePath, string outPath, string zipOutFolder) { string fileExtension = Path.GetExtension(inFilePath).ToLower(); if ((fileExtension == ".tif") || (fileExtension == ".tiff")) { string outfileName = Path.GetFileNameWithoutExtension(fileName) + "_{0}"; using (TiffImage multiImage = (TiffImage)Image.Load(inFilePath)) { if (multiImage.Frames.Length > 1) { int frameCounter = 0; // Iterate over the TiffFrames in TiffImage foreach (TiffFrame tiffFrame in multiImage.Frames) { multiImage.ActiveFrame = tiffFrame; // Load Pixels of TiffFrame into an array of Colors Color[] pixels = multiImage.LoadPixels(tiffFrame.Bounds); // Create an instance of JpegOptions // Set the Source of JpegOptions as FileCreateSource by specifying the location where output will be saved // Last boolean parameter denotes isTemporal outPath = zipOutFolder + "/" + outfileName; optionsBase.Source = new FileCreateSource(string.Format(outPath, frameCounter + 1) + "." + outputType, false); // Create a new RasterImage of Jpeg type using (var jpgImage = (RasterImage)Image.Create(optionsBase, tiffFrame.Width, tiffFrame.Height)) { // Save the JpegImage with pixels from TiffFrame jpgImage.SavePixels(tiffFrame.Bounds, pixels); // Resize the Jpeg Image jpgImage.Resize(100, 100, ResizeType.NearestNeighbourResample); // Save the results on disk jpgImage.Save(); } frameCounter++; } } else { multiImage.Save(outPath, optionsBase); } } } else { using (Image image = Image.Load(inFilePath)) { image.Save(outPath, optionsBase); } } })); } return(new Response { FileName = null, Status = "Output type not found", StatusCode = 500 }); }
public static void Run() { // ExStart:ReadAndWriteXMPDataToImages // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Specify the size of image by defining a Rectangle Rectangle rect = new Rectangle(0, 0, 100, 200); TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.TiffJpegRgb); tiffOptions.Photometric = TiffPhotometrics.MinIsBlack; tiffOptions.BitsPerSample = new ushort[] { 8 }; // Create the brand new image just for sample purposes using (var image = new TiffImage(new TiffFrame(tiffOptions, rect.Width, rect.Height))) { // Create an instance of XMP-Header XmpHeaderPi xmpHeader = new XmpHeaderPi(Guid.NewGuid().ToString()); // Create an instance of Xmp-TrailerPi, XMPmeta class to set different attributes XmpTrailerPi xmpTrailer = new XmpTrailerPi(true); XmpMeta xmpMeta = new XmpMeta(); xmpMeta.AddAttribute("Author", "Mr Smith"); xmpMeta.AddAttribute("Description", "The fake metadata value"); // Create an instance of XmpPacketWrapper that contains all metadata XmpPacketWrapper xmpData = new XmpPacketWrapper(xmpHeader,xmpTrailer, xmpMeta); // Create an instacne of Photoshop package and set photoshop attributes PhotoshopPackage photoshopPackage = new PhotoshopPackage(); photoshopPackage.SetCity("London"); photoshopPackage.SetCountry("England"); photoshopPackage.SetColorMode(ColorMode.Rgb); photoshopPackage.SetCreatedDate(DateTime.UtcNow); // Add photoshop package into XMP metadata xmpData.AddPackage(photoshopPackage); // Create an instacne of DublinCore package and set dublinCore attributes DublinCorePackage dublinCorePackage = new DublinCorePackage(); dublinCorePackage.SetAuthor("Charles Bukowski"); dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts"); dublinCorePackage.AddValue("dc:movie", "Barfly"); // Add dublinCore Package into XMP metadata xmpData.AddPackage(dublinCorePackage); using (var ms = new MemoryStream()) { // Update XMP metadata into image and Save image on the disk or in memory stream image.XmpData = xmpData; image.Save(ms); ms.Seek(0, System.IO.SeekOrigin.Begin); // Load the image from moemory stream or from disk to read/get the metadata using (var img = (TiffImage)Image.Load(ms)) { // Getting the XMP metadata XmpPacketWrapper imgXmpData = img.XmpData; foreach (XmpPackage package in imgXmpData.Packages) { // Use package data ... } } } } }
public static void Run() { //ExStart:ReadAndWriteXMPDataToImages // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Specify the size of image by defining a Rectangle Rectangle rect = new Rectangle(0, 0, 100, 200); TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.TiffJpegRgb); tiffOptions.Photometric = TiffPhotometrics.MinIsBlack; tiffOptions.BitsPerSample = new ushort[] { 8 }; // Create the brand new image just for sample purposes using (var image = new TiffImage(new TiffFrame(tiffOptions, rect.Width, rect.Height))) { // Create an instance of XMP-Header XmpHeaderPi xmpHeader = new XmpHeaderPi(Guid.NewGuid().ToString()); // Create an instance of Xmp-TrailerPi, XMPmeta class to set different attributes XmpTrailerPi xmpTrailer = new XmpTrailerPi(true); XmpMeta xmpMeta = new XmpMeta(); xmpMeta.AddAttribute("Author", "Mr Smith"); xmpMeta.AddAttribute("Description", "The fake metadata value"); // Create an instance of XmpPacketWrapper that contains all metadata XmpPacketWrapper xmpData = new XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta); // Create an instacne of Photoshop package and set photoshop attributes PhotoshopPackage photoshopPackage = new PhotoshopPackage(); photoshopPackage.SetCity("London"); photoshopPackage.SetCountry("England"); photoshopPackage.SetColorMode(ColorMode.Rgb); photoshopPackage.SetCreatedDate(DateTime.UtcNow); // Add photoshop package into XMP metadata xmpData.AddPackage(photoshopPackage); // Create an instacne of DublinCore package and set dublinCore attributes DublinCorePackage dublinCorePackage = new DublinCorePackage(); dublinCorePackage.SetAuthor("Charles Bukowski"); dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts"); dublinCorePackage.AddValue("dc:movie", "Barfly"); // Add dublinCore Package into XMP metadata xmpData.AddPackage(dublinCorePackage); using (var ms = new MemoryStream()) { // Update XMP metadata into image and Save image on the disk or in memory stream image.XmpData = xmpData; image.Save(ms); ms.Seek(0, System.IO.SeekOrigin.Begin); // Load the image from moemory stream or from disk to read/get the metadata using (var img = (TiffImage)Image.Load(ms)) { // Getting the XMP metadata XmpPacketWrapper imgXmpData = img.XmpData; foreach (XmpPackage package in imgXmpData.Packages) { // Use package data ... } } } } }