Tonec.com Bringing Internet Technology Innovations to Market since 1991
  News Products Outsourcing About Us Contact Us
what's new?what's new? featuresfeatures samplessamples downloaddownload buybuy
  Tonec Homepage
ProductsActive ImageManual

Active Image Active Image v4.9 Documentation


Methods:

CopyImage , CopyImageResize, CopyImageRotate *, CopyImageSimpleRotate*, CopyImageMerge *, CreateImage, ConvertToGrayScale *, ConvertToMonochromeAuto *, ConvertToPalette *, ConvertToPaletteNoAlpha *, CreateImagePalette *, DestroyImage, DrawArc, DrawEllipse, DrawFilledArc, DrawFilledEllipse, DrawFilledPolygon, DrawFilledRectangle, DrawLine, DrawPolygon, DrawRectangle, DrawText, DrawTextAngle, Fill, DrawTextTTF *, DrawTextAngleTTF *, Fill, GetColorBlue, GetColorGreen, GetColorRed, GetColorAlpha *, GetColorTotal *, GetPixelAlpha *, GetTextTTFRectangle *, GetTrueColor *, GetFont, GetHeight, GetImage, GetImageType, GetInterlace, GetJpegQuality, GetLineThickness, GetPixelBlue, GetPixelGreen, GetPixelRed, GetTransparent, GetWidth, ReadFromDatabase, ReadFromFile, ReadFromVariable, SetColor, SetFont, SetFontTTF, SetImage, SetImageType, SetJpegQuality, SetLineThickness, SetAlphaColor *, SetAlphaBlending *, SetColorByIndex *, SetFontPathTTF *, SetFontPathTTFAuto *, SetFontSizeTTF *, SetSaveAlpha *, SetPixel, SetTextAntialias, SetTransparent, WriteToDatabase, WriteToFile, WriteToVariable, WriteToVariableVariant *

* - new methods in v4.2, v4.5 , v4.7 and v4.9

Introduction

General information

Component is distributed with complete source code that can be easily extended with your own functionality. Another advantage is that you can host the component on the servers where system security policy allows running only open source components.

Working with the component

Let us take a close look at the component internals on a simple sample.

Image Creation.

Used method: CreateImage (width, height)

CreateImage allocates memory and creates black image with specified image dimensions (width and height) in a special internal format. You need to select image type every time you need to import/export image to/from the component e.g. saving image to file, database or data stream.

Image format.

Used method: SetImageType (style)

Image format can be set with SetImageType method. Type 0 sets PNG format (default), type 1- Jpeg. You need also to define the type when reading image from database or variable.

Text Output.

Used method: SetFont (num), and TrueType font - SetFontPathTTFAuto, SetFontTTF, DrawTextTTF

Component has a number of predefined font styles: 0 - Small (default) , 1 - MediumBold , 2- Large, 3 - Tiny, 4 - Giant

Dim im
‘ Define object variable
Set im = CreateObject("ActiveImage.Images.1") ‘ Create object
im.CreateImage 150,75 ‘ Create image with specified width and height
im.SetSaveAlpha 0
im.SetColor 191,255,255 ‘Set foreground color in RGB format (white)
im.Fill 0,0 ‘ Fill from the current point with foreground color
im.SetColor 0,0,0 ‘ Set foreground color in RGB format (black)
im.SetFont 0 ‘ Set font number to 0 (Small)
im.DrawText 10,10, "Small - (default) " &im.GetFont ‘ Draw text and the number of active font
im.SetFont 1
im.DrawText 10,20, "Medium Bold - " & im.GetFont
im.SetFont 2
im.DrawText 10,30, "Large - " & im.GetFont
im.SetFont 3
im.DrawText 10,44, "Tiny - " & im.GetFont
im.SetFont 4
im.DrawText 10,50, "Giant - " & im.GetFont
 
'TrueType font
im.SetPathFontTTFAuto
im.SetFontSize 14
im.SetFontTTF "verdanab"
im.DrawTextTTF 10,60, "TrueType"
im.WriteToFile "C:\font.png" ‘ Save Image to file. Default type 0 corresponds to PNG format.
im.SetImageType 1 ' Set Jpeg format
im.SetJpegQuality 100 ‘ Set Jpeg quality
im.WriteToFile "C:\font.jpg"
im.DestroyImage ‘ Delete image and free memory
Set im = Nothing ‘ Clear the variable
Picture 1.

Line.

Used method: SetLineThickness (num). Line thickness (in number of pixels) is applied for DrawLine, DrawArc and DrawPolygon methods. Default value is 1

Polygon.

Used method: DrawPolygon (array a, integer point_num)

This sample draws polygons. You need to define coordinates array and consequently fill it with x,y pairs. For example coord(0) = x1, coord(1) = y1, etc. In a call to DrawPolygon you have to specify the array and the number of points (or x, y pairs) to draw.

Methods

ConvertToGrayScale () Converts image to GrayScale.
ConvertToMonochromeAuto () Converts TrueColor image to black and white. This method can be used to create WBMP images. See "Graphics for WAP" sample.
ConvertToPalette () Converts TrueColor image to palletized one. This method can be used to create transparent PNG images. Seecreating transparent images sample.
ConvertToPaletteNoAlpha () Converts TrueColor image to palletized one without alpha channel (most accurate color conversion despite decreasing color depth from 4294967296 to 256 colors).
CopyImage (destnum, srcnum, destX, destY, srcX, srcY, width, height) - Copy image part
srcnum – Image handle (number) to copy from [0 - 10]
destnum – Image handle (number) to copy to [0 - 10]
(destX, destY)– coordinate to place a part of source image from (srcX, srcY) with specified width and height
width – integer. Image width
height – integer. Image height
CopyImageMerge (destnum, srcnum, destX, destY, srcX, srcY, width, height, opaque) - Copy image part with merge
srcnum – Image handle (number) to copy from [0 - 10]
destnum – Image handle (number) to copy to [0 - 10]
(destX, destY)– destination coordinates to place a part of source image from (srcX, srcY) with specified width and height
width – integer. Image width
height – integer. Image height
opaque – integer [0..100]. Opaque level
CopyImageResize (destnum, srcnum, destX, destY, scrX, srcY, destWidth, destHeight, srcWitdh, srcHeight) - Copy image part with resize
srcnum – Image handle (number) to copy from [0 - 10]
destnum
– Image handle (number) to copy to [0 - 10]
(destX, destY)– coordinate of destination image to place a part of source image beginning in (srcX, srcY) with specified srcWidth and srcHeight
destWidth
, destHeight– width and height of destination image. Image is resized if srcWidth != destWidth or srcHeight != destHeight
CopyImageRotate (destnum,srcnum,angle)
Rotate source image and copy to a new image. The new image will be created automatically. The color of background can be set with SetColor method. New image dimensions will be changed to accommodate rotated image.
srcnum - Image handle (number) to copy from [0 - 10]
destnum
- Image handle (number) to copy to [0 - 10]
angle - angle to rotate image
CopyImageSimpleRotate (destnum,srcnum,dstX,dstY,scrX,srcY,Witdh,Height) - Rotate source image and copy to a new image. The new image should exist. This method uses different algorithm to rotate images.
srcnum - Image handle (number) to copy from [0 - 10]
d
estnum - Image handle (number) to copy to [0 - 10]
(destX, destY) - coordinates of center of the rotated copy
(srcX, srcY) - coordinates of upper left corner of the source image.
angle - angle to rotate image
CreateImage (width, height) - Allocate memory and create image in internal format
width – integer. Image width
height
– integer. Image height
CreateImagePalette (width, height)  – Creates palette (256 color table)
width – integer. Image width
height
– integer. Image height
DestroyImage - Destroy active image that was specified in a call to SetImage and clean up the memory. By default the image with 0 handle is destroyed.
Returns True is a image destroyed succsesfully
DrawArc (cx, cy, w, h, s, e) - Draw Arc
cx,cy – arc center coordinate
w,h
– arc width and height
s,e
– start and end angles [0 – 360]

Sample


Dim im
Set im = CreateObject("ActiveImage.Images.1")
im.CreateImage 150,150
im.SetColor 255,255,255
im.Fill 0,0
im.SetColor 0,0,0
im.DrawArc 100,100,120,100,180,270
im.SetFont 3
im.DrawText 10,10, "cx=100, cy=100 "
im.DrawText 10,20, "w=120, h=100"
im.DrawText 10,30, "s=180, e=270"
 
im.WriteToFile "C:\arc.png"
im.SetImageType 1
im.SetJpegQuality 100
im.WriteToFile "C:\arc.jpg"
im.DestroyImage
Set im = Nothing


Picture 2.
DrawEllipse (cx,cy, w, h, s, e) - Draw Ellipse
cx,cy – ellipse center coordinate
w,h –ellipse width and height
s,e – start and end angles [0 – 360]
DrawFilledArc (cx, cy, w, h, s, e) - Draw filled arc (can be used to create pie charts)
cx,cy – arc center coordinate
w,h – arc width and height
s,e – start and end angle [0 – 360]
DrawFilledEllipse (cx, cy, w, h, s, e) - Draw filled ellipse (can be used to create charts)
cx,cy – ellipse center
w,h – ellipse height and width
s,e – start and end angles [0 – 360]
DrawFilledPolygon (coords, num) - Draw filled polygon
coords – one dimension array that specifies all coordinate pairs. First value (X1) should be placed in the array element with zero index
num – Number of points (x,y pairs). This value shouldn't be greater than 1998.

Sample


Dim im
Dim coords(100)
Set im = CreateObject("ActiveImage.Images.1")
im.CreateImage 100,100
im.SetColor 255,255,255
im.Fill 0,0
im.SetColor 255,0,0
coords(0) = 10
coords(1) = 10
coords(2) = 80
coords(3) = 10
coords(4) = 45
coords(5) = 55
im.DrawFilledPolygon coords, 6
im.WriteToFile "C:\three.png"
im.SetImageType 1
im.SetJpegQuality 100
im.WriteToFile "C:\three.jpg"
im.DestroyImage
Set im = Nothing


Picture 3.
DrawFilledRectangle (x1,y1,x2,y2)- Draw filled rectangle
x1,y1,x2,y2 – coordinates of upper left and lower right rectangle corners. DrawFilledRectangle draws with active foreground color and you should use SetColor method if you want to change it.
DrawLine (x1,y1,x2,y2) - Draw line
x1,y1,x2,y2 - coordinates of the end and start line points. Line thickness can be set using SetLineThickness method. DrawLine draws with active foreground color and you may change it calling SetColor method.
DrawPolygon (coords, num) - Draw polygon
coords – one dimension array that specifies all coordinate pairs. First value (X1) should be placed in the array element with zero index
num – Number of points (x,y pairs). The value shouldn't be greater than 1998 [0..1998].
DrawRectangle (x1,y1,x2,y2) - Draw rectangle
x1,y1,x2,y2 – coordinates of upper left and lower right rectangle corners. DrawRectangle draws with active foreground color and you should use SetColor method if you want to change it. Line thickness can be set in a call to SetLineThickness method.
DrawText (x,y,text) - Draw text
x,y – define start point for text output.
text – text string to draw
DrawTextAngle (x, y, angle, text) - Draw text with angle
x,y – define start point for text output..
angle – text slope [0..360]
text
– text string to draw
DrawTextAngleTTF (x,y,angle,text)–  Draw text with selected angle and TrueType font.
x,y – define start point for text output..
angle – text slope [0..360]
text
– text string to draw
DrawTextTTF (x,y,text)– Draw text with selected TrueType font
x,y – define start point for text output..
text – text string to draw
Fill (x,y) - Color fill (changing color on another)
Fill method replaces all points of the same color adjacent to start point (x,y) on active foreground color.
x,y – fill start point
You can change the color with SetColor. This method may be useful to change black background after image creation.
GetColorAlpha Get alpha channel value of active foreground color
GetColorBlue Get blue value of active foreground color
GetColorGreen Get green value of active foreground color
GetColorTotal Return total number of colors used. Works only for palletized images.
GetColorRed Get red value of active foreground color
GetFont Get font style for text output operations
Returns active font style for text output operations
0 - Small
1- MediumBold
2 - Large
3 - Tiny
4 - Giant

Sample

Dim im
‘ Define object variable
Set im = CreateObject("ActiveImage.Images.1") ‘ Create object
im.CreateImage 150,75 ‘ Create image with specified width and height
im.SetColor 191,255,255 ‘ Set foreground color in RGB format (white)
im.Fill 0,0 ‘ Fill from the current point with foreground color
im.SetColor 0,0,0 ‘ Set foreground color in RGB format (black)
im.SetFont 0 ‘ Set font number to 0 (Small)
im.DrawText 10,10, "Small - (default) " & im.GetFont ‘ Draw text and the number of active font
im.SetFont 1
im.DrawText 10,20, "Medium Bold - " & im.GetFont
im.SetFont 2
im.DrawText 10,30, "Large - " & im.GetFont
im.SetFont 3
im.DrawText 10,44, "Tiny - " & im.GetFont
im.SetFont 4
im.DrawText 10,50, "Giant - " & im.GetFont
im.WriteToFile "C:\font.png" ‘ Save Image to file. Default type 0 corresponds to PNG format.
im.SetImageType 1 ' Set Jpeg format
im.SetJpegQuality 100 ‘ Set Jpeg quality
im.WriteToFile "C:\font.jpg"
im.DestroyImage ‘ Delete image and free memory
Set im = Nothing ‘ Clear the variable
Picture 4.

GetHeight Get image height
Returns image height
For example you may determine image height after image read operation and resize the image if necessary.
GetImage Get image handle
Returns the number of active image. [0..10]. You can set active image in a call to SetImage.
GetImageType Get image format (PNG, Jpeg)
Returns active image format (0 – PNG , 1 – Jpeg). You can set image format with SetImageType. Image format is used only for import/export operations.
GetInterlace returns true if image is interlaced
GetJpegQuality Get Jpeg quality value
Return default value or the value set with SetJpegQuality.
You can set necessary Jpeg quality if you save the image in Jpeg format to variable, database or file in a call to SetJpegQuality.
GetLineThickness Get current line thickness (used in DrawLine, etc)
GetPixelAlpha (x,y)  Gets the value of alpha channel component of the color
GetPixelBlue (x,y) Get blue value for a pixel
Returns blue component of a pixel at (x,y) coordinate. B (RGB) [0..255]
GetPixelGreen (x,y) Get green value for a pixel
Returns green component of a pixel at (x,y) coordinate. G (RGB) [0..255]
GetPixelRed (x,y) Get red value for a pixel
Returns red component of a pixel at (x,y) coordinate. R (RGB) [0..255]
GetTextTTFRectangle Get text string dimensions
Returns variant array [1,4]
GetTransparent Returns true if image is transparent
GetTrueColor (filename) Returns true if image is in TrueColor
GetWidth Get image width
Returns image width
For example you may determine image height after image read operation and resize the image if necessary.
ReadFromDatabase (AdoRecordset)- Read image from database
Use ADO for database access.
Methods DAO (for MS Access) are not supported yet.
You need to have open recordset with cursor 2 (adOpenDynamic) and blocking type 3 (adLockOptimistic).
ReadFromFile (namefile) Read image from file
namefile – file name (can include file path) For example, ReadFromFile “C:\test.png”
By default, ReadFromFile reads image in PNG format. If you want to read Jpeg image, you need to call SetImageType 1 before calling ReadFromFile. ( 0 – PNG, 1 – Jpeg)
ReadFromVariable (var) Read image from variable
var – variable of Variant type.
You can save image in variable using WriteToVariable. By default ReadFromVariable reads image in PNG format. If you want to read Jpeg image, you need to call SetImageType 1 before calling ReadFromVariable. ( 0 – PNG, 1 – Jpeg)

Sample

Shows how to read image from calling program variable. You can upload the image from the client side in the same way, process it memory and save back without the creation of any temporary files.

<%
‘up.asp
Dim a, fs, pth, fname, BinArray, im
fname = "copyrose.jpg"
pth = Server.MapPath(".") & "\"
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.OpenTextFile(pth & fname, 1, 0)
Do while not a.AtEndOfStream
BinArray = BinArray & chrB(asc(a.Read(1)))
Loop
a.Close
 
Set im = CreateObject("ActiveImage.Images.1")
im.SetImageType 1
im.ReadFromVariable (BinArray)
response.write "<br>"
response.write "height = " & im.GetHeight
response.write "<br>"
response.write "width = " & im.GetWidth
im.DestroyImage
Set im = Nothing
%>


SetAlphaBlending (newval)–Enables/Disables alpha blending. Value 1 turns alpha lending mode on when each next element of the image will be drawn ith a value of transparency. See Alpha Blending Sample.
SetAlphaColor (r,g,b,a)   New method to set color with alpha channel. For palletized image any non-zero value will result in setting this color as transparent. For example if you draw a filled rectangle with alpha value set to 1 on a palletized image, you will get transparent box. See image transparency sample.
 integer r [0..255]   - set red component
 integer g [0..255]  - set green component
 integer b [0..255]  - set blue component
 integer a [0..127]  - set alpha channel component. 0 - image is opaque. 127 - image is fully transparent. 64 - image is half tranparent.
SetColor (R,G,B) Set foreground color
R - red image component [0..255]
G
- green image component [0..255]
B
- blue image component [0..255]

Different drawing operations (like DrawText, DrawRectangle, DrawLine, Fill etc) will be made with this active foreground color.

Sample colors:

255,255,255 – white color
0,0,0 – black color
255,0,0 – red color
0,0,255 – blue color
127,127,127 – grey color

SetColorByIndex (n)  Set color from already created color table (palette). n - color number/index in the color table.
SetFont (num) - Select current font
Set active font style
0 - Small (default)
1- MediumBold
2 - Large
3- Tiny
4 - Giant

For more information you may check out the GetFont sample.
SetFontPathTTF (str)–Set path to the TrueType font directory.
SetFontPathTTFAuto   Set path to TrueType font automatically. For example if Windows NT/2000 has been installed to C:\winnt, then the path is C:\Winnt\Fonts
SetFontSizeTTF (size) Set true type font size
SetFontTTF (str) –Set true type font name. For example, "verdana".
SetImage (num) - Select active image
Set active image. All image operations will be in progress with the selected image [0..10]
SetImageType (num) Set image format (PNG, Jpeg)
Set image format for export/import operations (reading/writing file, database, variable)
num : 0 - PNG (default), 1 - Jpeg
If you try to read Jpeg using PNG format converter, error exception "No Image!" will be thrown. If you want to handle errors in VBScript you need to run “On Error Resume Next” command before calling SetImageType method
SetJpegQuality (quality) Set Jpeg quality value
integer quality [0..100]
You can set necessary Jpeg quality if you save the image in Jpeg format to variable, database or file.
SetLineThickness (width) Set line thickness for simple draw operations
Positive integer width (positive), default = 1
Sets line thickness in pixels for common draw methods (DrawLine, DrawPolygon, DrawArc, etc).
SetPixel (x,y) -Set pixel
Draw a pixel in (x,y) coordinate with active foreground color.
SetSaveAlpha (newval)  Enable/Disable saving alpha channel color information. See SaveAlpha Sample
Value 1 sets the mode when alpha channel information will be saved in image
SetTextAntialias (num) Sets text antialiasing for palette images
Num:
1 – turn on text antialiasing
0 – turn off text antialiasing
SetTransparent (num) Set current color as transparent
Num:
1 – turn on image transparency
0 – turn off image transparency
WriteToDatabase (AdoRecordset) Write image to database
Use ADO for database access. Methods DAO (for MS Access) are not supported yet.
You need to have open recordset with cursor 2 (adOpenDynamic) and blocking type 3 (adLockOptimistic).
WriteToFile (namefile) –Write image to file
You need to specify image type (call SetImageType) if you want to change image format
WriteToVariable (var)–Write image to variable (can be also used to write image directly to browser data stream)
var –variable has VARIANT type. You may also need to specify image format in a call to SetImageType (num)
WriteToVariableVariant (var) –Write image to variable (can be also used to write image to OleLoadPicture in VC++)
var –variable has VARIANT type. You may also need to specify image format in a call to SetImageType (num)


Error handling

If you want to catch errors returned from the component, you have to enable it in ASP/VBScript code, adding “On Error Resume Next”. The component throws the following exceptions:

  1. No image. It may happen when (a) you draw on the NULL image object. Check if you called CreateImage before calling draw methods(b) When you save empty image to file/database/variable (c) You deleted image with DestroyImage or tried to call SetImage with wrong image number (d) You try to load the image of wrong format or set incorrect format in a call to SetImageType.


  2. Invalid parameter. The passed parameters may have wrong type, incorrect value (blue color component is greater than 255 or negative color for example) Also this error may be thrown when you try to create image larger than (5000x5000 pixels) or specify more than 1998 polygon vertexes.


  3. No font. The path to TrueType directory is invalid. You can try to use SetFontPathTTFAuto method instead of SetFontPathTTF.  Also font name can be invalid for your system. For example if you call SetFontTTF verdana.ttf - you need to give font name, instead of file name with extensions

  TonecPrivacy Policy
  ��1999-2007. Tonec, Inc. All rights reserved.