⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 根据图像生成数据
💻 FRM
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1 
   Caption         =   "不规则窗体数据生成器"
   ClientHeight    =   4710
   ClientLeft      =   60
   ClientTop       =   630
   ClientWidth     =   4200
   LinkTopic       =   "Form1"
   ScaleHeight     =   4710
   ScaleWidth      =   4200
   StartUpPosition =   2  '屏幕中心
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   0
      Top             =   0
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
      CancelError     =   -1  'True
      Flags           =   4097
   End
   Begin VB.PictureBox Picture1 
      AutoSize        =   -1  'True
      BorderStyle     =   0  'None
      Height          =   4560
      Left            =   0
      Picture         =   "Form1.frx":0000
      ScaleHeight     =   304
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   192
      TabIndex        =   0
      Top             =   0
      Visible         =   0   'False
      Width           =   2880
   End
   Begin VB.Menu 背景颜色 
      Caption         =   "背景颜色(&D)"
      Begin VB.Menu 背景色 
         Caption         =   "黑色"
         Index           =   0
      End
      Begin VB.Menu 背景色 
         Caption         =   "深蓝色"
         Index           =   1
      End
      Begin VB.Menu 背景色 
         Caption         =   "绿色"
         Index           =   2
      End
      Begin VB.Menu 背景色 
         Caption         =   "青色"
         Index           =   3
      End
      Begin VB.Menu 背景色 
         Caption         =   "咖啡色"
         Index           =   4
      End
      Begin VB.Menu 背景色 
         Caption         =   "紫色"
         Index           =   5
      End
      Begin VB.Menu 背景色 
         Caption         =   "墨绿色"
         Index           =   6
      End
      Begin VB.Menu 背景色 
         Caption         =   "灰色"
         Index           =   7
      End
      Begin VB.Menu 背景色 
         Caption         =   "深灰色"
         Index           =   8
      End
      Begin VB.Menu 背景色 
         Caption         =   "蓝色"
         Index           =   9
      End
      Begin VB.Menu 背景色 
         Caption         =   "浅绿色"
         Checked         =   -1  'True
         Index           =   10
      End
      Begin VB.Menu 背景色 
         Caption         =   "浅蓝色"
         Index           =   11
      End
      Begin VB.Menu 背景色 
         Caption         =   "红色"
         Index           =   12
      End
      Begin VB.Menu 背景色 
         Caption         =   "粉红色"
         Index           =   13
      End
      Begin VB.Menu 背景色 
         Caption         =   "黄色"
         Index           =   14
      End
      Begin VB.Menu 背景色 
         Caption         =   "白色"
         Index           =   15
      End
   End
   Begin VB.Menu 开始 
      Caption         =   "开始(&O)"
   End
   Begin VB.Menu 加载图像 
      Caption         =   "加载图像(&J)"
   End
   Begin VB.Menu 关闭 
      Caption         =   "关闭(&C)"
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

'**********************************************
'* Web URL: http://xxlno2vb.yeah.net          *
'* 作者: xxlno2                               *
'* E-Mail:xxlno2@yeah.net                     *
'*        xxlno2@sina.com                     *
'* 如有问题请来信联系                         *
'* 由于程序还不完善,还请多多指教             *
'* 欢迎来信讨论VB问题。                       *
'**********************************************

'*************不规则窗体数据生成器***
'扫描图像,生成窗体数据,提供生成不规则窗体的需要
'只是生成窗体数据,需要其它程序配合
'注意属性设置 ,不然果有差异

'Picture1.Visible = False
'不要PictureBox控件在窗体上面影响扫描后果
' Picture1.ScaleMode = 3 - Pixel
'Picutre1.Picture 加载所要生成窗体数据的图像
'Picture1.AutoSize = True
'使图片框和图像一样大小
'因为该程序需要图像的像素作扫描图像的单位
'所以Picture1必须使用像素作为测量单位
'调节窗体的大小大于图像大小,这样不会图像扫描不完全
'图像的背景色最好和图像的颜色不相同,用特别的色
'注意: 必需当扫描提示出现才可以关闭程序,否则
'      图像数据会扫描不完全,生成的数据不正确
'************************************************
'声明存放背景色变量
Dim 颜色 As Byte

Private Sub Form_Load()
'把图片框中的图像加载到窗体上
Form1.Picture = Picture1.Picture
'初始化背景颜色 为 浅绿色
'范例的图像的背景颜色为浅绿色
颜色 = 10

End Sub

Private Sub 开始_Click()
Dim Ma As Dat
'生成窗体数据文件
'如果想把数据文件放在其它位置上可以把修改路径
Open "d:\Ma.dat" For Random As #1 Len = Len(Ma)
'扫描图像
For y = 0 To Picture1.ScaleHeight - 1
'初始化变量
Ma.Sx = 0
Ma.Sy = 0
Ma.Ex = 0
Ma.Ey = 0
For x = 0 To Picture1.ScaleWidth - 1
'用函数从窗体中取得一个像素的RGB值
'如果窗体图像的坐标(X,Y)不是背景色并且X坐标变量
'还是空白时,记录区域的X轴开始位置
If GetPixel(Form1.hdc, x, y) <> QBColor(颜色) And Ma.Sx = 0 Then Ma.Sx = x
'当以经记录区域的X轴开始位置并且在非背景色渡过背景
'时记录起区域的结束位置
If GetPixel(Form1.hdc, x, y) = QBColor(颜色) And Ma.Sx <> 0 Then
'记录结束位置
Ma.Ex = x
'记录区域的块数
n = n + 1
'记录区域的Y轴的开始位置
Ma.Sy = y
'因为矩形区域是线形的,所以Y轴的结束位置是在开始
'的Y轴加上1
Ma.Ey = y + 1
'把所测到的窗体数据存放入数据文件
Put #1, n, Ma
'变量化0
Ma.Sx = 0
Ma.Ex = 0
Ma.Ey = 0
Ma.Sy = 0
End If
Next x
Next y
'提示完成图像扫描
MsgBox "完成图像扫描" & Chr(13) & "数据文件大小为:" & LOF(1) & "字节"

'关闭文件
Close #1
End Sub

Private Sub 背景色_Click(Index As Integer)
'设置背景色
'将打上选择的符号取消
For i = 0 To 15
背景色(i).Checked = False
Next
'将被子点击到的选项加上符号
背景色(Index).Checked = True
'背景色的号码为
颜色 = Index
End Sub

Private Sub 关闭_Click()
'关闭生成器程序
Unload Me
End Sub

'加载图像的设置
'通用型对话框控件属性Flags为&H1001
'Filter为图像文件 *.bmp,*.jpg,*.gif,*.ico,*.wmf等
'将通用型对话框控件属性ComcelError 设为True

Private Sub 加载图像_Click()
'当在对话框上按下取消时,不加载图像
 On Error GoTo Er
 ' 设置打开文件的类型
 CommonDialog1.Filter = "位图(*.bmp),Jpg文件|*.bmp;*.jpg"
CommonDialog1.ShowOpen
'把图像加载到窗体和图片框上
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
Form1.Picture = Picture1.Picture
Er:
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -