JpegGif Object

Overview

The JpegGif object creates, opens, resizes, manages and saves GIF images. This object is covered in detail in Chapter 9 - GIF Output.

Member List

Properties


byte [] Binary (Read-only)

Returns a binary array of bytes representing the output GIF image. This property is useful for saving images in the database as BLOBs.

See also: Chapter 9 - GIF Output.


int BrushColor (Read/Write)

Specifies a brush color index for the current frame. Affects all the fill operations.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


int CurrentFrame (Read/Write)

Returns or specifies the current frame within a GIF image. All drawing operations are always performed on the current frame. The frame index is 1-based and must be between 1 and FrameCount.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


uint Delay (Read/Write)

Returns or specifies the delay (in 100ths of a second) of the current frame in an animated GIF. 100 (1 second) by default.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support, Section 9.7.2 - Other Animation Management Properties.


short DisposalMethod (Read/Write)

Controls the way frames in an animated GIF replace each other. Valid values are:

  1. Leave the current image in place and draw the next image on top of it. This is the default method.
  2. The canvas should be restored to the background color before the next image is rendered.
  3. The canvas should be restored to its previous state before the current image is drawn.

See also: Section 9.4 - Using External Images as Frames, Section 9.7.2 - Other Animation Management Properties.


int FontAlign (Read/Write)

Specifies text alignment for the PrintText method. Valid values are: 0 - left (default), 1 - right, 2 - center and 3 - justified. If a value other than 0 is specified, the FontWidth property must also be specified.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


int FontRotation (Read/Write)

Specifies text rotation angle (in degrees, rotation is counter-clockwise) for the PrintText method. 0 (horizontal) by default.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


int FontSize (Read/Write)

Specifies font size for the PrintText method, in pixels. 12 by default.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


int FontSpacing (Read/Write)

Specifies line spacing adjustment (in pixels) for the PrintText method. A positive value increases the default line spacing, a negative value decreases it.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


int FontWidth (Read/Write)

Specifies the width of an area in which a text string drawn via PrintText is to be inscribed. Activates word wrapping if necessary. This property must also be set if the FontAlign property is set to a value other than 0 (left alignment).

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


int FrameCount (Read/Write)

Returns the total number of frames in the GIF image.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


int FrameHeight (Read/Write)
Returns or specifies the height of the current frame in pixels.

int FrameOffsetX (Read/Write)
Returns or specifies the horizontal offset of the current frame in pixels.

int FrameOffsetY (Read/Write)
Returns or specifies the vertical offset of the current frame in pixels.

int FrameToSave (Read/Write)

0 by default. If set to a valid 1-based frame index, instructs the JpegGif object to only save the specified frame when a Save method is called. This property is mostly useful for debugging only.

See also: Section 9.7.3 - Saving Individual Frames.


int FrameWidth (Read/Write)
Returns or specifies the width of the current frame in pixels.

int Height (Read/Write)

Returns or specifies the overall height of a GIF image in pixels. This property does not affect the size of individual frames within the image. If an image has no frames yet, callings AddFrame or AddImage for the first time sets the Height to that of the frame being added.

See also: Section 9.4 - Using External Images as Frames.


uint Loops (Read/Write)

Returns or specifies the number of times an animated GIF runs its sequence before stopping. 0 by default which means the sequence runs indefinitely.

See also: Section 9.7.2 - Other Animation Management Properties.


int PenColor (Read/Write)

Specifies a pen color index for the current frame. This property affects all drawing methods and also PrintText.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


int PenWidth (Read/Write)

Specifies a pen width for the current frame. This property affects all drawing methods.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


byte Pixels[int Col, int Row] (Read/Write)
This parameterized property returns or sets the color index for a pixel specified by [Col, Row] within the current frame.

int Quantization (Read/Write)

Controls the quality of true-color to 256-color conversion when AddImage is called. Valid values are from 1 to 30, 1 being the highest quality but also the slowest speed. The default value is 20 which provides an adequate balance between speed and quality. Setting this property to anything below 10 is not recommended for performance considerations.

See also: Section 9.4 - Using External Images as Frames.


short TranspColor (Read/Write)

Returns or specifies the transparent color index for the current frame. Setting this property has a side effect of setting the TranspColorSet property to true.

See also: Section 9.6 - Transparency


bool TranspColorSet (Read/Write)

Returns true if the current frame has a transparent color index associated with it. The index itself is returned via the TranspColor property. Setting this property to false effectively removes a transparent color from the current frame.

See also: Section 9.6 - Transparency.


int Width (Read/Write)

Returns or specifies the overall width of a GIF image in pixels. This property does not affect the size of individual frames within the image. If an image has no frames yet, callings AddFrame or AddImage for the first time sets the Width to that of the frame being added.

See also: Section 9.4 - Using External Images as Frames.

Methods


void AddFrame(int Width, int Height, int OffsetX, int OffsetY)

Adds an empty frame to the image with the specified width, height, and offsets. The newly added frame becomes the current one and is filled with color index 0. It has no local palette. The new frame is added to the end of the animation sequence.

If this is the first frame in the image, the overall image width and height are assigned the values from the new frame.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


void AddImage(JpegImage Image, int OffsetX, int OffsetY)

Adds a new frame populated with Image which is an instance of the JpegImage object. This method performs a true-color to 256-color conversion. The speed and quality of the conversion is determined by the Quantization property.

The new frame is assigned a 256-color local palette computed from the image being converted for optimal quality.

See also: Section 9.4 - Using External Images as Frames.


void Clear()
Removes all frames from the image. An empty image cannot be drawn on, resized, or saved.

void DrawArc(float x, float y, float Radius1, float Radius2, float Angle1, float Angle2, float TiltAngle)

Draws an arc with the center in (x, y), horizontal radius Radius1, vertical radius Radius2, beginning at the angle Angle1 relative to the horizontal axis of the ellipse, ending at the angle Angle2. The ellipse itself is tilted by an angle specified by TiltAngle. Uses the current pen's width, color, opacity and dash pattern, on the current frame.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


void DrawEllipse(float x, float y, float Radius1, float Radius2)

Draws an ellipse with the center in (x, y) and horizontal and vertical radii Radius1 and Radius2, respectively, using the current pen's width, color, opacity and dash pattern, on the current frame.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


void DrawLine(float x1, float y1, float x2, float y2)

Draws a line specified by the coordinates of its starting and ending points (in pixels) using the current pen's width, color, opacity and dash pattern, on the current frame.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


void DrawRect(float x, float y, float Width, float Height)

Draws a rectangle with the upper-left corner in (x, y) and specified Width and Height using the current pen's width, color, opacity, dash pattern and other parameters, on the current frame.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


void DrawRoundRect(float x, float y, float Width, float Height, float Rx, float Ry)

Draws a rectangle with rounded corners on the current frame using the current pen's width, color, opacity and dash pattern. The rectangle is specified by the coordinates of its upper-left corner, width and height. The corners are rounded by an ellipse with the width and height specified by Rx and Ry.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


void DrawSegment(float x, float y, float Radius1, float Radius2, float Angle1, float Angle2, float TiltAngle)

Draws the segment of an ellipse with the center in (x, y), horizontal radius Radius1, vertical radius Radius2, beginning at the angle Angle1 relative to the horizontal axis of the ellipse, ending at the angle Angle2. The ellipse itself is tilted by an angle specified by TiltAngle. The segment is drawn on the current frame using the current pen's width, color, opacity, dash pattern and other parameters.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


void FillArc(float x, float y, float Radius1, float Radius2, float Angle1, float Angle2, float TiltAngle)

Fills an arc with the center in (x, y), horizontal radius Radius1, vertical radius Radius2, beginning at the angle Angle1 relative to the horizontal axis of the ellipse, ending at the angle Angle2. The ellipse itself is tilted by an angle specified by TiltAngle. The arc is filled on the current frame using the current brush's color and opacity.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


void FillEllipse(float x, float y, float Radius1, float Radius2)

Fills an ellipse with the center in (x, y) and horizontal and vertical radii Radius1 and Radius2, respectively. The ellipse is filled on the current frame using the current brush's color and opacity.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


void FillRect(float x, float y, float Width, float Height)

Fills a rectangle with the upper-left corner in (x, y) and specified Width and Height. The rectangle is filled on the current frame using the current brush's color and opacity.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


void FillRoundRect(float x, float y, float Width, float Height, float Rx, float Ry)

Fills a rectangle with rounded corners on the current frame using the current brush's color and opacity. The rectangle is specified by the coordinates of its upper-left corner, width and height. The corners are rounded by an ellipse with the width and height specified by Rx and Ry.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


void FillSegment(float x, float y, float Radius1, float Radius2, float Angle1, float Angle2, float TiltAngle)

Fill the segment of an ellipse with the center in (x, y), horizontal radius Radius1, vertical radius Radius2, beginning at the angle Angle1 relative to the horizontal axis of the ellipse, ending at the angle Angle2. The ellipse itself is tilted by an angle specified by TiltAngle. The segment is filled on the current frame using the current brush's color and opacity.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


void FindClosestColor(bool Global, int R, int G, int B)

Scans the specified palette and looks for a color closest to the RGB values specified, and returns its index. If Global is true, the global palette is scanned, otherwise the local palette pertaining to the current frame is scanned.

See also: 9.7.4 - Finding a Closest Color.


void GetPaletteItem(bool Global, int Index)

Returns an RGB component of a palette item pointed to by Index in a palette specified by Global. If Global is true, the global palette is used, otherwise the local palette pertaining to the current frame is used. Index must be an integer between 0 and GetPaletteSize() * 3 - 1. For example, GetPaletteItem(true, 4) refers to the Green component of the 2nd entry of the global palette.

See also: 9.7.4 - Finding a Closest Color.


void GetPaletteSize(bool Global)

Returns the number of entries in a palette. If Global is true, the global palette is used, otherwise the local palette pertaining to the current frame is used.

See also: 9.7.4 - Finding a Closest Color.


void MoveFrame(int OriginalIndex, int DesiredIndex)

Moves the frame specified by the first argument (1-based) to a new location specified by the 2nd argument. If the current frame is affected by the move, the CurrentFrame property will change to reflect the new position of the current frame.

See also: 9.7.1 - Other Frame Management Methods.


void Open(string Path)
void Open(byte [] FileBytes)

Opens a GIF image from a disk file specified by Path or a byte array specified by FileBytes. Populates all the frames and assigns all the JpegGif object properties. Path must point to a GIF file, any other format will be rejected.

See also: 9.3 - GIF Image Resizing.


int PrintText(string Text, int x, int y, string FontPath)
int PrintText(string Text, int x, int y, string FontPath, int FontIndex)
int PrintText(string Text, int x, int y, byte [] FontBytes)
int PrintText(string Text, int x, int y, byte [] FontBytes, int FontIndex)

Prints text using a TrueType/OpenType or Type 1 font specified by its physical path or byte array. Supports word wrapping, rotation, text alignment (to the left, right, center and justified) and adjustable line spacing.

Text - specifies the text string to be printed (in Unicode format). May contain CR/LF characters for multi-line display.

x, y - coordinates of the lower-left corner of the first character of the first line, relative to the upper-left corner of the image.

FontPath - specifies a physical path to the font file. The font does not need to be properly registered on the system as long as the path to the font file is known.

FontBytes - specifies a byte array containing the font. The font does not need to be properly registered on the system as long as the path to the font file is known.

FontIndex specifies a font index within a multi-font file (or byte array) and is 0 by default.

Additional optional parameters are specified via the following properties:

PenColor - specifies the text color index.

FontRotation - specifies the rotation angle around the (X, Y) point in degrees. A positive value creates a counter-clockwise rotation.

FontSize - specifies font size in pixels.

FontSpacing - specifies an adjustment in pixels for the default line spacing when multi-line text is being rendered. A positive value increases the line spacing, a negative one decreases it.

FontWidth - specifies the width of an area in which the text string is to be inscribed.

Word wrapping occurs if the text string does not fit in the area. This property must also be set if non-default text alignment is specified via FontAlign.

FontAlign - specifies text alignment. Valid values are: 0 - left (default), 1 - right, 2 - center, and 3 - justified. For values other than 0, FontWidth must also be specified.

Returns the width (in pixels) of the text string being drawn. If the string is split into multiple lines, returns the width of the longest line.


void RemoveFrame(int Index)

Removes the frame specified by its index. If the current frame is being removed, another frame becomes current, and the CurrentFrame property may change.

See also: Section 9.2 - AspJpeg.NET's GIF Output Support.


void Resize(int NewWidth, int NewHeight)
void Resize(int NewWidth, int NewHeight, int Interpolation)

Resizes the current image while preserving its transparency and animation. If either NewWidth or NewHeight is zero, this argument is calculated automatically to preserve the original aspect ratio. NewWidth and NewHeight cannot both be zero. Interpolation is 0 (nearest-neighbor algorithm) by default. Using other algorithms may cause undesired artifacts when resizing certain animated images.

See also: Section 9.3 - GIF Image Resizing.


void Save(string Path)

Saves the resultant GIF image to disk. If a file specified by Path already exists, it will be overwritten.

See also: Chapter 9 - GIF Output.


string SaveUnique(string Path)

Same as Save but generates a unique filename if the file specified by Path already exists. A unique name is generated to avoid overwriting an existing file by appending a number in parentheses after the filename, such as image(1).jpg, image(2).jpg, etc. Returns the filename (without the path) under which the image ends up being saved.

See also: Chapter 9 - GIF Output.


void SendBinary()
void SendBinary(string ContentDisposition)

Sends the resultant image directly to the client browser by internally calling Response.BinaryWrite. Automatically sets the Content-Type header to "image/gif".

If ContentDisposition is set, also sets the "Content-Disposition" header to a value specified by this argument. A typical value for this argument is

"filename=image_name.gif"

or

"attachment;filename=image_name.gif"

You can only use this method in an IIS environment.

See also: Chapter 9 - GIF Output.


void SetPalette(bool Global As Boolean, byte [] Palette)

Specifies a new palette by supplying an array of RGB values for all entries at once.

If Global is set to true, the global palette is changed, otherwise the local palette pertaining to the current frame is changed.

Palette is a byte array of numbers that are treated as consecutive RGB values of all palette entries. The size of the array must be 3 multiplied by a valid GIF palette size (2, 4, 8, ..., 256 entries.)

See also: 9.5 - Palette Management.


void SetPaletteItem(bool Global, int Index, int Value)

Specifies an RGB component of a palette item pointed to by Index in a palette specified by Global. If Global is true, the global palette is used, otherwise the local palette pertaining to the current frame is used. Index must be an integer between 0 and GetPaletteSize() * 3 - 1. For example, SetPaletteItem(true, 4, 255) sets the Green component of the 2nd entry of the global palette to 255.

See also: Section 9.5 - Palette Management.


void SetPaletteSize(bool Global, int Value)

Specifies the number of entries in a palette. If Global is true, the global palette is used, otherwise the local palette pertaining to the current frame is used. Setting a palette size to 0 effectively removes the palette.

See also: Section 9.5 - Palette Management.


void SetStockPalette(bool Global, int Type)

Specifies a built-in (or "stock") palette by number.

If Global is set to true, the global palette is changed, otherwise the local palette pertaining to the current frame is changed.

Type selects one of the available stock palettes. The valid values are:

  1. 216 web-safe colors.
  2. 16 standard HTML colors.
  3. 256 grayscale colors.

See also: 9.5.3 - Stock Palettes.