图 像 缩 放 显 示 的 基 本 原 理 就 是 把 原 图 像 的 一 部 分 缩 放 后 再 送 入 窗 口 的 图 形 容 器 控 件 中, 在VB 中 可 用 内 部 命 令PaintPicture 来 进 行, 语 法 格 式 为: PaintPicture Pic,DestX,DestY,DestWidth,
DestHeight,ScrX,ScrY,ScrWidth,ScrHeight---- 其 中,Pic 为 图 片 对 象, 如 图 形 控 件 对 象 等; DestX,DestY为目标图像起始坐标;
DestWidth,DestHeight为目标图像幅面尺寸;
ScrX,ScrY为源图像起始坐标;
ScrWidth,ScrHeight为源图像剪裁尺寸。---- 该 命 令 就 是 把 一 个 源 图 像 资 源 任 意 复 制 到 指 定 的 区 域, 其 功 能 相 当 于API 函 数 的BitBlt, 但 使 用 更 简 单, 若 复 制 时 改 变 源 图 像 的ScrWidth,ScrHeight 或 目 标 图 像 的DestWidth,DestHeight 可 使 复 制 后 的 图 像 尺 寸 发 生 变 化, 实 现 窗 口 图 像 的 缩 放 显 示。 若ScrWidth,ScrHeight 或DestWidth,DestHeight 为 负 值 还 可 实 现 窗 口 图 像 的 水 平、 垂 直 反 转 显 示。 因 此, 在 把 源 图 像 送 入 目 标 图 形 容 器 控 件 时, 若 改 变 源 图 像 的 幅 面 尺 寸, 即 可 实 现 图 像 的 缩 放 处 理。 

解决方案 »

  1.   

    我有一段純粹用兩個picture和paint做的圖片縮放例子,帶滾動條,無多次縮放圖象損失
    代碼如下任意指定一個圖片給圖片框p2就可以對該圖片操作VERSION 5.00
    Begin VB.Form Form1 
       Caption         =   "Form1"
       ClientHeight    =   7650
       ClientLeft      =   60
       ClientTop       =   345
       ClientWidth     =   11340
       LinkTopic       =   "Form1"
       LockControls    =   -1  'True
       ScaleHeight     =   7650
       ScaleWidth      =   11340
       StartUpPosition =   3  'Windows Default
       Begin VB.CommandButton Command2 
          Caption         =   "++"
          Height          =   330
          Left            =   8415
          TabIndex        =   6
          Top             =   2430
          Width           =   825
       End
       Begin VB.Frame Fr1 
          Height          =   4965
          Left            =   180
          TabIndex        =   1
          Top             =   315
          Width           =   7845
          Begin VB.HScrollBar HS1 
             Height          =   240
             LargeChange     =   40
             Left            =   45
             SmallChange     =   20
             TabIndex        =   5
             Top             =   4680
             Visible         =   0   'False
             Width           =   7485
          End
          Begin VB.VScrollBar VS1 
             Height          =   4785
             LargeChange     =   40
             Left            =   7515
             SmallChange     =   20
             TabIndex        =   4
             Top             =   135
             Visible         =   0   'False
             Width           =   285
          End
          Begin VB.PictureBox p1 
             AutoSize        =   -1  'True
             Height          =   3570
             Left            =   4680
             Picture         =   "Form1.frx":0000
             ScaleHeight     =   3510
             ScaleWidth      =   2175
             TabIndex        =   3
             Top             =   270
             Visible         =   0   'False
             Width           =   2235
          End
          Begin VB.PictureBox P2 
             AutoRedraw      =   -1  'True
             AutoSize        =   -1  'True
             BorderStyle     =   0  'None
             Height          =   4605
             Left            =   45
             ScaleHeight     =   4605
             ScaleWidth      =   7485
             TabIndex        =   2
             Top             =   135
             Width           =   7485
          End
       End
       Begin VB.CommandButton Command1 
          Caption         =   "--"
          Height          =   330
          Left            =   8415
          TabIndex        =   0
          Top             =   1620
          Width           =   780
       End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = FalsePrivate Sub Command1_Click()
    P2.Left = Fr1.Width
    P2.Width = P2.Width * 0.8
    P2.Height = P2.Width * 0.8P2.Left = (Fr1.Width - P2.Width) / 2
    P2.Top = (Fr1.Height - P2.Height) / 2
    P2.PaintPicture p1.Picture, 0, 0, P2.ScaleWidth, P2.ScaleHeightP2.Picture = P2.Imageinit_vshs
    End SubPrivate Sub Command2_Click()
    P2.Left = Fr1.Width
    P2.Width = P2.Width * 1.2
    P2.Height = P2.Height * 1.2P2.Left = (Fr1.Width - P2.Width) / 2
    P2.Top = (Fr1.Height - P2.Height) / 2
    P2.PaintPicture p1.Picture, 0, 0, P2.ScaleWidth, P2.ScaleHeightP2.Picture = P2.Image
    init_vshs
    End SubPrivate Sub init_vshs()
    If P2.Width > Fr1.Width Then
        HS1.Visible = True
        HS1.Max = P2.Width - Fr1.Width
    Else
        HS1.Visible = False
    End IfIf P2.Height > Fr1.Width Then
        VS1.Visible = True
        VS1.Max = P2.Height - Fr1.Height
    Else
        VS1.Visible = False
    End IfEnd SubPrivate Sub HS1_Change()
    P2.Left = -HS1.Value
    End SubPrivate Sub P2_Click()End SubPrivate Sub VS1_Change()
    P2.Top = -VS1.Value
    End Sub
      

  2.   

    首先多谢这位仁兄的精彩回答,但我还有个小问题,我想把桌面移入
    PictureBox中,我想在PictureBox中能看到整个桌面,而且这时的
    PictureBox中不是静态的图像,而是一个窗口,里面的图像就是一个
    真正的桌面元素一样可以真正的操作,那应该如何缩放?是不是完全
    没有影响?