忘记类定义文件。。。
程序代码:
**************************************************
*-- Class: bmpfile (d:\documents\visual foxpro 项目\myclass.vcx)
*-- ParentClass: struct (d:\documents\visual foxpro 项目\myclass.vcx)
*-- BaseClass: custom
*-- Time Stamp: 04/15/23 09:19:03 PM
*
DEFINE CLASS bmpfile AS struct
*-- 颜色表
colortable = ("")
*-- 位图数据
bitmapdata = ("")
*-- 用来保存bmp文件名。
filename = ""
Name = "bmpfile"
*-- 保存bmp文件。
PROCEDURE save
PARAMETERS cfilename
IF PARAMETERS()=0
cfilename=PUTFILE("","unnamed1","bmp")
IF EMPTY(cfilename)
RETURN .f.
ENDIF
ENDIF
cfilename=IIF(UPPER(RIGHT(cfilename,4))==UPPER(".bmp"),cfilename,cfilename+".bmp")
this.filename=cfilename
cstr=this.bmfheader.getstruct()+this.bmiheader.getstruct()+this.colortable+this.bitmapdata
STRTOFILE(cstr,cfilename,0)
RELEASE cfilename,cstr
RETURN .t.
ENDPROC
*-- 读取bmp文件。
PROCEDURE load
PARAMETERS cfilename
IF PARAMETERS()=0
cfilename=GETFILE("bmp")
IF EMPTY(cfilename)
RETURN .f.
ENDIF
ENDIF
this.filename=cfilename
cstr=FILETOSTR(cfilename)
this.bmfheader.set(SUBSTR(cstr,1,14))
this.bmiheader.set(SUBSTR(cstr,15,40))
IF this.bmfheader.bfoffbits#54
this.colortable=SUBSTR(cstr,55,this.bmfheader.bfoffbits-54)
ENDIF
*this.bitmapdata=SUBSTR(cstr,this.bmfheader.bfoffbits+1,LEN(cstr)-this.bmfheader.bfoffbits)
this.bitmapdata=right(cstr,LEN(cstr)-this.bmfheader.bfoffbits)
RELEASE cfilename,cstr
RETURN .t.
ENDPROC
*-- 新建一个bmp文件。
PROCEDURE new
PARAMETERS nwidth,nheight
this.bmfheader.bftype="BM"
*!* this.bmfheader.bfoffbits=54
this.bmiheader.biwidth=nwidth
this.bmiheader.biheight=nheight
*!* this.bmiheader.bibitcount=32
this.bmiheader.bisizeimage=nwidth*nheight
this.bmfheader.bfsize=LEN(this.colortable)+54+nwidth*nheight*4
this.bitmapdata=REPLICATE(chr(255),nwidth*nheight*4)
this.save
ENDPROC
PROCEDURE Init
this.AddObject("bmfheader","bmfheader")
this.AddObject("bmiheader","bmiheader")
ENDPROC
ENDDEFINE
*
*-- EndDefine: bmpfile
**************************************************
**************************************************
*-- Class: bmfheader (d:\documents\visual foxpro 项目\myclass.vcx)
*-- ParentClass: struct (d:\documents\visual foxpro 项目\myclass.vcx)
*-- BaseClass: custom
*-- Time Stamp: 04/15/23 08:50:04 PM
*
DEFINE CLASS bmfheader AS struct
Height = 25
Width = 155
*-- BMP文件类型,为字符BM,2个字节。
bftype = "BM"
*-- 文件大小,4个字节。
bfsize = 0
*-- 保留字节,2个字节。
bfreserved1 = 0
*-- 保留字节2,2个字节。
bfreserved2 = 0
*-- bitmap文件的图像数据起始位置偏移量,4个字节。
bfoffbits = 54
struct = (repli(chr(0),14))
Name = "bmfheader"
PROCEDURE getstruct
this.struct=this.bftype+BINTOC(this.bfsize,"4rs");
+BINTOC(this.bfreserved1,"2rs");
+BINTOC(this.bfreserved2,"2rs");
+BINTOC(this.bfoffbits,"4rs")
RETURN this.struct
ENDPROC
PROCEDURE set
PARAMETERS cstruct
IF LEN(cstruct)#14
RETURN .f.
ENDIF
this.bftype=SUBSTR(cstruct,1,2)
this.bfsize=;
ASC(SUBSTR(cstruct,3,1))+;
ASC(SUBSTR(cstruct,4,1))*0x100+;
ASC(SUBSTR(cstruct,5,1))*0x10000+;
ASC(SUBSTR(cstruct,6,1))*0x1000000
*!* this.bfreserved1=0 &&不需要设置,默认为零
*!* this.bfreserved2=0 &&不需要设置,默认为零
this.bfoffbits=;
ASC(SUBSTR(cstruct,11,1))+;
ASC(SUBSTR(cstruct,12,1))*0x100+;
ASC(SUBSTR(cstruct,13,1))*0x10000+;
ASC(SUBSTR(cstruct,14,1))*0x1000000
RETURN .t.
ENDPROC
ENDDEFINE
*
*-- EndDefine: bmfheader
**************************************************
**************************************************
*-- Class: bmiheader (d:\documents\visual foxpro 项目\myclass.vcx)
*-- ParentClass: struct (d:\documents\visual foxpro 项目\myclass.vcx)
*-- BaseClass: custom
*-- Time Stamp: 04/02/23 05:50:12 PM
*
DEFINE CLASS bmiheader AS struct
Height = 27
Width = 178
*-- bitmapinfo的size,4个字节。
bisize = 40
*-- 位图宽,4个字节。
biwidth = 0
*-- 位图高,4个字节。
biheight = 0
*-- 为目标设备说明位面数,其值将总是被设为1,2个字节。
biplanes = 1
*-- 说明比特数/像素,其值为1、4、8、16、24、或32,2个字节。
bibitcount = 32
*-- 说明图像数据压缩的类型,4个字节。
bicompression = 0
*-- 说明图像的大小,以字节为单位。当用BI_RGB格式时,可设置为0
bisizeimage = 0
*-- 说明水平分辨率,用像素/米表示
bixpelspermeter = 0
*-- 说明垂直分辨率,用像素/米表示
biypelspermeter = 0
*-- 说明位图实际使用的彩色表中的颜色索引数(设为0的话,则说明使用所有调色板项)
biclrused = 0
*-- 说明对图像显示有重要影响的颜色索引的数目,如果是0,表示都重要,4个字节。
biclrimportant = 0
struct = (repli(chr(0),40))
Name = "bmiheader"
PROCEDURE set
PARAMETERS cstruct
IF LEN(cstruct)#40
RETURN .f.
ENDIF
this.bisize=ASC(SUBSTR(cstruct,1,1)) &&通常这个值一个字节就够了
this.biwidth=;
ASC(SUBSTR(cstruct,5,1))+;
ASC(SUBSTR(cstruct,6,1))*0x100+;
ASC(SUBSTR(cstruct,7,1))*0x10000+;
ASC(SUBSTR(cstruct,8,1))*0x1000000
this.biheight=;
ASC(SUBSTR(cstruct,9,1))+;
ASC(SUBSTR(cstruct,10,1))*0x100+;
ASC(SUBSTR(cstruct,11,1))*0x10000+;
ASC(SUBSTR(cstruct,12,1))*0x1000000
*!* this.biplanes=1 && 不需要设置,默认为1
this.bibitcount=ASC(SUBSTR(cstruct,15,1))&&这个值一个字节就够了
this.bicompression=;
ASC(SUBSTR(cstruct,17,1))+;
ASC(SUBSTR(cstruct,18,1))*0x100+;
ASC(SUBSTR(cstruct,19,1))*0x10000+;
ASC(SUBSTR(cstruct,20,1))*0x1000000
this.bisizeimage=;
ASC(SUBSTR(cstruct,21,1))+;
ASC(SUBSTR(cstruct,22,1))*0x100+;
ASC(SUBSTR(cstruct,23,1))*0x10000+;
ASC(SUBSTR(cstruct,24,1))*0x1000000
this.bixpelspermeter=;
ASC(SUBSTR(cstruct,25,1))+;
ASC(SUBSTR(cstruct,26,1))*0x100+;
ASC(SUBSTR(cstruct,27,1))*0x10000+;
ASC(SUBSTR(cstruct,28,1))*0x1000000
this.biypelspermeter=;
ASC(SUBSTR(cstruct,29,1))+;
ASC(SUBSTR(cstruct,30,1))*0x100+;
ASC(SUBSTR(cstruct,31,1))*0x10000+;
ASC(SUBSTR(cstruct,32,1))*0x1000000
this.biclrused=;
ASC(SUBSTR(cstruct,33,1))+;
ASC(SUBSTR(cstruct,34,1))*0x100+;
ASC(SUBSTR(cstruct,35,1))*0x10000+;
ASC(SUBSTR(cstruct,36,1))*0x1000000
this.biclrimportant=;
ASC(SUBSTR(cstruct,37,1))+;
ASC(SUBSTR(cstruct,38,1))*0x100+;
ASC(SUBSTR(cstruct,39,1))*0x10000+;
ASC(SUBSTR(cstruct,40,1))*0x1000000
RETURN .f.
ENDPROC
PROCEDURE getstruct
this.struct=BINTOC(this.bisize,"4rs");
+BINTOC(this.biwidth,"4rs");
+BINTOC(this.biheight,"4rs");
+BINTOC(this.biplanes,"2rs");
+BINTOC(this.bibitcount,"2rs");
+BINTOC(this.bicompression,"4rs");
+BINTOC(this.bisizeimage,"4rs");
+BINTOC(this.bixpelspermeter,"4rs");
+BINTOC(this.biypelspermeter,"4rs");
+BINTOC(this.biclrused,"4rs");
+BINTOC(this.biclrimportant,"4rs")
RETURN this.struct
ENDPROC
ENDDEFINE
*
*-- EndDefine: bmiheader
**************************************************
**************************************************
*-- Class: struct (d:\documents\visual foxpro 项目\myclass.vcx)
*-- ParentClass: custom
*-- BaseClass: custom
*-- Time Stamp: 04/02/23 04:00:01 PM
*
DEFINE CLASS struct AS custom
*-- 用以储存或设置结构体数据
struct = ("")
Name = "struct"
*-- 设置结构体
PROCEDURE set
RETURN .t.
ENDPROC
*-- 获得结构体数据。
PROCEDURE getstruct
ENDPROC
ENDDEFINE
*
*-- EndDefine: struct
**************************************************