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() { 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() { // 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() { // 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) { } }
private static Rectangle FixTileSize(TiffImage image, System.Drawing.Point offset, Rectangle tile) { return(Rectangle.FromLTRB( tile.Left, tile.Top, Math.Min(tile.Right, offset.X + image.Width), Math.Min(tile.Bottom, offset.Y + image.Height))); }
public Image GetImage(int pageNum) { try { return(TiffImage.GetTiffImage(ram, pageNum)); } catch (IOException ex) { // System.IO.IOException: Compression JPEG is only supported with a single strip. This image has 30 strips. if (ex.Message.StartsWith("Compression JPEG is only supported with a single strip")) { return(new WindowsBitmapReader(new NoclosePassthru(si)).GetImage(pageNum)); } throw; } catch (ArgumentException ex) { // System.ArgumentException: Extra samples are not supported. if (ex.Message.StartsWith("Extra samples are not supported")) { return(new WindowsBitmapReader(new NoclosePassthru(si)).GetImage(pageNum)); } throw; } }
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 }
//this function is capable of taking multiple tiff images from a directory //and processing each tiff frame by frame private void AddTiff(Document pdfDocument, iTextSharp.text.Rectangle pdfPageSize, String tiffPath) { RandomAccessFileOrArray ra = new RandomAccessFileOrArray(tiffPath); int pageCount = TiffImage.GetNumberOfPages(ra); for (int i = 1; i <= pageCount; i++) { iTextSharp.text.Image img = TiffImage.GetTiffImage(ra, i); if (img.ScaledWidth > pdfPageSize.Width || img.ScaledHeight > pdfPageSize.Height) { img.SetDpi(2, 2); if (img.DpiX != 0 && img.DpiY != 0 && img.DpiX != img.DpiY) { float percentX = (pdfPageSize.Width * 100) / img.ScaledWidth; float percentY = (pdfPageSize.Height * 100) / img.ScaledHeight; img.ScalePercent(percentX, percentY); img.WidthPercentage = 0; } else { img.ScaleToFit(pdfPageSize.Width, pdfPageSize.Height); } } iTextSharp.text.Rectangle pageRect = new iTextSharp.text.Rectangle(0, 0, img.ScaledWidth, img.ScaledHeight); pdfDocument.SetPageSize(pageRect); pdfDocument.SetMargins(0, 0, 0, 0); pdfDocument.NewPage(); pdfDocument.Add(img); } }
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() { // 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() { //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() { // 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() { //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() { // 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 }
// Contructor public SegmentationService(TiffImage image, int N, float threshold) { segmentation = new Dictionary <Segment, Segment>(); this.N = N; this.threshold = threshold; var imageSize = (int)Math.Pow(2, N); pixelMap = new Segment[imageSize, imageSize]; // init pixel map for (var x = 0; x < imageSize; x++) { for (var y = 0; y < imageSize; y++) { var coordinate = new Coordinate { X = x, Y = y }; pixelMap[x, y] = new Pixel(coordinate, image.getColourBands(x, y)); } } // run the whole algorithm GrowUntilNoChange(); }
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."); // 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() { // 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) { } }
private static int TiffPagesCouter(string filename) { var ra = new RandomAccessFileOrArray(filename); var n = TiffImage.GetNumberOfPages(ra); ra.Close(); return(n); }
private static void DrawRows(TiffImage image, System.Drawing.Point offset, Rectangle region, Rectangle tile, Graphics graphics) { while (tile.IntersectsWith(region)) { DrawRow(image, offset, region, tile, graphics); tile = NextTileY(image, offset, tile); } }
protected void Button2_Click(object sender, EventArgs e) { // if (!string.IsNullOrEmpty(TextBox2.Text)) { int index = int.Parse(TextBox2.Text); TiffImage.RemovePage(index, savePathTextbox.Text); } }
protected override void VerifyImageFormat(TiffImage tiff) { base.VerifyImageFormat(tiff); // For use as a height map, the image must be in 16-bit or 32-bit grayscale. // Both scanline and tiled encoding are supported. if (tiff.Metadata.BitsPerSample != 32 && tiff.Metadata.BitsPerSample != 16 || tiff.Metadata.SamplesPerPixel != 1) { throw new FileFormatException("Invalid TIFF format. Only 16-bit and 32-bit grayscale files are supported."); } }
// --------------------------------------------------------------------------- public void AddTif(Document document, String path) { RandomAccessFileOrArray ra = new RandomAccessFileOrArray(path); int n = TiffImage.GetNumberOfPages(ra); Image img; for (int i = 1; i <= n; i++) { img = TiffImage.GetTiffImage(ra, i); img.ScaleToFit(523, 350); document.Add(img); } }
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); } }
internal static PdfReader CreatePdfReaderFromTiff(byte[] sourceBytes, Rectangle pageSize, Margins margins) { using (var document = new Document()) { using (var stream = new MemoryStream()) { using (var writer = PdfWriter.GetInstance(document, stream)) { var ra = new RandomAccessFileOrArray(sourceBytes); int numberOfPages = TiffImage.GetNumberOfPages(ra); for (int i = 1; i <= numberOfPages; i++) { var image = TiffImage.GetTiffImage(ra, i); Rectangle currentPageSize = pageSize == null ? new Rectangle(image.ScaledWidth + margins.Left + margins.Right + 1, image.ScaledHeight + margins.Top + margins.Bottom + 1) : pageSize; document.SetPageSize(currentPageSize); document.SetMargins(margins.Left, margins.Right, margins.Top, margins.Bottom); if (i == 1) { document.Open(); } else { document.NewPage(); } if (pageSize != null) { float width = pageSize.Width - (margins.Left + margins.Right + 1); float height = pageSize.Height - (margins.Top + margins.Bottom + 1); if (width <= 0 || height <= 0) { throw new IOException("Margin is too big."); } image.ScaleToFit(width, height); } document.Add(image); } document.Close(); ra.Close(); } var pdfArray = stream.ToArray(); return(new PdfReader(pdfArray)); } } }
static void Main(string[] args) { using (TiffFile file = new TiffFile("F:\\Downloads\\Public\\VLI\\heic0601a.ptiff")) { TiffImage image = file.Images[5]; using (Bitmap bitmap = image.GetTile(0 * 256, 0 * 256)) bitmap.Save("0.jpg", ImageFormat.Jpeg); using (Bitmap bitmap = image.GetTile(1 * 256, 0 * 256)) bitmap.Save("1.jpg", ImageFormat.Jpeg); using (Bitmap bitmap = image.GetTile(0 * 256, 1 * 256)) bitmap.Save("2.jpg", ImageFormat.Jpeg); using (Bitmap bitmap = image.GetTile(1 * 256, 1 * 256)) bitmap.Save("3.jpg", ImageFormat.Jpeg); } }
public Bitmap Extract(TiffImage image, System.Drawing.Point offset, Rectangle region) { Bitmap regionImage = new Bitmap(region.Width, region.Height); Rectangle tile = new Rectangle( Math.Max(region.X - (region.X - offset.X) % image.TileWidth, offset.X), Math.Max(region.Y - (region.Y - offset.Y) % image.TileWidth, offset.Y), image.TileWidth, image.TileHeight); tile = FixTileSize(image, offset, tile); using (Graphics graphics = Graphics.FromImage(regionImage)) { graphics.Clear(Color.FromArgb(233, 231, 212)); DrawRows(image, offset, region, tile, graphics); } return(regionImage); }
public IEnumerator LoadTifPages(string imagePath, List <Image> tifImages) { Debug.Log("Loading Image As Textures: " + imagePath); TiffImage loadedTiff = new TiffImage(imagePath); yield return(null); Debug.LogFormat("Getting individual tif pages from {0}", imagePath); for (int i = 0; i < loadedTiff.PageCount; i++) { tifImages.Add(loadedTiff.GetTiffSpecificPage(i)); Debug.LogFormat("Loaded page {0} of the tif {1}", i, imagePath); yield return(null); } }
public static void Run() { // ExStart:SplittingTiffFrames // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Create an instance of TiffImage and load the file from disc using (var multiImage = (TiffImage)TiffImage.Load(dataDir + "SampleTiff1.tiff")) { // Initialize a variable to keep track of the frames in the image int i = 0; // Iterate over the tiff frame collection foreach (var tiffFrame in multiImage.Frames) { // Save the frame directly on disc in Jpeg compression tiffFrame.Save(dataDir + i++ + ".tiff", new TiffOptions(TiffExpectedFormat.TiffJpegRgb)); } } // ExEnd:SplittingTiffFrames }
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 ... } } } } }