Difference between revisions of "Drawing, Graphics, and Images VB6"

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search
m
Line 6: Line 6:
  
 
=== Draw ===
 
=== Draw ===
 +
The graphical methods and properties which VB supports native:
  
*               Rectangle 100,100,200,200
+
METHODS
*              Ellipse 110,110,190,190
+
* Circle - draws a circle or an ellipse
*              RoundRect 220,300,350,400
+
* Cls - clears all graphics
*              Line 250,400,500,400
+
* Line - draws a straight line
 +
* PaintPicture - draws the contents of a graphics file
 +
* Point - returns the color of a point
 +
* Print - used for printing text
 +
* Pset - sets the color of a specific pixel
 +
 
 +
PROPERTIES
 +
* AutoRedraw - Determines if graphics are automatically redrawn if something moves in front of them
 +
* ClipControls - Determines how repainting of graphics is handled
 +
* DrawMode - Sets the appearance of a graphics method
 +
* DrawStyle - Sets the line style for output from graphics methods
 +
* DrawWidth - Sets the line width for output from graphics methods
 +
* FillColor - Sets the color used to fill circles, lines and boxes
 +
* FillStyle - Sets the pattern used to fill circle, lines and boxes
 +
* FontTransparent - Determines if the font is printed with a transparent background
 +
* Palette - Sets the image containing the palette to use for a control
 +
* PaletteMode - Determines which palette to use for the controls on a object
 +
* RightToLeft - Indicates the text display direction.
 +
* ScaleHeight - Sets the height of the client area
 +
* ScaleLeft - Sets the starting value of the left of the client area
 +
* ScaleTop - Sets the starting value of the top of the client area
 +
* ScaleWidth - Sets the width of the client area
 +
* ScaleMode - Sets the units of the scale
 +
 
 +
  Rectangle 100,100,200,200
 +
  Ellipse 110,110,190,190
 +
  RoundRect 220,300,350,400
 +
  Line 250,400,500,400
  
 
=== PaintPicture ===
 
=== PaintPicture ===

Revision as of 07:30, 11 February 2008

VB6 Controls and Methods

PictureBox: Picture Box Control

 pMainShip.Picture = LoadPicture(Trim(App.Path) & "\" & "sc001.bmp")

Draw

The graphical methods and properties which VB supports native:

METHODS

  • Circle - draws a circle or an ellipse
  • Cls - clears all graphics
  • Line - draws a straight line
  • PaintPicture - draws the contents of a graphics file
  • Point - returns the color of a point
  • Print - used for printing text
  • Pset - sets the color of a specific pixel

PROPERTIES

  • AutoRedraw - Determines if graphics are automatically redrawn if something moves in front of them
  • ClipControls - Determines how repainting of graphics is handled
  • DrawMode - Sets the appearance of a graphics method
  • DrawStyle - Sets the line style for output from graphics methods
  • DrawWidth - Sets the line width for output from graphics methods
  • FillColor - Sets the color used to fill circles, lines and boxes
  • FillStyle - Sets the pattern used to fill circle, lines and boxes
  • FontTransparent - Determines if the font is printed with a transparent background
  • Palette - Sets the image containing the palette to use for a control
  • PaletteMode - Determines which palette to use for the controls on a object
  • RightToLeft - Indicates the text display direction.
  • ScaleHeight - Sets the height of the client area
  • ScaleLeft - Sets the starting value of the left of the client area
  • ScaleTop - Sets the starting value of the top of the client area
  • ScaleWidth - Sets the width of the client area
  • ScaleMode - Sets the units of the scale
 Rectangle 100,100,200,200
 Ellipse 110,110,190,190
 RoundRect 220,300,350,400
 Line 250,400,500,400

PaintPicture

Copy an image from a control such as a PictureBox and put it anywhere on a form. Useful for animation. BitBlt does the same thing as PaintPicture but faster. BitBlt discussed later. Under Windows 98 and ME programmers find Bitblt is basically equal in speed to paintpicture when using the .picture method of a picture box. Bitlblt is faster when using the .image property of picture box control with paintpicture. Under Windows XP, Bitblt out performs PaintPicture using either property.

object.PaintPicture source, x1, y1, w1, h1, x2, y2, w2, h2, opcode


 

Animation and API Calls

BitBlt

Option Explicit

Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Private Sub cmdBitBlt_Click()
  Me.Cls
  BitBlt Me.hDC, 0, 0, picBitBlt.ScaleWidth, picBitBlt.ScaleHeight, picBitBlt.hDC, 0, 0, vbSrcCopy
End Sub

Steps to Smooth Animation

Summary:

  1. Load Images (Mask and Sprite)
    1. Load into PictureBox then use BitBlt -or-
    2. Load into memory DC then use BitBlt (less memory, time, and resource)
  2. Oscillator
    1. Use a Timer Control -or-
    2. Throttle technique (looping continously)
  3. Place the Mask (2 color)
  4. Place the Sprite Raster Image (visible part of image)
  5. Me.Refresh
    1. Optional use Back Buffer (flickers more on small images)
    2. Optional use StretchBlt to resize Sprite