Class TiffImage
Namespace: Aspose.Imaging.FileFormats.Tiff
Assembly: Aspose.Imaging.dll (25.7.0)
Process Tagged Image File Format (TIFF) raster images with our API, offeringcomprehensive support for various resolutions and advanced editing capabilitieslike EXIF data manipulation and alpha channels. Normalize angles for scanned images,resize, transform to grayscale, and apply filters, gamma corrections and imageparameters adjustments with ease. Seamlessly handle multi-frame TIFF files,create graphics paths, add shapes, and effortlessly save images to different formats.
[JsonObject(MemberSerialization.OptIn)]
public class TiffImage : RasterCachedMultipageImage, IDisposable,
IObjectWithBounds, IRasterImageArgb32PixelLoader,
IRasterImageRawDataLoader, IMultipageImageExt, IMultipageImage,
IHasExifData, IHasXmpData, IHasMetadata
{
}
Inheritance
object ← DisposableObject ← DataStreamSupporter ← Image ← RasterImage ← RasterCachedImage ← RasterCachedMultipageImage ← TiffImage
Derived
Implements
IDisposable , IObjectWithBounds , IRasterImageArgb32PixelLoader , IRasterImageRawDataLoader , IMultipageImageExt , IMultipageImage , IHasExifData , IHasXmpData , IHasMetadata
Inherited Members
RasterCachedMultipageImage.AdjustBrightness(int) , RasterCachedMultipageImage.AdjustContrast(float) , RasterCachedMultipageImage.AdjustGamma(float, float, float) , RasterCachedMultipageImage.AdjustGamma(float) , RasterCachedMultipageImage.Blend(Point, RasterImage, Rectangle, byte) , RasterCachedMultipageImage.BinarizeFixed(byte) , RasterCachedMultipageImage.BinarizeBradley(double, int) , RasterCachedMultipageImage.BinarizeBradley(double) , RasterCachedMultipageImage.BinarizeOtsu() , RasterCachedMultipageImage.Crop(Rectangle) , RasterCachedMultipageImage.Crop(int, int, int, int) , RasterCachedMultipageImage.Dither(DitheringMethod, int, IColorPalette) , RasterCachedMultipageImage.Grayscale() , RasterCachedMultipageImage.NormalizeHistogram() , RasterCachedMultipageImage.Rotate(float, bool, Color) , RasterCachedMultipageImage.RotateFlip(RotateFlipType) , RasterCachedMultipageImage.RotateFlipAll(RotateFlipType) , RasterCachedMultipageImage.Resize(int, int, ResizeType) , RasterCachedMultipageImage.Resize(int, int, ImageResizeSettings) , RasterCachedMultipageImage.ResizeWidthProportionally(int, ResizeType) , RasterCachedMultipageImage.ResizeHeightProportionally(int, ResizeType) , RasterCachedMultipageImage.ReplaceColor(int, byte, int) , RasterCachedMultipageImage.ReplaceNonTransparentColors(int) , RasterCachedMultipageImage.Filter(Rectangle, FilterOptionsBase) , RasterCachedMultipageImage.NormalizeAngle(bool, Color) , RasterCachedMultipageImage.CacheData() , RasterCachedMultipageImage.ReleaseManagedResources() , RasterCachedMultipageImage.ResizeMain(int, int, ResizeType) , RasterCachedMultipageImage.RotateFlipMain(RotateFlipType) , RasterCachedMultipageImage.CropMain(int, int, int, int) , RasterCachedMultipageImage.SavePixelsInternalMain(Rectangle, int[]) , RasterCachedMultipageImage.CanDoAdjustments() , RasterCachedMultipageImage.GetPagesAsEnumerable() , RasterCachedMultipageImage.GetSerializedStream(ImageOptionsBase, Rectangle, out int) , RasterCachedMultipageImage.Height , RasterCachedMultipageImage.Width , RasterCachedMultipageImage.BitsPerPixel , RasterCachedMultipageImage.IsCached , RasterCachedMultipageImage.PageCount , RasterCachedMultipageImage.Pages , RasterCachedMultipageImage.HasAlpha , RasterCachedMultipageImage.HasTransparentColor , RasterCachedMultipageImage.ImageOpacity , RasterCachedMultipageImage.BackgroundColor , RasterCachedMultipageImage.XmpData , RasterCachedMultipageImage.PageExportingAction , RasterCachedImage.CacheData() , RasterCachedImage.Blend(Point, RasterImage, Rectangle, byte) , RasterCachedImage.Resize(int, int, ResizeType) , RasterCachedImage.Resize(int, int, ImageResizeSettings) , RasterCachedImage.RotateFlip(RotateFlipType) , RasterCachedImage.Rotate(float, bool, Color) , RasterCachedImage.Crop(Rectangle) , RasterCachedImage.Dither(DitheringMethod, int, IColorPalette) , RasterCachedImage.Grayscale() , RasterCachedImage.NormalizeHistogram() , RasterCachedImage.BinarizeFixed(byte) , RasterCachedImage.BinarizeOtsu() , RasterCachedImage.BinarizeBradley(double, int) , RasterCachedImage.BinarizeBradley(double) , RasterCachedImage.AdjustBrightness(int) , RasterCachedImage.AdjustContrast(float) , RasterCachedImage.AdjustGamma(float, float, float) , RasterCachedImage.AdjustGamma(float) , RasterCachedImage.OnCached() , RasterCachedImage.OnPaletteChanged(IColorPalette, IColorPalette) , RasterCachedImage.IsCached , RasterImage.xmpData , RasterImage.RemoveMetadata() , RasterImage.Save(Stream, ImageOptionsBase, Rectangle) , RasterImage.GetModifyDate(bool) , RasterImage.Dither(DitheringMethod, int) , RasterImage.Dither(DitheringMethod, int, IColorPalette) , RasterImage.GetDefaultPixels(Rectangle, IPartialArgb32PixelLoader) , RasterImage.GetDefaultRawData(Rectangle, IPartialRawDataLoader, RawDataSettings) , RasterImage.GetDefaultArgb32Pixels(Rectangle) , RasterImage.GetDefaultRawData(Rectangle, RawDataSettings) , RasterImage.GetArgb32Pixel(int, int) , RasterImage.GetPixel(int, int) , RasterImage.SetArgb32Pixel(int, int, int) , RasterImage.SetPixel(int, int, Color) , RasterImage.ReadScanLine(int) , RasterImage.ReadArgb32ScanLine(int) , RasterImage.WriteScanLine(int, Color[]) , RasterImage.WriteArgb32ScanLine(int, int[]) , RasterImage.LoadPartialArgb32Pixels(Rectangle, IPartialArgb32PixelLoader) , RasterImage.LoadPartialPixels(Rectangle, IPartialPixelLoader) , RasterImage.LoadArgb32Pixels(Rectangle) , RasterImage.LoadArgb64Pixels(Rectangle) , RasterImage.LoadPartialArgb64Pixels(Rectangle, IPartialArgb64PixelLoader) , RasterImage.LoadPixels(Rectangle) , RasterImage.LoadCmykPixels(Rectangle) , RasterImage.LoadCmyk32Pixels(Rectangle) , RasterImage.LoadRawData(Rectangle, RawDataSettings, IPartialRawDataLoader) , RasterImage.LoadRawData(Rectangle, Rectangle, RawDataSettings, IPartialRawDataLoader) , RasterImage.SaveRawData(byte[], int, Rectangle, RawDataSettings) , RasterImage.SaveArgb32Pixels(Rectangle, int[]) , RasterImage.SavePixels(Rectangle, Color[]) , RasterImage.SaveCmykPixels(Rectangle, CmykColor[]) , RasterImage.SaveCmyk32Pixels(Rectangle, int[]) , RasterImage.SetResolution(double, double) , RasterImage.SetPalette(IColorPalette, bool) , RasterImage.Resize(int, int, ImageResizeSettings) , RasterImage.Rotate(float, bool, Color) , RasterImage.Rotate(float) , RasterImage.BinarizeFixed(byte) , RasterImage.BinarizeOtsu() , RasterImage.BinarizeBradley(double) , RasterImage.BinarizeBradley(double, int) , RasterImage.Blend(Point, RasterImage, Rectangle, byte) , RasterImage.Blend(Point, RasterImage, byte) , RasterImage.Grayscale() , RasterImage.NormalizeHistogram() , RasterImage.AdjustBrightness(int) , RasterImage.AdjustContrast(float) , RasterImage.AdjustGamma(float, float, float) , RasterImage.AdjustGamma(float) , RasterImage.GetSkewAngle() , RasterImage.NormalizeAngle() , RasterImage.NormalizeAngle(bool, Color) , RasterImage.Filter(Rectangle, FilterOptionsBase) , RasterImage.ReplaceColor(Color, byte, Color) , RasterImage.ReplaceColor(int, byte, int) , RasterImage.ReplaceNonTransparentColors(Color) , RasterImage.ReplaceNonTransparentColors(int) , RasterImage.ToBitmap() , RasterImage.ReleaseManagedResources() , RasterImage.UpdateMetadata() , RasterImage.UpdateDimensions(int, int) , RasterImage.PremultiplyComponents , RasterImage.UseRawData , RasterImage.UpdateXmpData , RasterImage.XmpData , RasterImage.RawIndexedColorConverter , RasterImage.RawCustomColorConverter , RasterImage.RawFallbackIndex , RasterImage.RawDataSettings , RasterImage.UsePalette , RasterImage.RawDataFormat , RasterImage.RawLineSize , RasterImage.IsRawDataAvailable , RasterImage.HorizontalResolution , RasterImage.VerticalResolution , RasterImage.HasTransparentColor , RasterImage.HasAlpha , RasterImage.TransparentColor , RasterImage.ImageOpacity , RasterImage.DataLoader , Image.CanLoad(string) , Image.CanLoad(string, LoadOptions) , Image.CanLoad(Stream) , Image.CanLoad(Stream, LoadOptions) , Image.Create(ImageOptionsBase, int, int) , Image.Create(Image[]) , Image.Create(MultipageCreateOptions) , Image.Create(string[], bool) , Image.Create(string[]) , Image.Create(Image[], bool) , Image.GetFileFormat(string) , Image.GetFileFormat(Stream) , Image.GetFittingRectangle(Rectangle, int, int) , Image.GetFittingRectangle(Rectangle, int[], int, int) , Image.Load(string, LoadOptions) , Image.Load(string) , Image.Load(Stream, LoadOptions) , Image.Load(Stream) , Image.GetProportionalWidth(int, int, int) , Image.GetProportionalHeight(int, int, int) , Image.RemoveMetadata() , Image.CanSave(ImageOptionsBase) , Image.Resize(int, int) , Image.Resize(int, int, ResizeType) , Image.Resize(int, int, ImageResizeSettings) , Image.GetDefaultOptions(object[]) , Image.GetOriginalOptions() , Image.ResizeWidthProportionally(int) , Image.ResizeHeightProportionally(int) , Image.ResizeWidthProportionally(int, ResizeType) , Image.ResizeHeightProportionally(int, ResizeType) , Image.ResizeWidthProportionally(int, ImageResizeSettings) , Image.ResizeHeightProportionally(int, ImageResizeSettings) , Image.RotateFlip(RotateFlipType) , Image.Rotate(float) , Image.Crop(Rectangle) , Image.Crop(int, int, int, int) , Image.Save() , Image.Save(string) , Image.Save(string, ImageOptionsBase) , Image.Save(string, ImageOptionsBase, Rectangle) , Image.Save(Stream, ImageOptionsBase) , Image.Save(Stream, ImageOptionsBase, Rectangle) , Image.GetSerializedStream(ImageOptionsBase, Rectangle, out int) , Image.SetPalette(IColorPalette, bool) , Image.UpdateContainer(Image) , Image.GetCanNotSaveMessage(ImageOptionsBase) , Image.GetFitRectangle(Rectangle) , Image.GetImage2Export(ImageOptionsBase, Rectangle, IImageExporter) , Image.GetFitRectangle(Rectangle, int[]) , Image.OnPaletteChanged(IColorPalette, IColorPalette) , Image.OnPaletteChanging(IColorPalette, IColorPalette) , Image.ReleaseManagedResources() , Image.BitsPerPixel , Image.Bounds , Image.Container , Image.Height , Image.Palette , Image.UsePalette , Image.Size , Image.Width , Image.InterruptMonitor , Image.BufferSizeHint , Image.AutoAdjustPalette , Image.HasBackgroundColor , Image.FileFormat , Image.BackgroundColor , DataStreamSupporter.timeout , DataStreamSupporter.CacheData() , DataStreamSupporter.Save() , DataStreamSupporter.Save(Stream) , DataStreamSupporter.Save(string) , DataStreamSupporter.Save(string, bool) , DataStreamSupporter.SaveData(Stream) , DataStreamSupporter.ReleaseManagedResources() , DataStreamSupporter.OnDataStreamContainerChanging(StreamContainer) , DataStreamSupporter.DataStreamContainer , DataStreamSupporter.IsCached , DisposableObject.Dispose() , DisposableObject.ReleaseManagedResources() , DisposableObject.ReleaseUnmanagedResources() , DisposableObject.VerifyNotDisposed() , DisposableObject.Disposed , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Examples
Create Graphics Path from Path Resources in TIFF image.
using (var image as TiffImage = Image.Load("Bottle.tif"))
{
var graphicsPath = PathResourceConverter.ToGraphicsPath(image.ActiveFrame.PathResources.ToArray(), image.ActiveFrame.Size);
var graphics = new Graphics(image);
graphics.DrawPath(new Pen(Color.Red, 10), graphicsPath);
image.Save("BottleWithRedBorder.tif");
}
Create Path Resources using Graphics Path.
static void Main(string[] args)
{
using (var image = (TiffImage)Image.Load("Bottle.tif"))
{
var figure = new Figure();
figure.AddShape(CreateBezierShape(100f, 100f, 500f, 100f, 500f, 1000f, 100f, 1000f));
var graphicsPath = new GraphicsPath();
graphicsPath.AddFigure(figure);
var pathResouze = PathResourceConverter.FromGraphicsPath(graphicsPath, image.Size);
image.ActiveFrame.PathResources = new List<PathResource>(pathResouze);
image.Save("BottleWithRectanglePath.tif");
}
private static BezierShape CreateBezierShape(params float[] coordinates)
{
var bezierPoints = CoordinatesToBezierPoints(coordinates).ToArray();
return new BezierShape(bezierPoints, true);
}
private static IEnumerable<PointF> CoordinatesToBezierPoints(float[] coordinates)
{
for (var coordinateIndex = 0; coordinateIndex < coordinates.Length; coordinateIndex += 2)
for (var index = 0; index < 3; index++)
yield return new PointF(coordinates[coordinateIndex], coordinates[coordinateIndex + 1]);
}
Constructors
TiffImage(TiffFrame)
Initialize a new object of the Aspose.Imaging.FileFormats.Tiff.TiffImage class, specifying theframe parameter. This constructor facilitates the creation of a TiffImageinstance, allowing developers to specify the frame to be loaded or processed,streamlining Tiff image handling tasks within their applications.
public TiffImage(TiffFrame frame)
{
}
Parameters
frame
TiffFrame
The tiff frame to initialize image with.
Examples
This example shows how to create a TIFF image from scratch and save it to a file.
string dir = "c:\\temp\\";
Aspose.Imaging.ImageOptions.TiffOptions createOptions = new Aspose.Imaging.ImageOptions.TiffOptions(Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
createOptions.BitsPerSample = new ushort[] { 8, 8, 8 };
createOptions.ByteOrder = Aspose.Imaging.FileFormats.Tiff.Enums.TiffByteOrder.BigEndian;
createOptions.Compression = Aspose.Imaging.FileFormats.Tiff.Enums.TiffCompressions.Lzw;
createOptions.Photometric = Aspose.Imaging.FileFormats.Tiff.Enums.TiffPhotometrics.Rgb;
createOptions.PlanarConfiguration = Aspose.Imaging.FileFormats.Tiff.Enums.TiffPlanarConfigs.Contiguous;
Aspose.Imaging.FileFormats.Tiff.TiffFrame firstFrame = new Aspose.Imaging.FileFormats.Tiff.TiffFrame(createOptions, 100, 100);
Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
new Aspose.Imaging.Point(0, 0),
new Aspose.Imaging.Point(firstFrame.Width, firstFrame.Height),
Aspose.Imaging.Color.Blue,
Aspose.Imaging.Color.Yellow);
Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(firstFrame);
graphics.FillRectangle(gradientBrush, firstFrame.Bounds);
using (Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = new Aspose.Imaging.FileFormats.Tiff.TiffImage(firstFrame))
{
tiffImage.Save(dir + "output.tif");
}
Exceptions
Tiff frame’ cannot be empty.
TiffImage(TiffFrame[])
Create a new instance of the Aspose.Imaging.FileFormats.Tiff.TiffImage class, providing a list offrames as a parameter. This constructor enables the initialization of a TiffImageobject with multiple frames, facilitating efficient handling and processing ofTIFF image sequences within software applications.
public TiffImage(TiffFrame[] frames)
{
}
Parameters
frames
TiffFrame
[]
The frames.
Examples
This example shows how to create a TIFF image with 2 frames and save it to a file.
string dir = "c:\\temp\\";
Aspose.Imaging.ImageOptions.TiffOptions createOptions1 = new Aspose.Imaging.ImageOptions.TiffOptions(Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
createOptions1.BitsPerSample = new ushort[] { 8, 8, 8 };
createOptions1.ByteOrder = Aspose.Imaging.FileFormats.Tiff.Enums.TiffByteOrder.BigEndian;
createOptions1.Compression = Aspose.Imaging.FileFormats.Tiff.Enums.TiffCompressions.Lzw;
createOptions1.Photometric = Aspose.Imaging.FileFormats.Tiff.Enums.TiffPhotometrics.Rgb;
createOptions1.PlanarConfiguration = Aspose.Imaging.FileFormats.Tiff.Enums.TiffPlanarConfigs.Contiguous;
Aspose.Imaging.FileFormats.Tiff.TiffFrame frame1 = new Aspose.Imaging.FileFormats.Tiff.TiffFrame(createOptions1, 100, 100);
Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
new Aspose.Imaging.Point(0, 0),
new Aspose.Imaging.Point(frame1.Width, frame1.Height),
Aspose.Imaging.Color.Blue,
Aspose.Imaging.Color.Yellow);
Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(frame1);
graphics.FillRectangle(gradientBrush, frame1.Bounds);
Aspose.Imaging.ImageOptions.TiffOptions createOptions2 = new Aspose.Imaging.ImageOptions.TiffOptions(Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
createOptions2.BitsPerSample = new ushort[] { 1 };
createOptions2.ByteOrder = Aspose.Imaging.FileFormats.Tiff.Enums.TiffByteOrder.LittleEndian;
createOptions2.Compression = Aspose.Imaging.FileFormats.Tiff.Enums.TiffCompressions.CcittFax3;
createOptions2.Photometric = Aspose.Imaging.FileFormats.Tiff.Enums.TiffPhotometrics.MinIsBlack;
Aspose.Imaging.FileFormats.Tiff.TiffFrame frame2 = new Aspose.Imaging.FileFormats.Tiff.TiffFrame(createOptions2, 200, 200);
Aspose.Imaging.Graphics graphics2 = new Aspose.Imaging.Graphics(frame2);
graphics2.FillRectangle(gradientBrush, frame2.Bounds);
using (Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = new Aspose.Imaging.FileFormats.Tiff.TiffImage(new Aspose.Imaging.FileFormats.Tiff.TiffFrame[] { frame1, frame2 }))
{
tiffImage.Save(dir + "output.multiframe.tif");
}
Exceptions
frames
Properties
ActiveFrame
Manage the active frame seamlessly, facilitating dynamic navigation andmanipulation within the designated context. Empower your application to interactefficiently with multimedia content, enhancing user engagement and productivity.
public TiffFrame ActiveFrame
{
get;
set;
}
Property Value
Examples
The following example shows how to compose a mutlipage TIFF from individual raster images.
Aspose.Imaging.ImageOptions.TiffOptions createTiffOptions = new Aspose.Imaging.ImageOptions.TiffOptions(Aspose.Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
createTiffOptions.Source = new Aspose.Imaging.Sources.FileCreateSource("c:\\temp\\multipage.tif", false);
createTiffOptions.Photometric = Aspose.Imaging.FileFormats.Tiff.Enums.TiffPhotometrics.Rgb;
createTiffOptions.BitsPerSample = new ushort[] { 8, 8, 8 };
using (Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Image.Create(createTiffOptions, 100, 100))
{
Aspose.Imaging.Font font = new Aspose.Imaging.Font("Arial", 64);
Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.White);
for (int i = 1; i <= 5; i++)
{
Aspose.Imaging.ImageOptions.PngOptions createPngOptions = new Aspose.Imaging.ImageOptions.PngOptions();
createPngOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream());
Aspose.Imaging.FileFormats.Png.PngImage pngImage = (Aspose.Imaging.FileFormats.Png.PngImage)Image.Create(createPngOptions, 100, 100);
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(pngImage);
gr.DrawString(i.ToString(), font, brush, 10, 10);
Aspose.Imaging.FileFormats.Tiff.TiffFrame frame = new Aspose.Imaging.FileFormats.Tiff.TiffFrame(pngImage);
tiffImage.AddFrame(frame);
}
Aspose.Imaging.FileFormats.Tiff.TiffFrame activeFrame = tiffImage.ActiveFrame;
tiffImage.ActiveFrame = tiffImage.Frames[1];
tiffImage.RemoveFrame(0);
activeFrame.Dispose();
tiffImage.Save();
}
ByteOrder
Toggle the byte order for TIFF files seamlessly, ensuring precise control overdata interpretation. Empower your applications with the flexibility to adapt todiverse file specifications, enhancing compatibility and efficiency in data processing.
public TiffByteOrder ByteOrder
{
get;
set;
}
Property Value
ExifData
Access or modify EXIF data associated with the active frame seamlessly, empoweringprecise control over image metadata. Enhance your application’s capabilities byintegrating this feature, ensuring accurate preservation and customization ofessential image information.
public ExifData ExifData
{
get;
set;
}
Property Value
FileFormat
Retrieve the file format value associated with the image. This property serves asa critical aspect of image metadata retrieval, allowing software applications toidentify and interpret the format of the image data efficiently.
public override FileFormat
Get
{
get
{
}
}
Property Value
Frames
Retrieve an array of Aspose.Imaging.FileFormats.Tiff.TiffFrame instances, enabling comprehensiveaccess and manipulation of individual frames within the TIFF image. Harness thepower of this array to streamline image processing workflows, ensuring precisecontrol and optimization of visual content.
public TiffFrame[] Frames
{
get;
}
Property Value
TiffFrame []
Examples
The following example shows how to compose a mutlipage TIFF from individual raster images.
Aspose.Imaging.ImageOptions.TiffOptions createTiffOptions = new Aspose.Imaging.ImageOptions.TiffOptions(Aspose.Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
createTiffOptions.Source = new Aspose.Imaging.Sources.FileCreateSource("c:\\temp\\multipage.tif", false);
createTiffOptions.Photometric = Aspose.Imaging.FileFormats.Tiff.Enums.TiffPhotometrics.Rgb;
createTiffOptions.BitsPerSample = new ushort[] { 8, 8, 8 };
using (Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Image.Create(createTiffOptions, 100, 100))
{
Aspose.Imaging.Font font = new Aspose.Imaging.Font("Arial", 64);
Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.White);
for (int i = 1; i <= 5; i++)
{
Aspose.Imaging.ImageOptions.PngOptions createPngOptions = new Aspose.Imaging.ImageOptions.PngOptions();
createPngOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream());
Aspose.Imaging.FileFormats.Png.PngImage pngImage = (Aspose.Imaging.FileFormats.Png.PngImage)Image.Create(createPngOptions, 100, 100);
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(pngImage);
gr.DrawString(i.ToString(), font, brush, 10, 10);
Aspose.Imaging.FileFormats.Tiff.TiffFrame frame = new Aspose.Imaging.FileFormats.Tiff.TiffFrame(pngImage);
tiffImage.AddFrame(frame);
}
Aspose.Imaging.FileFormats.Tiff.TiffFrame activeFrame = tiffImage.ActiveFrame;
tiffImage.ActiveFrame = tiffImage.Frames[1];
tiffImage.RemoveFrame(0);
activeFrame.Dispose();
tiffImage.Save();
}
HasAlpha
Determine whether the image has an alpha channel, providing crucial informationfor rendering and compositing operations. Integrate this feature to optimizevisual processing workflows, ensuring accurate representation and manipulation oftransparent elements.
public override bool HasAlpha
{
get;
}
Property Value
Examples
The following example loads a TIFF image and prints information about raw data format and alpha channel.
string dir = "c:\\temp\\";
string fileName = dir + "sample.tif";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(fileName))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
System.Console.WriteLine("ImageFile={0}, FileFormat={1}, HasAlpha={2}", fileName, tiffImage.RawDataFormat, tiffImage.HasAlpha);
int i = 0;
foreach (Aspose.Imaging.FileFormats.Tiff.TiffFrame frame in tiffImage.Frames)
{
System.Console.WriteLine("Frame={0}, FileFormat={1}, HasAlpha={2}", ++i, frame.RawDataFormat, frame.HasAlpha);
}
}
HorizontalResolution
Retrieve the horizontal resolution of the specified Aspose.Imaging.Image in pixelsper inch, facilitating precise adjustment and rendering capabilities. Accessessential image metadata effortlessly, empowering streamlined image processingworkflows for enhanced user experiences.
public override double HorizontalResolution
{
get;
set;
}
Property Value
Examples
The following example shows how to set horizontal/vertical resolution of a TIFF image.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
double horizontalResolution = tiffImage.HorizontalResolution;
double verticalResolution = tiffImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", horizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", verticalResolution);
if (horizontalResolution != 96.0 || verticalResolution != 96.0)
{
System.Console.WriteLine("Set resolution values to 96 dpi");
tiffImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", tiffImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", tiffImage.VerticalResolution);
}
}
Remarks
Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.
PageCount
Retrieve the total count of pages within the specified document, facilitatingefficient navigation and management of multi-page content. Incorporate thisfunctionality to enhance user experience, enabling seamless access tocomprehensive document structures.
public override int PageCount
{
get;
}
Property Value
Pages
Access the pages of the document seamlessly, enabling dynamic navigation andmanipulation within the content structure. Empower your application with efficientaccess to individual pages, facilitating streamlined document processing andenhanced user interaction.
public override Image[] Pages
{
get;
}
Property Value
Image []
PremultiplyComponents
Indicate if components necessitate premultiplication, ensuring efficient handlingof visual elements. Enhance rendering processes by toggling this property,streamlining graphic workflows for optimized performance.
public override bool PremultiplyComponents
{
get;
set;
}
Property Value
Examples
The following example creates a new TIFF image, saves the specified semi-transparent pixels, then loads those pixels and gets final colors in the premultiplied form.
int imageWidth = 3;
int imageHeight = 2;
Aspose.Imaging.Color[] colors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.FromArgb(127, 255, 0, 0),
Aspose.Imaging.Color.FromArgb(127, 0, 255, 0),
Aspose.Imaging.Color.FromArgb(127, 0, 0, 255),
Aspose.Imaging.Color.FromArgb(127, 255, 255, 0),
Aspose.Imaging.Color.FromArgb(127, 255, 0, 255),
Aspose.Imaging.Color.FromArgb(127, 0, 255, 255),
};
Aspose.Imaging.ImageOptions.TiffOptions createOptions = new Aspose.Imaging.ImageOptions.TiffOptions(Aspose.Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.TiffDeflateRgba);
createOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream(), true);
using (Aspose.Imaging.FileFormats.Tiff.TiffImage image = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Aspose.Imaging.Image.Create(createOptions, imageWidth, imageHeight))
{
image.SavePixels(image.Bounds, colors);
image.PremultiplyComponents = true;
Aspose.Imaging.Color[] premultipliedColors = image.LoadPixels(image.Bounds);
for (int i = 0; i < colors.Length; i++)
{
System.Console.WriteLine("Original color: {0}", colors[i].ToString());
System.Console.WriteLine("Premultiplied color: {0}", premultipliedColors[i].ToString());
}
}
VerticalResolution
Access the vertical resolution of the designated Aspose.Imaging.Image in pixels perinch, enabling precise adjustments and rendering optimizations. Utilize essentialimage data effortlessly to streamline image processing workflows, ensuringsuperior quality and performance in your applications.
public override double VerticalResolution
{
get;
set;
}
Property Value
Examples
The following example shows how to set horizontal/vertical resolution of a TIFF image.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
double horizontalResolution = tiffImage.HorizontalResolution;
double verticalResolution = tiffImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", horizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", verticalResolution);
if (horizontalResolution != 96.0 || verticalResolution != 96.0)
{
System.Console.WriteLine("Set resolution values to 96 dpi");
tiffImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", tiffImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", tiffImage.VerticalResolution);
}
}
Remarks
Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.
Methods
Add(TiffImage)
Add the frames from the specified image seamlessly into the current frame,consolidating their content and enhancing compositional flexibility. Integratethis method to streamline frame management and manipulation within yourapplication, facilitating efficient handling of multi-frame images.
public void Add(TiffImage image)
{
}
Parameters
image
TiffImage
The source image.
AddFrame(TiffFrame)
Incorporate the specified frame seamlessly into the image, expanding its contentand versatility. Utilize this method to enhance image composition and management,empowering efficient handling of multi-frame images within your application.
public void AddFrame(TiffFrame frame)
{
}
Parameters
frame
TiffFrame
The frame to add.
Examples
The following example shows how to compose a mutlipage TIFF from individual raster images.
Aspose.Imaging.ImageOptions.TiffOptions createTiffOptions = new Aspose.Imaging.ImageOptions.TiffOptions(Aspose.Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
createTiffOptions.Source = new Aspose.Imaging.Sources.FileCreateSource("c:\\temp\\multipage.tif", false);
createTiffOptions.Photometric = Aspose.Imaging.FileFormats.Tiff.Enums.TiffPhotometrics.Rgb;
createTiffOptions.BitsPerSample = new ushort[] { 8, 8, 8 };
using (Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Image.Create(createTiffOptions, 100, 100))
{
Aspose.Imaging.Font font = new Aspose.Imaging.Font("Arial", 64);
Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.White);
for (int i = 1; i <= 5; i++)
{
Aspose.Imaging.ImageOptions.PngOptions createPngOptions = new Aspose.Imaging.ImageOptions.PngOptions();
createPngOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream());
Aspose.Imaging.FileFormats.Png.PngImage pngImage = (Aspose.Imaging.FileFormats.Png.PngImage)Image.Create(createPngOptions, 100, 100);
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(pngImage);
gr.DrawString(i.ToString(), font, brush, 10, 10);
Aspose.Imaging.FileFormats.Tiff.TiffFrame frame = new Aspose.Imaging.FileFormats.Tiff.TiffFrame(pngImage);
tiffImage.AddFrame(frame);
}
Aspose.Imaging.FileFormats.Tiff.TiffFrame activeFrame = tiffImage.ActiveFrame;
tiffImage.ActiveFrame = tiffImage.Frames[1];
tiffImage.RemoveFrame(0);
activeFrame.Dispose();
tiffImage.Save();
}
AddFrames(TiffFrame[])
Integrate the array of frames seamlessly into the image, enriching its content andversatility. Utilize this method to enhance image composition and management,enabling efficient handling of multi-frame images within your application.
public void AddFrames(TiffFrame[] frames)
{
}
Parameters
frames
TiffFrame
[]
The frames array to add
AddPage(RasterImage)
Incorporate a new page into the existing image seamlessly, expanding its contentand versatility. Utilize this method to enhance document composition andmanagement, empowering efficient handling of multi-page images within your application.
public virtual void AddPage(RasterImage page)
{
}
Parameters
page
RasterImage
The page to add.
Exceptions
page’ is null.
AdjustBrightness(int)
Implement brightness’ adjustment for the image, allowing themodification of overall luminance levels. Incorporate this method into your imageprocessing workflow to enhance visibility and improve the visual quality ofimages within your application.
public override void AdjustBrightness(int brightness)
{
}
Parameters
brightness
int
Brightness value.
Examples
The following example performs brightness correction of a TIFF image.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
var tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.AdjustBrightness(50);
tiffImage.Save(dir + "sample.AdjustBrightness.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
AdjustContrast(float)
Enhance the contrast of the Aspose.Imaging.Image instance,amplifying the differences between its light and dark areas. Integrate thisfunctionality to improve the visual clarity and overall quality of the imagewithin your application.
public override void AdjustContrast(float contrast)
{
}
Parameters
contrast
float
Contrast value (in range [-100; 100])
Examples
The following example performs contrast correction of a TIFF image.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
var tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.AdjustContrast(50f);
tiffImage.Save(dir + "sample.AdjustContrast.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
AdjustGamma(float)
Apply gamma correction to the image, adjusting pixel intensities to achievedesired color balance. Incorporate this method into your image processingworkflow to enhance visual quality and improve the accuracy of subsequentanalysis or display tasks within your application.
public override void AdjustGamma(float gamma)
{
}
Parameters
gamma
float
Gamma for red, green and blue channels coefficient
Examples
The following example performs gamma-correction of a TIFF image.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.AdjustGamma(2.5f);
tiffImage.Save(dir + "sample.AdjustGamma.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
AdjustGamma(float, float, float)
Perform gamma correction on the image using individual coefficients for red,green, and blue channels, allowing for fine-tuned adjustments of color balanceand contrast. Integrate this method into your image processing pipeline toachieve precise control over color rendering and enhance visual fidelity withinyour application.
public override void
AdjustGamma(
float gammaRed,
float gammaGreen,
float gammaBlue
)
Parameters
gammaRed
float
Gamma for red channel coefficient
gammaGreen
float
Gamma for green channel coefficient
gammaBlue
float
Gamma for blue channel coefficient
Examples
The following example performs gamma-correction of a TIFF image applying different coefficients for color components.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
var tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.AdjustGamma(1.5f, 2.5f, 3.5f);
tiffImage.Save(dir + "sample.AdjustGamma.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
AlignResolutions()
Implement the AlignResolutions helper method to synchronize horizontal andvertical resolutions, ensuring uniformity in image dimensions. This functionalityfacilitates streamlined image processing workflows by harmonizing resolutionparameters, optimizing visual quality and consistency across various platforms anddevices.
public void AlignResolutions()
{
}
BinarizeBradley(double, int)
Implement binarization on the image employing Bradley’s adaptive thresholdingalgorithm with integral image thresholding. This approach dynamically computeslocal thresholds based on the image’s neighborhood, enhancing adaptability tovarying lighting conditions and ensuring robust segmentation for subsequentprocessing tasks within your application.
public override void BinarizeBradley(double brightnessDifference, int windowSize)
{
}
Parameters
brightnessDifference
double
The brightness difference between pixel and the average of an s x s window of pixelscentered around this pixel.
windowSize
int
The size of s x s window of pixels centered around this pixel
Examples
The following example binarizes a TIFF image with Bradley’s adaptive thresholding algorithm with the specified window size. Binarized images contain only 2 colors - black and white.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.BinarizeBradley(5, 10);
tiffImage.Save(dir + "sample.BinarizeBradley5_10x10.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
BinarizeFixed(byte)
Apply binarization to the image using a predefined threshold, converting it intoa binary image with distinct foreground and background regions. Incorporate thismethod into your image processing workflow to facilitate segmentation and featureextraction tasks, enhancing the accuracy and efficiency of image analysis withinyour application.
public override void BinarizeFixed(byte threshold)
{
}
Parameters
threshold
byte
Threshold value. If corresponding gray value of a pixel is greater than threshold, a value of255 will be assigned to it, 0 otherwise.
Examples
The following example binarizes a TIFF image with the predefined threshold. Binarized images contain only 2 colors - black and white.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
var tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.BinarizeFixed(127);
tiffImage.Save(dir + "sample.BinarizeFixed.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
BinarizeOtsu()
Utilize Otsu thresholding to perform binarization on the image, automaticallydetermining the optimal threshold value based on the image’s histogram. Integratethis method into your image processing workflow to achieve effective segmentationand feature extraction, enhancing the accuracy and reliability of image analysistasks within your application.
public override void BinarizeOtsu()
{
}
Examples
The following example binarizes a TIFF image with Otsu thresholding. Binarized images contain only 2 colors - black and white.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.BinarizeOtsu();
tiffImage.Save(dir + "sample.BinarizeOtsu.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
Crop(Rectangle)
Crop the image using a specified rectangular region, allowing precise selection ofdesired content. Integrate this method into your image processing workflow toefficiently remove unwanted areas and focus on essential details, enhancing theoverall clarity and composition of the image.
public override void Crop(Rectangle rectangle)
{
}
Parameters
rectangle
Rectangle
The rectangle.
Examples
The following example crops a TIFF image. The cropping area is be specified via Aspose.Imaging.Rectangle.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
var tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
var area = new Aspose.Imaging.Rectangle(tiffImage.Width / 4, tiffImage.Height / 4, tiffImage.Width / 2, tiffImage.Height / 2);
tiffImage.Crop(area);
tiffImage.Save(dir + "sample.Crop.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
Crop(int, int, int, int)
Perform cropping on the image by specifying shifts in the left, right, top, andbottom directions. This method enables precise selection of the desired portion ofthe image, facilitating efficient removal of unwanted areas and focusing onessential content. Integrate this functionality into your image processingpipeline to enhance clarity and composition as needed within your application.
public override void Crop(
int leftShift,
int rightShift,
int topShift,
int bottomShift
)
Note that I have added a single space after the method opening brace (`{`) and before each following line. This is consistent with most coding standards in C#. Also, each argument is now on a new line for better readability.
Parameters
leftShift
int
The left shift.
rightShift
int
The right shift.
topShift
int
The top shift.
bottomShift
int
The bottom shift.
Examples
The following example crops a TIFF image. The cropping area is specified via Left, Top, Right, Bottom margins.
string dir = @"c:\temp\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
int horizontalMargin = tiffImage.Width / 10;
int verticalMargin = tiffImage.Height / 10;
tiffImage.Crop(horizontalMargin, horizontalMargin, verticalMargin, verticalMargin);
tiffImage.Save(dir + "sample.Crop.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
Dither(DitheringMethod, int, IColorPalette)
Execute dithering on the current image to enhance its visual quality and reducecolor banding artifacts. Integrate this method into your image processing workflowto ensure smoother transitions between colors, resulting in improved overall imageappearance and clarity.
public override void
Dither(
DitheringMethod ditheringMethod,
int bitsCount,
IColorPalette customPalette)
{
}
Parameters
ditheringMethod
DitheringMethod
The dithering method.
bitsCount
int
The final bits count for dithering.
customPalette
IColorPalette
The custom palette for dithering.
Examples
The following example loads a TIFF image and performs threshold and floyd dithering using different palette depth.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.Dither(Aspose.Imaging.DitheringMethod.ThresholdDithering, 4, null);
tiffImage.Save(dir + "sample.ThresholdDithering4.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.Dither(Aspose.Imaging.DitheringMethod.FloydSteinbergDithering, 1, null);
tiffImage.Save(dir + "sample.FloydSteinbergDithering1.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
Filter(Rectangle, FilterOptionsBase)
Filter the content within the specified rectangle, applying a designated imageprocessing filter to enhance or modify the selected region. Integrate this methodinto your image manipulation workflow to achieve targeted enhancements ortransformations within your application.
public override void
Filter(
Rectangle rectangle,
FilterOptionsBase options)
{
}
Parameters
rectangle
Rectangle
The rectangle.
options
FilterOptionsBase
The options.
Examples
The following example applies various types of filters to a TIFF image.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.Filter(tiffImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.MedianFilterOptions(5));
tiffImage.Save(dir + "sample.MedianFilter.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.Filter(tiffImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.BilateralSmoothingFilterOptions(5));
tiffImage.Save(dir + "sample.BilateralSmoothingFilter.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.Filter(tiffImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.GaussianBlurFilterOptions(5, 4.0));
tiffImage.Save(dir + "sample.GaussianBlurFilter.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.Filter(tiffImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.GaussWienerFilterOptions(5, 4.0));
tiffImage.Save(dir + "sample.GaussWienerFilter.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.Filter(tiffImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.MotionWienerFilterOptions(10, 1.0, 90.0));
tiffImage.Save(dir + "sample.MotionWienerFilter.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.Filter(tiffImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.SharpenFilterOptions(5, 4.0));
tiffImage.Save(dir + "sample.SharpenFilter.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
GetOriginalOptions()
Retrieve options derived from the original file settings, facilitating seamlesspreservation of key parameters such as bit-depth and other essential attributes ofthe original image. Utilize this method to maintain fidelity and consistency inimage processing tasks, ensuring optimal results without unnecessary alterations.For example, if we load a black-white PNG image with 1 bit per pixel and then save it using theAspose.Imaging.DataStreamSupporter.Save(System.String) method, the output PNG image with 8-bit per pixel will be produced.To avoid it and save PNG image with 1-bit per pixel, use this method to get corresponding saving options and pass themto the Aspose.Imaging.Image.Save(System.String,Aspose.Imaging.ImageOptionsBase) method as the second parameter.
public override ImageOptionsBase GetOriginalOptions()
{
}
Returns
The options based on the original file settings.
Exceptions
There is no original options that can be extracted from image
Grayscale()
Convert the image to its grayscale representation, transforming it into asingle-channel image where each pixel represents intensity. Integrate this methodinto your image processing pipeline to simplify analysis and enhancecompatibility with grayscale-based algorithms, facilitating various computervision and image analysis tasks within your application.
public override void Grayscale()
{
}
Examples
The following example transforms a colored TIFF image to its grayscale representation. Grayscale images are composed exclusively of shades of gray and carry only intensity information.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
var tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.Grayscale();
tiffImage.Save(dir + "sample.Grayscale.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
InsertFrame(int, TiffFrame)
Insert the new frame at the specified index within the frame sequence, ensuringprecise control over frame arrangement. Employ this method to manage framesequences effectively, facilitating dynamic manipulation and organization of imagecontent within your application.
public void InsertFrame(int index, TiffFrame frameToInsert)
{
}
In this case, since the input code already follows standard C# conventions for indentation, spacing, and general readability, no changes were needed.
Parameters
index
int
Index of new frame in list of frames
frameToInsert
TiffFrame
The frame To Insert.
NormalizeAngle(bool, Color)
Utilize the NormalizeAngle method specifically designed for scanned text documentsto rectify skewed scans, ensuring accurate alignment. Seamlesslyintegrate this functionality into your text processing workflows to enhancedocument readability and quality, improving overall efficiency in text recognitionand analysis tasks.This method uses Aspose.Imaging.RasterImage.GetSkewAngle and Aspose.Imaging.FileFormats.Tiff.TiffImage.Rotate(System.Single,System.Boolean,Aspose.Imaging.Color) methods.
public override void NormalizeAngle(
bool resizeProportionally,
Color backgroundColor
)
Note that I have added a space after the opening and closing parentheses for proper spacing. Also, each parameter has been placed on its own line for improved readability. Additionally, indentation has been properly structured according to C# conventions.
Parameters
resizeProportionally
bool
if set to ’true’ you will have your image size changed according to rotated rectangle (corner points) projections in other case that leaves dimensions untouched and only internal image contents are rotated.
backgroundColor
Color
Color of the background.
ReleaseManagedResources()
Releases the managed resources. Make sure no unmanaged resources are released here, since they may have been already released.
protected override void ReleaseManagedResources()
{
}
RemoveFrame(int)
Effortlessly eliminate the frame identified by its index from the image sequence,streamlining frame management within your application. Integrate thisfunctionality to enhance efficiency and precision in frame manipulation,facilitating seamless organization and presentation of image content.
public TiffFrame RemoveFrame(int index)
{
if (Frames == null || index < 0 || index >= Frames.Count)
throw new ArgumentOutOfRangeException(nameof(index), "Index is out of range.");
var frameToRemove = Frames[index];
Frames.RemoveAt(index);
return frameToRemove;
}
Parameters
index
int
Index of frame to be removed.
Returns
The removed frame.
Examples
The following example shows how to compose a mutlipage TIFF from individual raster images.
Aspose.Imaging.ImageOptions.TiffOptions createTiffOptions = new Aspose.Imaging.ImageOptions.TiffOptions(Aspose.Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
createTiffOptions.Source = new Aspose.Imaging.Sources.FileCreateSource("c:\\temp\\multipage.tif", false);
createTiffOptions.Photometric = Aspose.Imaging.FileFormats.Tiff.Enums.TiffPhotometrics.Rgb;
createTiffOptions.BitsPerSample = new ushort[] { 8, 8, 8 };
using (Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Image.Create(createTiffOptions, 100, 100))
{
Aspose.Imaging.Font font = new Aspose.Imaging.Font("Arial", 64);
Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.White);
for (int i = 1; i <= 5; i++)
{
Aspose.Imaging.ImageOptions.PngOptions createPngOptions = new Aspose.Imaging.ImageOptions.PngOptions();
createPngOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream());
Aspose.Imaging.FileFormats.Png.PngImage pngImage = (Aspose.Imaging.FileFormats.Png.PngImage)Image.Create(createPngOptions, 100, 100);
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(pngImage);
gr.DrawString(i.ToString(), font, brush, 10, 10);
Aspose.Imaging.FileFormats.Tiff.TiffFrame frame = new Aspose.Imaging.FileFormats.Tiff.TiffFrame(pngImage);
tiffImage.AddFrame(frame);
}
Aspose.Imaging.FileFormats.Tiff.TiffFrame activeFrame = tiffImage.ActiveFrame;
tiffImage.ActiveFrame = tiffImage.Frames[1];
tiffImage.RemoveFrame(0);
activeFrame.Dispose();
tiffImage.Save();
}
Remarks
Note: do not forget to Dispose the frame if you will not add it to some other TiffImage.
RemoveFrame(TiffFrame)
Efficiently remove the specified frame from the image sequence, facilitatingstreamlined frame management within your application. Integrate this functionalityto enhance precision and flexibility in frame manipulation, ensuring seamlessorganization and presentation of image content.
public void RemoveFrame(TiffFrame frame)
{
}
Parameters
frame
TiffFrame
The frame to remove.
Remarks
Note: do not forget to Dispose the frame if you will not add it to some other TiffImage.
RemoveMetadata()
Removes this image instance metadata by setting this Aspose.Imaging.Xmp.IHasXmpData.XmpData and Aspose.Imaging.Exif.IHasExifData.ExifData values to null.
public override void
RemoveMetadata()
{
}
ReplaceFrame(int, TiffFrame)
Substitute the frame at the designated position with another frame seamlessly,facilitating dynamic frame management within the image sequence. Integrate thismethod to enhance flexibility and precision in frame manipulation, ensuringoptimal organization and presentation of image content within your application.
public TiffFrame ReplaceFrame(int index, TiffFrame frameToReplace)
{
if (Index < 0 || Index >= Frames.Count)
throw new ArgumentOutOfRangeException(nameof(index), "The index value is out of the valid range.");
var frame = Frames[index];
return frameToReplace;
}
Parameters
index
int
The zero based frame position.
frameToReplace
TiffFrame
The frame to replace.
Returns
The removed frame.
Remarks
Note: do not forget to Dispose the frame if you will not add it to some other TiffImage.
Resize(int, int, ResizeType)
Resize the image according to a specified resizing type, facilitating flexibleadjustment of image dimensions while preserving aspect ratio or applying specificscaling algorithms. Incorporate this method into your image processing workflowto achieve precise control over resizing operations within your application.
public override void
Resize(
int newWidth,
int newHeight,
ResizeType resizeType
)
Parameters
newWidth
int
The new width.
newHeight
int
The new height.
resizeType
ResizeType
The resize type.
Examples
This example loads a TIFF image and resizes it using various resizing methods.
string dir = "c:\\temp\\";
using (Aspose.Imaging.FileFormats.Tiff.TiffImage image = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
image.Resize(image.Width * 2, image.Height * 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
image.Save(dir + "upsample.nearestneighbour.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
using (Aspose.Imaging.FileFormats.Tiff.TiffImage image = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
image.Resize(image.Width / 2, image.Height / 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
image.Save(dir + "downsample.nearestneighbour.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
using (Aspose.Imaging.FileFormats.Tiff.TiffImage image = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
image.Resize(image.Width * 2, image.Height * 2, Aspose.Imaging.ResizeType.BilinearResample);
image.Save(dir + "upsample.bilinear.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
using (Aspose.Imaging.FileFormats.Tiff.TiffImage image = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
image.Resize(image.Width / 2, image.Height / 2, Aspose.Imaging.ResizeType.BilinearResample);
image.Save(dir + "downsample.bilinear.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
Resize(int, int, ImageResizeSettings)
Adjust the size of the image based on specified settings, allowing for precisecontrol over dimensions, aspect ratio, and scaling behavior. Integrate thismethod into your image processing workflow to achieve customized resizingoperations tailored to the specific requirements of your application.
public override void
Resize(
int newWidth,
int newHeight,
ImageResizeSettings settings)
{
}
Parameters
newWidth
int
The new width.
newHeight
int
The new height.
settings
ImageResizeSettings
The resize settings.
Examples
This example loads a TIFF image and resizes it using various resizing settings.
string dir = "c:\\temp\\";
Aspose.Imaging.ImageResizeSettings resizeSettings = new Aspose.Imaging.ImageResizeSettings();
resizeSettings.Mode = Aspose.Imaging.ResizeType.AdaptiveResample;
resizeSettings.FilterType = Aspose.Imaging.ImageFilterType.SmallRectangular;
resizeSettings.EntriesCount = 256;
resizeSettings.ColorQuantizationMethod = Aspose.Imaging.ImageColors.ColorQuantizationMethod.None;
resizeSettings.ColorCompareMethod = Aspose.Imaging.ImageColors.ColorCompareMethod.Euclidian;
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
tiffImage.Resize(image.Width / 2, image.Height / 2, resizeSettings);
tiffImage.Save(dir + "downsample.adaptive.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
ResizeHeightProportionally(int, ResizeType)
Conduct a proportional adjustment of the image’s height, preserving its aspectratio for consistent visual integrity. Employ this method to dynamically resizeimages within your application, ensuring optimal display across diverse platformsand devices without compromising content quality.
public override void ResizeHeightProportionally(int newHeight, ResizeType resizeType)
{
}
Parameters
newHeight
int
The new height.
resizeType
ResizeType
Type of the resize.
Examples
This example loads a TIFF image and resizes it proportionally using various resizing methods. Only the height is specified, the width is calculated automatically.
string dir = "c:\\temp\\";
using (Aspose.Imaging.FileFormats.Tiff.TiffImage image = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
image.ResizeHeightProportionally(image.Height * 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
image.Save(dir + "upsample.nearestneighbour.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
using (Aspose.Imaging.FileFormats.Tiff.TiffImage image = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
image.ResizeHeightProportionally(image.Height / 2, Aspoe.Imaging.ResizeType.NearestNeighbourResample);
image.Save(dir + "downsample.nearestneighbour.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
using (Aspose.Imaging.FileFormats.Tiff.TiffImage image = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
image.ResizeHeightProportionally(image.Height * 2, Aspose.Imaging.ResizeType.BilinearResample);
image.Save(dir + "upsample.bilinear.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
using (Aspose.Imaging.FileFormats.Tiff.TiffImage image = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
image.ResizeHeightProportionally(image.Height / 2, Aspoe.Imaging.ResizeType.BilinearResample);
image.Save(dir + "downsample.bilinear.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
ResizeProportional(int, int, ResizeType)
Conduct a proportional resize operation on the image, preserving its aspect ratiowhile adjusting its dimensions. Employ this method to dynamically scale imageswithin your application, ensuring consistent visual representation of contentintegrity.The proportional resize will resize each frame according to the ratio of newWidth’/width and
newHeight’/height.
public void ResizeProportional(
int newWidth,
int newHeight,
ResizeType resizeType)
{
}
Parameters
newWidth
int
The new width.
newHeight
int
The new height.
resizeType
ResizeType
The resize type.
ResizeWidthProportionally(int, ResizeType)
Adjust the width of the image while maintaining its aspect ratio, ensuringproportional resizing for optimal visual presentation. Utilize this method todynamically scale images within your application, facilitating consistent andaesthetically pleasing rendering across various display contexts.
public override void
ResizeWidthProportionally(
int newWidth,
ResizeType resizeType
)
{
}
Parameters
newWidth
int
The new width.
resizeType
ResizeType
Type of the resize.
Examples
This example loads a TIFF image and resizes it proportionally using various resizing methods. Only the width is specified, the height is calculated automatically.
string dir = "c:\\temp\\";
using (Aspose.Imaging.FileFormats.Tiff.TiffImage image = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
image.ResizeWidthProportionally(image.Width * 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
image.Save(dir + "upsample.nearestneighbour.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
using (Aspose.Imaging.FileFormats.Tiff.TiffImage image = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
image.ResizeWidthProportionally(image.Width / 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);
image.Save(dir + "downsample.nearestneighbour.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
using (Aspose.Imaging.FileFormats.Tiff.TiffImage image = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
image.ResizeWidthProportionally(image.Width * 2, Aspose.Imaging.ResizeType.BilinearResample);
image.Save(dir + "upsample.bilinear.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
using (Aspose.Imaging.FileFormats.Tiff.TiffImage image = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
image.ResizeWidthProportionally(image.Width / 2, Aspose.Imaging.ResizeType.BilinearResample);
image.Save(dir + "downsample.bilinear.png", new Aspose.Imaging.ImageOptions.PngOptions());
}
Rotate(float, bool, Color)
Rotate the image around its center point by a specified angle, enabling preciseorientation adjustments. Incorporate this functionality into your image processingpipeline to facilitate accurate transformations, ensuring optimal alignment andpresentation of visual content within your application.
public override void Rotate(
float angle,
bool resizeProportionally,
Color backgroundColor)
{
}
Parameters
angle
float
The rotate angle in degrees. Positive values will rotate clockwise.
resizeProportionally
bool
if set to ’true’ you will have your image size changed according to rotated rectangle (corner points) projections in other case that leaves dimensions untouched and only internal image contents are rotated.
backgroundColor
Color
Color of the background.
Examples
The following example shows how to rotate a TIFF image around the center by 45 degrees clockwise.
string dir = "c:\\temp\\";
Aspose.Imaging.ImageOptions.TiffOptions createTiffOptions = new Aspose.Imaging.ImageOptions.TiffOptions(Aspose.Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
createTiffOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(dir + "rotated.tif", false);
createTiffOptions.Photometric = Aspose.Imaging.FileFormats.Tiff.Enums.TiffPhotometrics.Rgb;
createTiffOptions.BitsPerSample = new ushort[] { 8, 8, 8 };
using (Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Image.Create(createTiffOptions, 100, 100))
{
Aspose.Imaging.Brushes.LinearGradientBrush brush =
new Aspose.Imaging.Brushes.LinearGradientBrush(
new Aspose.Imaging.Point(0, 0),
new Aspose.Imaging.Point(tiffImage.Width, tiffImage.Height),
Aspose.Imaging.Color.Red,
Aspose.Imaging.Color.Green);
Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(tiffImage);
gr.FillRectangle(brush, tiffImage.Bounds);
tiffImage.Rotate(45f, true, Aspose.Imaging.Color.Black);
tiffImage.Save();
tiffImage.Rotate(45f, false, Aspose.Imaging.Color.Gray);
tiffImage.Save(dir + "rotated.preservesize.tif");
}
RotateFlip(RotateFlipType)
Perform rotation, flipping, or a combination of both operations exclusively on theactive frame. This method allows precise manipulation of individual frames withinthe image sequence, enhancing flexibility in image editing and composition withinyour application.
public override void RotateFlip(RotateFlipType rotateFlipType)
{
}
Parameters
rotateFlipType
RotateFlipType
The rotate flip type.
Examples
This example loads a TIFF image, rotates it by 90 degrees clockwise and optionally flips the image horizontally and(or) vertically.
string dir = "c:\\temp\\";
Aspose.Imaging.RotateFlipType[] rotateFlipTypes = new Aspose.Imaging.RotateFlipType[]
{
Aspose.Imaging.RotateFlipType.Rotate90FlipNone,
Aspose.Imaging.RotateFlipType.Rotate90FlipX,
Aspose.Imaging.RotateFlipType.Rotate90FlipXY,
Aspose.Imaging.RotateFlipType.Rotate90FlipY
};
foreach (Aspose.Imaging.RotateFlipType rotateFlipType in rotateFlipTypes)
{
using (Aspose.Imaging.FileFormats.Tiff.TiffImage image = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
image.RotateFlip(rotateFlipType);
image.Save(dir + "sample." + rotateFlipType + ".png", new Aspose.Imaging.ImageOptions.PngOptions());
}
}
SaveData(Stream)
Saves the object’s data to the specified stream.
protected override void SaveData(Stream stream)
{
base.SaveData(stream);
}
Parameters
stream
Stream
The stream to save the object’s data to.
SetResolution(double, double)
Establishes the resolution for the specified Aspose.Imaging.RasterImage, enablingprecise control over image rendering and display properties. Integrate thisfunctionality to optimize visual output and ensure compatibility with diverseoutput devices and platforms, enhancing the overall user experience.
public override void
SetResolution(double dpiX, double dpiY)
{
}
Parameters
dpiX
double
The horizontal resolution, in dots per inch, of the Aspose.Imaging.RasterImage.
dpiY
double
The vertical resolution, in dots per inch, of the Aspose.Imaging.RasterImage.
Examples
The following example shows how to set horizontal/vertical resolution of a TIFF image.
string dir = "c:\\temp\\";
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.tif"))
{
Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (Aspose.Imaging.FileFormats.Tiff.TiffImage)image;
double horizontalResolution = tiffImage.HorizontalResolution;
double verticalResolution = tiffImage.VerticalResolution;
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", horizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", verticalResolution);
if (horizontalResolution != 96.0 || verticalResolution != 96.0)
{
System.Console.WriteLine("Set resolution values to 96 dpi");
tiffImage.SetResolution(96.0, 96.0);
System.Console.WriteLine("The horizontal resolution, in pixels per inch: {0}", tiffImage.HorizontalResolution);
System.Console.WriteLine("The vertical resolution, in pixels per inch: {0}", tiffImage.VerticalResolution);
}
}
UpdateDimensions(int, int)
Updates the image dimensions.
protected override void UpdateDimensions(
int newWidth,
int newHeight
)
{
}
Parameters
newWidth
int
The new image width.
newHeight
int
The new image height.