This page explains some of the drawing and editing functions of csImageFile. For a description of each command, refer to the instructions. We will try to cover some of the issues here that can cause confusion.
The following classic ASP code shows the effect of the PenColor, PenThickness, BrushColor and BrushStyle properties.
Image.NewImage 200, 200, "FFFFFF"
Image.Rectangle 10, 10, 90, 90
Image.PenColor = "FF0000"
Image.PenThickness = 5
Image.BrushColor = "0000FF"
Image.BrushStyle = 0
Image.Rectangle 110, 10, 190, 90
Image.PenThickness = 1
Image.Line 0, 100, 100, 199
Image.Line 100, 199, 199, 100
Image.BrushColor = "00FF00"
Image.FloodFill 10, 190
The first rectangle is drawn using the default settings for the pen and brush, which gives a black line one pixel wide and a clear background. For the second rectangle the PenThickness is 5 and the BrushColor is blue. The BrushStyle property must also be set to solid (zero) for the shape to be filled with the brush colour.
The PenThickness property is set back to 1 to draw the lines. Note that although the image is 200 pixels square, the coordinates range from 0 to 199. Also, when drawing with the Line command the destination pixel is not filled in.
The FloodFill command is used to fill an area with BrushColor. It fills all adjoining pixels that are the same colour. It does not fill adjoining pixels that are a similar colour, they must be exactly the same. This makes it unsuitable for filling areas on JPEGs where the colours are not continuous. The alternative fill command is FillToBorder which fills an area enclosed by a specified colour and this can be used for areas that are not a continuous colour although there must be an enclosing border to the area filled.
It is worth mentioning this property because it can be useful. It returns the colour of the pixel at X, Y and can also be set to change individual pixel colours. If, for example, it is known that the pixel at (0, 0) is the colour of the entire image background it could be used to set transparency:
Image.TransparentColor = Image.Pixel(0, 0)
Image.Transparent = true
The Pixel property is slow and should not be used to draw or fill large numbers of pixels. csImageFile provides the PixelArray property which returns an entire row of pixels as a variant array, and this is a much faster method of working with the raw pixel data but it is difficult to use in VBScript.
© Chestysoft, 2017.