home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch3 / CopyDDB.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-04-22  |  5.8 KB  |  201 lines

  1. VERSION 5.00
  2. Begin VB.Form frmCopyDDB 
  3.    Caption         =   "CopyDDB"
  4.    ClientHeight    =   5400
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   5190
  8.    LinkTopic       =   "Form1"
  9.    Palette         =   "CopyDDB.frx":0000
  10.    PaletteMode     =   1  'UseZOrder
  11.    ScaleHeight     =   5400
  12.    ScaleWidth      =   5190
  13.    StartUpPosition =   3  'Windows Default
  14.    Begin VB.PictureBox picTriplet 
  15.       AutoRedraw      =   -1  'True
  16.       AutoSize        =   -1  'True
  17.       Height          =   2355
  18.       Left            =   2640
  19.       ScaleHeight     =   153
  20.       ScaleMode       =   3  'Pixel
  21.       ScaleWidth      =   165
  22.       TabIndex        =   3
  23.       Top             =   2760
  24.       Width           =   2535
  25.    End
  26.    Begin VB.PictureBox picSource 
  27.       AutoRedraw      =   -1  'True
  28.       AutoSize        =   -1  'True
  29.       Height          =   2355
  30.       Left            =   720
  31.       Picture         =   "CopyDDB.frx":20E32
  32.       ScaleHeight     =   153
  33.       ScaleMode       =   3  'Pixel
  34.       ScaleWidth      =   165
  35.       TabIndex        =   0
  36.       Top             =   0
  37.       Width           =   2535
  38.    End
  39.    Begin VB.CommandButton cmdCopy 
  40.       Caption         =   "Copy"
  41.       Default         =   -1  'True
  42.       Height          =   495
  43.       Left            =   3360
  44.       TabIndex        =   2
  45.       Top             =   840
  46.       Width           =   1215
  47.    End
  48.    Begin VB.PictureBox picPSet 
  49.       AutoRedraw      =   -1  'True
  50.       AutoSize        =   -1  'True
  51.       Height          =   2355
  52.       Left            =   0
  53.       ScaleHeight     =   153
  54.       ScaleMode       =   3  'Pixel
  55.       ScaleWidth      =   165
  56.       TabIndex        =   1
  57.       Top             =   2760
  58.       Width           =   2535
  59.    End
  60.    Begin VB.Label Label1 
  61.       Alignment       =   2  'Center
  62.       Caption         =   "Using an RGBTriplet array"
  63.       Height          =   255
  64.       Index           =   1
  65.       Left            =   2640
  66.       TabIndex        =   7
  67.       Top             =   2520
  68.       Width           =   2535
  69.    End
  70.    Begin VB.Label Label1 
  71.       Alignment       =   2  'Center
  72.       Caption         =   "Using Point and PSet"
  73.       Height          =   255
  74.       Index           =   0
  75.       Left            =   0
  76.       TabIndex        =   6
  77.       Top             =   2520
  78.       Width           =   2535
  79.    End
  80.    Begin VB.Label lblDDBTime 
  81.       Alignment       =   2  'Center
  82.       Height          =   255
  83.       Left            =   2640
  84.       TabIndex        =   5
  85.       Top             =   5160
  86.       Width           =   2535
  87.    End
  88.    Begin VB.Label lblPSetTime 
  89.       Alignment       =   2  'Center
  90.       Height          =   255
  91.       Left            =   0
  92.       TabIndex        =   4
  93.       Top             =   5160
  94.       Width           =   2535
  95.    End
  96. Attribute VB_Name = "frmCopyDDB"
  97. Attribute VB_GlobalNameSpace = False
  98. Attribute VB_Creatable = False
  99. Attribute VB_PredeclaredId = True
  100. Attribute VB_Exposed = False
  101. Option Explicit
  102. ' Copy picSource's picture into the result pictures.
  103. Private Sub cmdCopy_Click()
  104. Dim pixels() As RGBTriplet
  105. Dim bits_per_pixel As Integer
  106. Dim X As Integer
  107. Dim Y As Integer
  108. Dim start_time As Single
  109.     ' Blank previous results.
  110.     cmdCopy.Enabled = False
  111.     MousePointer = vbHourglass
  112.     picPSet.Cls
  113.     picTriplet.Cls
  114.     lblPSetTime.Caption = ""
  115.     lblDDBTime.Caption = ""
  116.     DoEvents
  117.     ' Make the PictureBoxes the same size.
  118.     picPSet.Width = picSource.Width
  119.     picPSet.Height = picSource.Height
  120.     picTriplet.Width = picSource.Width
  121.     picTriplet.Height = picSource.Height
  122.     ' Use Point and PSet.
  123.     start_time = Timer
  124.     For Y = 0 To picSource.ScaleHeight
  125.         For X = 0 To picSource.ScaleWidth
  126.             picPSet.PSet (X, Y), picSource.Point(X, Y)
  127.         Next X
  128.     Next Y
  129.     ' Fill some colored boxes to verify that we
  130.     ' can set pixel values correctly.
  131.     For Y = 0 To 20
  132.         For X = 0 To 20
  133.             picPSet.PSet (X, Y), vbRed
  134.         Next X
  135.     Next Y
  136.     For Y = 21 To 40
  137.         For X = 21 To 40
  138.             picPSet.PSet (X, Y), vbGreen
  139.         Next X
  140.     Next Y
  141.     For Y = 41 To 60
  142.         For X = 41 To 60
  143.             picPSet.PSet (X, Y), vbBlue
  144.         Next X
  145.     Next Y
  146.     lblPSetTime.Caption = _
  147.         Format$(Timer - start_time, "0.00") & _
  148.         " seconds"
  149.     DoEvents
  150.     ' Use the RGBTriplet array.
  151.     start_time = Timer
  152.     ' Get picSource's pixels.
  153.     GetBitmapPixels picSource, pixels, bits_per_pixel
  154.     ' Fill some colored boxes to verify that we
  155.     ' can set pixel values correctly.
  156.     For Y = 0 To 20
  157.         For X = 0 To 20
  158.             With pixels(X, Y)
  159.                 .rgbRed = 255
  160.                 .rgbGreen = 0
  161.                 .rgbBlue = 0
  162.             End With
  163.         Next X
  164.     Next Y
  165.     For Y = 21 To 40
  166.         For X = 21 To 40
  167.             With pixels(X, Y)
  168.                 .rgbRed = 0
  169.                 .rgbGreen = 255
  170.                 .rgbBlue = 0
  171.             End With
  172.         Next X
  173.     Next Y
  174.     For Y = 41 To 60
  175.         For X = 41 To 60
  176.             With pixels(X, Y)
  177.                 .rgbRed = 0
  178.                 .rgbGreen = 0
  179.                 .rgbBlue = 255
  180.             End With
  181.         Next X
  182.     Next Y
  183.     ' If this is 8 bit color, make picTriplet use the
  184.     ' same palette as picSource.
  185.     If bits_per_pixel = 8 Then
  186.         picTriplet.Picture = picSource.Picture
  187.     End If
  188.     ' Set picTriplet's pixels.
  189.     SetBitmapPixels picTriplet, bits_per_pixel, pixels
  190.     lblDDBTime.Caption = _
  191.         Format$(Timer - start_time, "0.00") & _
  192.         " seconds"
  193.     MousePointer = vbDefault
  194.     cmdCopy.Enabled = True
  195. End Sub
  196. Private Sub Form_Load()
  197.     Show
  198.     picSource.ZOrder
  199.     picSource.SetFocus
  200. End Sub
  201.