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() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); List <string> files = new List <string>(new[] { dataDir + "TestDemo.tiff", dataDir + "sample.tiff" }); TiffOptions createOptions = new TiffOptions(TiffExpectedFormat.Default); createOptions.BitsPerSample = new ushort[] { 1 }; createOptions.Orientation = TiffOrientations.TopLeft; createOptions.Photometric = TiffPhotometrics.MinIsBlack; createOptions.Compression = TiffCompressions.CcittFax3; createOptions.FillOrder = TiffFillOrders.Lsb2Msb; // Create a new image by passing the TiffOptions and size of first frame, we will remove the first frame at the end, cause it will be empty TiffImage output = null; try { List <TiffImage> images = new List <TiffImage>(); try { foreach (var file in files) { // Create an instance of TiffImage and load the source image TiffImage input = (TiffImage)Image.Load(file); images.Add(input); // Do not dispose before data is fetched. Data is fetched on 'Save' later. foreach (var frame in input.Frames) { if (output == null) { // Create a new tiff image with first frame defined. output = new TiffImage(TiffFrame.CopyFrame(frame)); } else { // Add copied frame to destination image output.AddFrame(TiffFrame.CopyFrame(frame)); } } } if (output != null) { // Save the result output.Save(dataDir + "ConcatenateTiffImagesHavingSeveralFrames_out.tif", createOptions); } } finally { foreach (TiffImage image in images) { image.Dispose(); } } } catch (Exception ex) { } }
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() { // 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 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() { 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 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: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() { 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 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() { // 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); } }