*ImageLib*

Back to the start
Back to the libraries overview


Overview (ImageLib)
Overview (ImageLib - Drawer)
DrawEllipse (ImageLib - Drawer)
DrawImage1 (ImageLib - Drawer)
DrawLine (ImageLib - Drawer)
DrawRectangle (ImageLib - Drawer)
DrawRectangle2 (ImageLib - Drawer)
DrawString1 (ImageLib - Drawer)
DrawString2 (ImageLib - Drawer)
FillEllipse (ImageLib - Drawer)
FillRectangle (ImageLib - Drawer)
FillRectangle2 (ImageLib - Drawer)
New1 (ImageLib - Drawer)
New2 (ImageLib - Drawer)
Refresh (ImageLib - Drawer)
Refresh2 (ImageLib - Drawer)
SetTransparentColor1 (ImageLib - Drawer)
StringHeight (ImageLib - Drawer)
StringWidth (ImageLib - Drawer)
Overview (ImageLib - Bitmap)
GetPixel1(ImageLib - Bitmap)
Height (ImageLib - Bitmap)
New1 (ImageLib - Bitmap)
New2 (ImageLib - Bitmap)
New3 (ImageLib - Bitmap)
SetPixel (ImageLib - Bitmap)
Value (ImageLib - Bitmap)
Width (ImageLib - Bitmap)
Overview (ImageLib - Brush)
Color (ImageLib - Brush)
New1 (ImageLib - Brush)
Value (ImageLib - Brush)
Overview (ImageLib - Pen)
Color (ImageLib - Pen)
New1 (ImageLib - Pen)
Value (ImageLib - Pen)
Overview (ImageLib - Rectangle)
Height (ImageLib - Rectangle)
New1 (ImageLib - Rectangle)
Value (ImageLib - Rectangle)
Width (ImageLib - Rectangle)
X (ImageLib - Rectangle)
Y (ImageLib - Rectangle)


Overview (ImageLib) Top

The ImageLib library extends the support for drawings and images.
The library includes five types of objects:
- Drawer - The main object, includes methods for drawing on other images.
- Bitmap - Bitmaps are images loaded from image files or newly created.
- Brush - Brushes are graphic objects which are used when filling shapes (eg: FillRectangle).
- Pen - Pens are graphic objects which are used when drawing shapes (eg: DrawRectangle).
- Rectangle - Rectangle objects represent a set of four points (organized as a rectangle) and are used in other drawing methods. It is more efficient to use rectangles than using four points each time.

Example:
'Add a Bitmap object named bitmap1, Brush object named brush1, a Drawer object named drawer and a Rectangle object named rect1.
Sub Globals

End Sub

Sub App_Start
Form1.Show
bitmap1.New2(100,100)
rect1.New1(0,0,bitmap1.Width,bitmap1.Height)
drawer.New2(bitmap1.Value, b4pObject(5)) 'The drawer will draw on bitmap1
brush1.New1(cGold)
drawer.FillRectangle(brush1.Value,rect1.Value)
brush1.Color = cBlue
rect1.Width = 40
drawer.FillEllipse(brush1.Value,rect1.Value)
form1.DrawImage(bitmap1.Value,10,10) 'Draws bitmap1 on form1
End Sub


Overview (ImageLib - Drawer) Top

Drawer objects draw on other images or directly on forms.
When initializing a Drawer object, the image is passed as one of the arguments.
Unlike the built-in drawing methods in Basic4ppc, when drawing on forms using Drawer the changes will only appear after refreshing the form.
Drawer includes two Refresh methods which allow refreshing a part of the form.
Drawer also includes transparent support.
For better performance it is better to make all the drawings and only then refresh the form.


DrawEllipse (ImageLib - Drawer) Top

Draws an ellipse on the image.
Syntax: DrawEllipse (pen As Pen, rect As Rectangle)

Example:
'Add a Drawer object named drawer, a Pen object named pen1 and a Rectangle object named rect1.


Sub App_Start
Form1.Show
drawer.New1("Form1",false)
rect1.New1(20,20,40,80)
pen1.New1 (cBlue)
drawer.DrawEllipse(pen1.Value,rect1.Value)
drawer.Refresh2(rect1.Value)
End Sub


DrawImage1 (ImageLib - Drawer) Top

Draws part of an image on another image.
Syntax: DrawImage1 (image As Image, rectSrc As Rectangle, rectDest As Rectangle, transparent As Boolean)


image - The source image.
rectSrc - The part taken from the source image.
rectDest - The area on the target image which the image will be drawn to.
transparent - If true then the the color set with Drawer.SetTransparentColor1 will be transparent.
Example:
'Add a Drawer object named drawer, a Rectangle object named rectSrc ,a Rectangle object named rectDest and a Bitmap object named bmpSrc.
Sub Globals

End Sub

Sub App_Start
Form1.Show
drawer.New1("Form1",false)
brush1.New1(cRed)
bmpSrc.New1(AppPath & "\smiley.gif") 'Loads an image from a file named smiley.gif
rectSrc.New1(0,0,bmpSrc.Width,bmpSrc.Height) 'Same size as the image.
rectDest.New1(100,100,25,25)
drawer.SetTransparentColor1(bmpSrc.GetPixel1(0,0)) 'Sets the transparent color to be the color of pixel (0,0) in the bitmap
drawer.DrawImage1(bmpSrc.Value,rectSrc.Value,rectDest.Value,true)
drawer.Refresh2(rectDest.Value)
End Sub


DrawLine (ImageLib - Drawer) Top

DrawLine draws a line on the image.
Syntax: DrawLine (pen As Pen, x1 As Int32, y1 As Int32, x2 As Int32, y2 As Int32)

Example:
'Add a Drawer object named drawer and a Pen object named pen1.
Sub App_Start
Form1.Show
drawer.New1("Form1",false)
pen1.New1 (cBlue)
drawer.DrawLine(pen1.Value,150,100,100,50)
drawer.Refresh(100,50,50,50)
End Sub


DrawRectangle (ImageLib - Drawer) Top

Draws a rectangle on the image.
Syntax: DrawRectangle (pen As Pen, rect As Rectangle)

Example:
'Add a Drawer object named drawer, a Pen object named pen1 and a Rectangle object named rect1.
Sub Globals

End Sub

Sub App_Start
Form1.Show
drawer.New1("Form1",false)
rect1.New1(20,20,40,80)
pen1.New1 (cBlue)
drawer.DrawRectangle(pen1.Value,rect1.Value)
drawer.Refresh2(rect1.Value)
End Sub


DrawRectangle2 (ImageLib - Drawer) Top

Draws a rectangle on the image.
Syntax: DrawRectangle (pen As Pen, x As Int32, y As Int32, width As Int32, height As Int32)

Example:
'Add a Drawer object named drawer and a Pen object named pen1.
Sub Globals

End Sub

Sub App_Start
Form1.Show
drawer.New1("Form1",false)
pen1.New1 (cBlue)
drawer.DrawRectangle2(pen1.Value,50,30,100,200)
drawer.Refresh(50,30,100,200)
End Sub


DrawString1 (ImageLib - Drawer) Top

Draws a string on the image.
Syntax: DrawString1 (string As String, FontSize As Single, brush As SolidBrush, x As Single, y As Single)

Example:
'Add a Drawer object named drawer and a Brush object named brush1.
Sub Globals

End Sub

Sub App_Start
Form1.Show
drawer.New1("Form1",false)
brush1.New1(cRed)
drawer.DrawString1("Hello world!!!",10, brush1.Value, 30,30)
drawer.Refresh(30,30,50,30)
End Sub


DrawString2 (ImageLib - Drawer) Top

Draws a string on the image.
Syntax: DrawString2 (string As String, FontSize As Single, brush As SolidBrush, rect As Rectangle)

Example:


'Add a Drawer object named drawer, a Rectangle object named rect1 and a Brush object named brush1.
Sub Globals

End Sub

Sub App_Start
Form1.Show
drawer.New1("Form1",false)
brush1.New1(cRed)
rect1.New1 (30,30,12,200)
drawer.DrawString2("Hello world!!",10, brush1.Value, rect1.Value)
drawer.Refresh2(rect1.Value)
End Sub


FillEllipse (ImageLib - Drawer) Top

Draws a filled ellipse.
Syntax: FillEllipse (brush As SolidBrush, rect As Rectangle)

Example:
'Add a Drawer object named drawer, a Brush object named brush1 and a Rectangle object named rect.
Sub Globals

End Sub

Sub App_Start
Form1.Show
drawer.New1("Form1",false)
brush1.New1(cRed)
rect1.New1(50,50,80,40)
drawer.FillEllipse(brush1.Value,rect1.Value)
drawer.Refresh2(rect1.Value)
End Sub


FillRectangle (ImageLib - Drawer) Top

Draws a filled rectangle on the image.
Syntax: FillRectangle (brush As SolidBrush, rect As Rectangle)
Example:
'Add a Drawer object named drawer, a Brush object named brush1 and a Rectangle object named rect.
Sub Globals

End Sub

Sub App_Start
Form1.Show
drawer.New1("Form1",false)
brush1.New1(cRed)
rect1.New1(50,50,80,40)
drawer.FillRectangle(brush1.Value,rect1.Value)
drawer.Refresh2(rect1.Value)
End Sub


FillRectangle2 (ImageLib - Drawer) Top

Draws a filled rectangle on the image.
Syntax: FillRectangle2 (brush As SolidBrush, x As Int32, y As Int32, width As Int32, height As Int32)

Example:
'Add a Drawer object named drawer and a Brush object named brush1.
Sub Globals

End Sub

Sub App_Start
Form1.Show
drawer.New1("Form1",false)
brush1.New1(cRed)
drawer.FillRectangle2(brush1.Value,50,50,80,40)
drawer.Refresh(50,50,80,40)
End Sub


New1 (ImageLib - Drawer) Top

Initializes a Drawer object.
New1 (unlike New2) is used to draw directly on a form.
Syntax: New1 (FormName As Form, ForeLayer As Boolean)
ForeLayer - If true then the drawer will draw on the forelayer.

Example:
drawer.New1 ("Form1", false)


New2 (ImageLib - Drawer) Top

Initializes the Drawer object.
New2 is used to draw on an image object.
Syntax: New2 (image As Image, B4PObject5 As Object)
image - Can be any image including images stored in ImageLists, Image control, forms or Bitmap objects.
B4PObject5 - Must be B4PObject(5).

Example:
drawer.New2 (ImageList1.Item(0), B4PObject(5))


Refresh (ImageLib - Drawer) Top
Causes the form to refresh part of it (show all changes done).
Syntax: Refresh (x As Int32, y As Int32, width As Int32, height As Int32)


Refresh2 (ImageLib - Drawer) Top
Causes the form to refresh part of it (show all changes done).
Syntax: Refresh2 (rect As Rectangle)
Example:
drawer.Refresh2 (rect.Value)


SetTransparentColor1 (ImageLib - Drawer) Top

Sets the color that will be used as the transparent color when drawing images using Drawer.DrawImage1 method.
Syntax: SetTransparentColor1 (color As Color)


StringHeight (ImageLib - Drawer) Top

Returns the height (number of pixels) of a specified string.
Syntax: StringHeight (string As String, FontSize As Single) As Int32

Example: Draws a string and a rectangle around the string.
'Add a Drawer object named drawer a Brush object named brush1, a Pen object named pen1 and a Rectangle object named rect.
Sub Globals

End Sub

Sub App_Start
Form1.Show
brush1.New1 (cBlack)
pen1.New1 (cBlue)
drawer.New1("Form1",false)
s = "Hello World!"
drawer.DrawString1(s, 12,brush1.Value,10,10)
rect1.New1(8,8, drawer.StringWidth(s,12) + 4, drawer.StringHeight(s,12) + 4)
drawer.DrawRectangle(pen1.Value, rect1.Value)
End Sub


StringWidth (ImageLib - Drawer) Top

Returns the width (number of pixels) of the specified string.
Syntax: StringWidth (string As String, FontSize As Single) As Int32

Example: Draws a string and a rectangle around the string.
'Add a Drawer object named drawer a Brush object named brush1, a Pen object named pen1 and a Rectangle object named rect.
Sub Globals

End Sub

Sub App_Start
Form1.Show
brush1.New1 (cBlack)
pen1.New1 (cBlue)
drawer.New1("Form1",false)
s = "Hello World!"
drawer.DrawString1(s, 12,brush1.Value,10,10)
rect1.New1(8,8, drawer.StringWidth(s,12) + 4, drawer.StringHeight(s,12) + 4)
drawer.DrawRectangle(pen1.Value, rect1.Value)
End Sub


Overview (ImageLib - Bitmap) Top

Bitmap objects represent an image stored in memory.
The Bitmap object can be used for off screen drawing.
The reference for the actual image is returned using the Value property.


GetPixel1(ImageLib - Bitmap) Top

Returns the color of a specific pixel in the image.
Syntax: GetPixel1 (x As Int32, y As Int32) As Color

Example:
drawer.SetTransparentColor1 (bitmap1.GetPixel1 (0,0))


Height (ImageLib - Bitmap) Top

Returns the height of the image.
Syntax: Height
Example:
h = bitmap1.Height


New1 (ImageLib - Bitmap) Top


Initializes the Bitmap object.
Loads an image from a file.
Syntax: New1 (FileName As String)

Example:
bitmap1.New1 (AppPath & "\smiley.gif")


New2 (ImageLib - Bitmap) Top

Initializes the Bitmap object.
Creates a new image with the specified size.
Syntax: New2 (Width As Int32, Height As Int32)
Example:
bitmap1.New2 (100,100)


New3 (ImageLib - Bitmap) Top

Initializes the Bitmap object.
Creates a new image from an existing image.
Syntax: New3 (image As Image)

Example:
bitmap1.New3 (ImageList1.Item(0))


SetPixel (ImageLib - Bitmap) Top

Changes the color of the specified pixel.
Syntax: SetPixel (x As Int32, y As Int32, color As Color)

Example:
bitmap1.SetPixel (5,5, cRed)


Value (ImageLib - Bitmap) Top

Gets (or sets) a reference to the image.
Syntax: Value

Example:
Form1.Image = bitmap1.Value


Width (ImageLib - Bitmap) Top

Returns the width of the image.
Syntax: Width

Example:
w = bitmap1.Width


Overview (ImageLib - Brush) Top

Brushes are graphic objects which are used to draw filled shapes.
To reference the actual brush use the Value property.
Example:
brush1.New1 (cRed)
drawer.FillRectangle (brush1.Value, rect1.Value)


Color (ImageLib - Brush) Top

Gets or sets the color of the brush.
Syntax: Color

Example:
brush1.Color = cBlue

Example:
brush1.Color = RGB (100,124,55)


New1 (ImageLib - Brush) Top

Initializes the Brush object.
Syntax: New1 (color As Color)

Example:
brush1.New1 (cBlue)


Value (ImageLib - Brush) Top

Gets (or sets) a reference to the actual graphic object.
Syntax: Value

Example:
brush1.New1 (cRed)
drawer.FillRectangle (brush1.Value, rect1.Value)


Overview (ImageLib - Pen) Top

Pens are graphic objects which are used to draw shapes.
To reference the actual pen use the Value property.
Example:
pen1.New1 (cRed)
drawer.DrawRectangle (pen1.Value, rect1.Value)


Color (ImageLib - Pen) Top
Gets or sets the color of the Pen object.
Syntax: Color

Example:
pen1.Color = cGold


New1 (ImageLib - Pen) Top

Initializes the Pen object.
Syntax: New1 (color As Color)

Example:
pen1.New1 (RGB (100,100,255))


Value (ImageLib - Pen) Top

Gets (or sets) the actual graphic object.
Syntax: Value

Example:
pen1.New1 (cRed)
drawer.DrawRectangle (pen1.Value, rect1.Value)


Overview (ImageLib - Rectangle) Top


Rectangles objects store the four points of a rectangle.
These objects are useful in may drawing methods.
To reference the actual object use the Value property.
Example:
Sub App_Start
Form1.Show
drawer.New1("form1",false)
pen1.New1 (cBlue)
rect1.New1 (100,100,50,50)
drawer.DrawRectangle(pen1.Value,rect1.Value)
drawer.Refresh2(rect1.Value)
End Sub


Height (ImageLib - Rectangle) Top

Gets or sets the height of the rectangle.
Syntax: Height

Example:
h = rect1.Height


IntersectsWith (ImageLib - Rectangle)
Checks whether one rectangle intersects with another.
Syntax: IntersectsWith (rect2 As Rectangle) As Boolean

Example:
if rect1.IntersectsWith(otherRect.Value) = true then ...


New1 (ImageLib - Rectangle) Top
Initializes the Rectangle object.
Syntax: New1 (x As Int32, y As Int32, width As Int32, height As Int32)

Example:
rect1.New1 (50,50,100,100)


Value (ImageLib - Rectangle) Top
Gets (or sets) a reference to the rectangle object.
Syntax: Value

Example:
drawer.DrawRectangle(pen1.Value,rect1.Value)


Width (ImageLib - Rectangle) Top

Gets or sets the width of the rectangle.
Syntax: Width

Example:
rect.Width = 200


X (ImageLib - Rectangle) Top

Gets or sets the X coordinate of the top-left point of the rectangle.
Syntax: X

Example:
rect1.X = 50


Y (ImageLib - Rectangle) Top
Gets or sets the Y coordinate of the top-left point of the rectangle.
Syntax: Y

Example:
rect1.Y = 10