Drawing, Graphics, and Images VB6: Difference between revisions

From Free Knowledge Base- The DUCK Project
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 14: Line 14:
=== PaintPicture ===
=== 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.  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.
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
  object.PaintPicture source, x1, y1, w1, h1, x2, y2, w2, h2, opcode
Line 34: Line 34:
   BitBlt Me.hDC, 0, 0, picBitBlt.ScaleWidth, picBitBlt.ScaleHeight, picBitBlt.hDC, 0, 0, vbSrcCopy
   BitBlt Me.hDC, 0, 0, picBitBlt.ScaleWidth, picBitBlt.ScaleHeight, picBitBlt.hDC, 0, 0, vbSrcCopy
  End Sub
  End Sub
=== Steps to Smooth Animation ===
''Summary:''
# Load Images (Mask and Sprite)
:# Load into PictureBox then use BitBlt -or-
:# Load into memory DC then use BitBlt (less memory, time, and resource)
# Place the Mask (2 color)
# Place the Sprite Raster Image (visible part of image)
# Me.Refresh
:# Optional use Back Buffer (flickers more on small images)
:# Optional use StretchBlt to resize Sprite





Revision as of 00:07, 11 February 2008

VB6 Controls and Methods

PictureBox: Picture Box Control

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

Draw

  • 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)
  1. Place the Mask (2 color)
  2. Place the Sprite Raster Image (visible part of image)
  3. Me.Refresh
  1. Optional use Back Buffer (flickers more on small images)
  2. Optional use StretchBlt to resize Sprite