TgaImage

TgaImage class

The TGA image.

public class TgaImage : RasterCachedImage

Constructors

Name Description
TgaImage(RasterImage) Initializes a new instance of the TgaImage class.
TgaImage(Stream) Initializes a new instance of the TgaImage class.
TgaImage(string) Initializes a new instance of the TgaImage class.

Properties

Name Description
AuthorComments { get; set; } Gets or sets Author Comments. This is an ASCII field consisting of 324 bytes which are organized as four lines of 80 characters, each followed by a null terminator.
AuthorName { get; set; } Gets or sets Author Name. This field is a total of 40 ASCII characters for the name. If the field is used, it should contain the name of the person who created the image (author).
AutoAdjustPalette { get; set; } Gets or sets a value indicating whether automatic adjust palette.
override BackgroundColor { get; set; } Gets or sets the background color.
override BitsPerPixel { get; } Gets bits per pixel.
Bounds { get; } Gets the image bounds.
BufferSizeHint { get; set; } Gets or sets the buffer size hint which is defined max allowed size for all internal buffers.
BytesPerPixel { get; } Gets bytes per pixel.
Container { get; } Gets the Image container.
DataStreamContainer { get; } Gets the object’s data stream.
DateTimeStamp { get; set; } Gets or sets Date/Time Stamp. This field defines the value for the date and time that the image was saved. Even though operating systems typically time- and date-stamp files, this feature is provided because the operating system may change the time and date stamp if the file is copied. By using this area, you are guaranteed an unmodified region for date and time recording.
Disposed { get; } Gets a value indicating whether this instance is disposed.
override FileFormat { get; } Gets the file format.
GammaValueDenominator { get; } Gets Gamma Value Denominator part. An uncorrected image (an image with no gamma) should have the value 1.0 as the result.
GammaValueNumerator { get; } Gets Gamma Value Numerator part. An uncorrected image (an image with no gamma) should have the value 1.0 as the result.
override HasAlpha { get; } Gets a value indicating whether this TgaImage has an alpha channel.
override HasBackgroundColor { get; set; } Gets or sets a value indicating whether the image has background color.
HasColorMap { get; } Gets a value indicating whether this image has color map.
override HasTransparentColor { get; set; } Gets or sets a value indicating whether the image has transparent color.
override Height { get; } Gets this image height.
virtual HorizontalResolution { get; set; } Gets or sets the horizontal resolution, in pixels per inch, of this RasterImage.
ImageId { get; set; } Gets or sets Image ID.
virtual ImageOpacity { get; } Gets opacity of this image.
InterruptMonitor { get; set; } Gets or sets the interrupt monitor.
override IsCached { get; } Gets a value indicating whether image data is cached currently.
IsGrayScale { get; } Gets a value indicating whether this TgaImage is gray-scale.
IsRawDataAvailable { get; } Gets a value indicating whether raw data loading is available.
JobNameOrId { get; set; } Gets or sets Job Name/ID.
JobTime { get; set; } Gets or sets Job Time.
Palette { get; set; } Gets or sets the color palette. The color palette is not used when pixels are represented directly.
PixelAspectRatioDenominator { get; } Gets Pixel Aspect Ratio denominator part.
PixelAspectRatioNumerator { get; } Gets Pixel Aspect Ratio numerator part.
virtual PremultiplyComponents { get; set; } Gets or sets a value indicating whether the image components must be premultiplied.
RawCustomColorConverter { get; set; } Gets or sets the custom color converter
virtual RawDataFormat { get; } Gets the raw data format.
RawDataSettings { get; } Gets the current raw data settings. Note when using these settings the data loads without conversion.
RawFallbackIndex { get; set; } Gets or sets the fallback index to use when palette index is out of bounds
RawIndexedColorConverter { get; set; } Gets or sets the indexed color converter
virtual RawLineSize { get; } Gets the raw line size in bytes.
Size { get; } Gets the image size.
SoftwareId { get; set; } Gets or sets Software ID. A total of 40 ASCII characters for the Software ID.
SoftwareVersion { get; set; } Gets or sets Software Version. Accepted version string length is 3-4 characters.
SoftwareVersionLetter { get; set; } Gets or sets Software Version letter part.
SoftwareVersionNumber { get; set; } Gets or sets Software Version number part.
override TransparentColor { get; set; } Gets or sets Key Color.
virtual UpdateXmpData { get; set; } Gets or sets a value indicating whether to update the XMP metadata.
override UsePalette { get; } Gets a value indicating whether the image palette is used.
virtual UseRawData { get; set; } Gets or sets a value indicating whether to use raw data loading when the raw data loading is available.
virtual VerticalResolution { get; set; } Gets or sets the vertical resolution, in pixels per inch, of this RasterImage.
override Width { get; } Gets this image width.
virtual XmpData { get; set; } Gets or sets the XMP metadata.
XOrigin { get; set; } Gets or sets absolute horizontal coordinate for the lower left corner of the image as it is positioned on a display device having an origin at the lower left of the screen(e.g., the TARGA series).
YOrigin { get; set; } Gets or sets absolute vertical coordinate for the lower left corner of the image as it is positioned on a display device having an origin at the lower left of the screen(e.g., the TARGA series).

Methods

Name Description
override AdjustBrightness(int) Adjust of a brightness for image.
override AdjustContrast(float) Image contrasting
override AdjustGamma(float) Gamma-correction of an image.
override AdjustGamma(float, float, float) Gamma-correction of an image.
override BinarizeBradley(double) Binarization of an image using Bradley’s adaptive thresholding algorithm using the integral image thresholding
override BinarizeBradley(double, int) Binarization of an image using Bradley’s adaptive thresholding algorithm using the integral image thresholding
override BinarizeFixed(byte) Binarization of an image with predefined threshold
override BinarizeOtsu() Binarization of an image with Otsu thresholding
override CacheData() Caches the data and ensures no additional data loading will be performed from the underlying DataStreamContainer.
CanSave(ImageOptionsBase) Determines whether image can be saved to the specified file format represented by the passed save options.
Clone() Creates a new object that is a copy of the current instance.
Clone(TgaImage) Clone other TgaImage object’s properties.
override Crop(Rectangle) Cropping the image.
override Crop(int, int, int, int) Crop image with shifts.
Dispose() Disposes the current instance.
Dither(DitheringMethod, int) Performs dithering on the current image.
override Dither(DitheringMethod, int, IColorPalette) Performs dithering on the current image.
override Equals(object) Equality comparison.
Equals(TgaImage) Equality comparison.
virtual Filter(Rectangle, FilterOptionsBase) Filters the specified rectangle.
GetArgb32Pixel(int, int) Gets an image 32-bit ARGB pixel.
GetDefaultArgb32Pixels(Rectangle) Gets the default 32-bit ARGB pixels array.
virtual GetDefaultOptions(object[]) Gets the default options.
GetDefaultPixels(Rectangle, IPartialArgb32PixelLoader) Gets the default pixels array using partial pixel loader.
GetDefaultRawData(Rectangle, RawDataSettings) Gets the default raw data array.
GetDefaultRawData(Rectangle, IPartialRawDataLoader, RawDataSettings) Gets the default raw data array using partial pixel loader.
override GetHashCode() Get hash code of this instance. Not suitable to be used as a key as TgaImage is not immutable.
virtual GetModifyDate(bool) Gets the date and time the resource image was last modified.
virtual GetOriginalOptions() Gets the options based on the original file settings. This can be helpful to keep bit-depth and other parameters of the original image unchanged. For example, if we load a black-white PNG image with 1 bit per pixel and then save it using the Save 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 them to the Save method as the second parameter.
GetPixel(int, int) Gets an image pixel.
GetSkewAngle() Gets the skew angle. This method is applicable to scanned text documents, to determine the skew angle when scanning.
override Grayscale() Transformation of an image to its grayscale representation
LoadArgb32Pixels(Rectangle) Loads 32-bit ARGB pixels.
LoadArgb64Pixels(Rectangle) Loads 64-bit ARGB pixels.
LoadCmyk32Pixels(Rectangle) Loads pixels in CMYK format.
LoadPartialArgb32Pixels(Rectangle, IPartialArgb32PixelLoader) Loads 32-bit ARGB pixels partially by packs.
LoadPartialArgb64Pixels(Rectangle, IPartialArgb64PixelLoader) Loads 64-bit ARGB pixels partially by packs.
LoadPartialPixels(Rectangle, IPartialPixelLoader) Loads pixels partially by packs.
LoadPixels(Rectangle) Loads pixels.
LoadRawData(Rectangle, RawDataSettings, IPartialRawDataLoader) Loads raw data.
LoadRawData(Rectangle, Rectangle, RawDataSettings, IPartialRawDataLoader) Loads raw data.
NormalizeAngle() Normalizes the angle. This method is applicable to scanned text documents to get rid of the skewed scan. This method uses GetSkewAngle and Rotate methods.
virtual NormalizeAngle(bool, Color) Normalizes the angle. This method is applicable to scanned text documents to get rid of the skewed scan. This method uses GetSkewAngle and Rotate methods.
ReadArgb32ScanLine(int) Reads the whole scan line by the specified scan line index.
ReadScanLine(int) Reads the whole scan line by the specified scan line index.
ReplaceColor(Color, byte, Color) Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.
virtual ReplaceColor(int, byte, int) Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.
ReplaceNonTransparentColors(Color) Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges. Note: if you use it on images without transparency, all colors will be replaced with a single one.
virtual ReplaceNonTransparentColors(int) Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges. Note: if you use it on images without transparency, all colors will be replaced with a single one.
Resize(int, int) Resizes the image. The default NearestNeighbourResample is used.
override Resize(int, int, ImageResizeSettings) Resizes the image.
override Resize(int, int, ResizeType) Resizes the image.
ResizeHeightProportionally(int) Resizes the height proportionally. The default NearestNeighbourResample is used.
virtual ResizeHeightProportionally(int, ImageResizeSettings) Resizes the height proportionally.
virtual ResizeHeightProportionally(int, ResizeType) Resizes the height proportionally.
ResizeWidthProportionally(int) Resizes the width proportionally. The default NearestNeighbourResample is used.
virtual ResizeWidthProportionally(int, ImageResizeSettings) Resizes the width proportionally.
virtual ResizeWidthProportionally(int, ResizeType) Resizes the width proportionally.
virtual Rotate(float) Rotate image around the center.
override Rotate(float, bool, Color) !:RasterCahcedMultipageImage.Rotate image around the center.
override RotateFlip(RotateFlipType) The rotate flip.
Save() Saves the image data to the underlying stream.
Save(Stream) Saves the object’s data to the specified stream.
override Save(string) Saves the image to the specified file location.
Save(Stream, ImageOptionsBase) Saves the image’s data to the specified stream in the specified file format according to save options.
virtual Save(string, bool) Saves the object’s data to the specified file location.
virtual Save(string, ImageOptionsBase) Saves the object’s data to the specified file location in the specified file format according to save options.
override Save(Stream, ImageOptionsBase, Rectangle) Saves the image’s data to the specified stream in the specified file format according to save options.
virtual Save(string, ImageOptionsBase, Rectangle) Saves the object’s data to the specified file location in the specified file format according to save options.
SaveArgb32Pixels(Rectangle, int[]) Saves the 32-bit ARGB pixels.
SaveCmyk32Pixels(Rectangle, int[]) Saves the pixels.
SavePixels(Rectangle, Color[]) Saves the pixels.
SaveRawData(byte[], int, Rectangle, RawDataSettings) Saves the raw data.
SetArgb32Pixel(int, int, int) Sets an image 32-bit ARGB pixel for the specified position.
override SetPalette(IColorPalette, bool) Sets the image palette.
SetPixel(int, int, Color) Sets an image pixel for the specified position.
virtual SetResolution(double, double) Sets the resolution for this RasterImage.
virtual ToBitmap() Converts raster image to the bitmap.
WriteArgb32ScanLine(int, int[]) Writes the whole scan line to the specified scan line index.
WriteScanLine(int, Color[]) Writes the whole scan line to the specified scan line index.
operator == Equality comparison.
operator != Non-equality comparison.

Examples

Saving of the JPG image as a TGA image.

[C#]

using (RasterImage image = (JpegImage)Image.Load("test.jpg"))
{
    image.Save("test.tga"", new TgaOptions());
}

Loading of the PNG image, conversion of it to the TgaImage and saving as a TGA image.

[C#]

using (RasterImage image = (RasterImage)Image.Load("test.png"))
{
    using (TgaImage tgaImage = new TgaImage(image))
    {
        tgaImage.Save("test.tga");
    }
}

Updating public properties of the loaded TGA image.

[C#]

using (TgaImage image = (TgaImage)Image.Load("test.tga"))
{
    image.DateTimeStamp = testTime;
    image.AuthorName = "John Smith";
    image.AuthorComments = "Comment";
    image.ImageId = "ImageId";
    image.JobNameOrId = "Important Job";
    image.JobTime = TimeSpan.FromDays(10);
    image.TransparentColor = Color.FromArgb(123);
    image.SoftwareId = "SoftwareId";
    image.SoftwareVersion = "abc1";
    image.SoftwareVersionLetter = 'a';
    image.SoftwareVersionNumber = 2;
    image.XOrigin = 1000;
    image.YOrigin = 1000;

    image.Save("test.tga")
}

Getting values of the public properties of the loaded TGA image.

[C#]

using (TgaImage image = (TgaImage)Image.Load("test.tga"))
{
    dateTimeStamp = image.DateTimeStamp;
    authorName = image.AuthorName;
    authorComments = image.AuthorComments;
    imageId = image.ImageId;
    jobNameOrId = image.JobNameOrId;
    jobTime = image.JobTime;
    keyColor = image.TransparentColor;
    softwareId = image.SoftwareId;
    softwareVersion = image.SoftwareVersion;
    softwareVersionLetter = image.SoftwareVersionLetter;
    softwareVersionNumber = image.SoftwareVersionNumber;
    xOrigin = image.XOrigin;
    yOrigin = image.YOrigin;
    gammaValueDenominator = image.GammaValueDenominator;
    gammaValueNumerator = image.GammaValueNumerator;
    hasAlphaChannel = image.HasAlpha;
    hasColorMap = image.HasColorMap;
    height = image.Height;
    isGrayScale = image.IsGrayScale;
    pixelAspectRatioDenominator = image.PixelAspectRatioDenominator;
    pixelAspectRatioNumerator = image.PixelAspectRatioNumerator;
    size = image.Size;
    width = image.Width;
}

See Also