资源描述
根据代码解释,详细讲解在代码后。
先写一个如下的界面。基中testlong,command5,test.在这里没用。
提取数据按钮代码如下:
Private Sub 提取数据_Click()
Dim filename As String ‘这里用来指定tiff文件的所在路径。绝对路径
filename = "C:\Documents and Settings\Administrator\桌面\1.tif"
Open filename For Binary As #1 ‘用二进制方法打开这个文件
Dim aryContent() As Byte '用来读取文件的数组
ReDim aryContent(3) ‘定义4个长度,2个为数据格式,2个为版本格式
Get #1, , aryContent() '取得第一文件的内容到数组
‘二个逗号之间为空,表明从头开始读数据,或者从上一次读完后的地方再读数据,读到把数组装满后就不再读取,因此本次读了4个字节的数据
Dim version As String
version = "整数格式为:H" & hex(aryContent(0)) & hex(aryContent(1)) & Car(13)
‘2个为数据格式
version = version & "版本格式为:H" & Hex(aryContent(2)) & Hex(aryContent(3))
‘版本格式
‘以下为按需要读取其它信息的代码。根据偏移量。在代码后面会有详细解释
Dim byte4() As Byte
ReDim byte4(CInt(Text3.Text))
‘这里动态的定义数组的大小,根据需要也可以写成clng(text3.text)
If Text1.Text <= "0" Then Text1.Text = "1" ‘防止没有写。
Get #1, CLng(Text1.Text), byte4()
Dim i As Integer
For i = 0 To CInt(Text3.Text - 1)
version = version & "-" & Hex(byte4(i))
Next i
Text2.Text = version
‘在Text2中显示出相关信息。
Close #1 ‘关闭
End sub
以我处理的文件为例。下面为读到的信息。
先处理文件头信息:如表一
表一 文件头信息
IFH结构描述
------------------------------------------------------------
名称 字节数 数据类型 说明
------------------------------------------------------------
Byteorder 2 Integer TIF标记,其值为4D4D或4949
Version 2 Integer 版本号,其值恒为2A00
Offset to first IFD 4 Long 第一个IFD的偏移量
从1开始读取2个长度的字节码,得到:整数格式为:H7373版本格式为:H2A0-49-49
1-2 Byteorder :H49H49 2个字节 H4949时,低字节在前,高字节在后
3-4 Version :H2AH0 2个字节
5-8 Offset to firstIFD :H50611800 第一个IFD的偏移量
因为低字节在前,所以处理时反过来。以后得到的数据都为16进制,在处理时都要反过来,把低字节放后,高字节放前。H186150,十进制为1597776,为偏移量
偏移量为1597776,但在text1处要填1597777。类似于一开始时,偏移量为0,但在那里填1。这里绕了几个小时,从http://www.awaresystems.be/imaging/tiff/tifftags/search.html下载一个软件installer0200.exe.里面可以把一些基本信息读出来,类似于本篇文章的代码功能。
再处理第一个IFD信息。信息内容如表二
表二 IFD结构描述
-----------------------------------------------------------------
名称 字节数 数据类型 说明
-----------------------------------------------------------------
Directory Entry Count 2 Integer 本IFD中DE的数量
Directory Entry(1) 12 简称DE,中文译义“目录项”
Directory Entry(2) 12
……
Directory Entry(N) 12
Offset to next IFD 4 Long 下一个IFD的偏移量
从1597777开始读取2个长度的字节码,得到。。。。。
1597777-1597779 本IFD中DE的数量:H000F 2个字节 表明里面有15个DE
DE中的信息如表三:
第一个DE中的信息1597779-1597790 FE-0-4-0-1-0-0-0-0-0-0-0
1597779-1597780 标签编号 2个字节 为HFE00,变为00FE
所以的标签编号信息如表四,在后面。
1597781-1597782 数据类型 2个字节 为H0400,变为0004 4为Long型
1597783-1597786 该类型数据的数量 4个字节 为H01000000变为 0-0-0-1数量为1
1597787-1597790 属性值的存放偏移量4个字节 0-0-0-0
以下类似,处理数据时都反过来处理
表三 DE结构描述
--------------------------------------------------
名称 字节数 数据类型 说明
--------------------------------------------------
tag 2 Integer 本属性的标签编号
type 2 Integer 本属性值的数据类型
length 4 Long 该类型数据的数量
valueOffset 4 Long 属性值的存放偏移量
--------------------------------------------------
(数据类型的信息,如表五)表五DE中的数据类型
--------------------------------------------------------------------
type值 数据类型 说明
--------------------------------------------------------------------
1 = BYTE
2 = ASCII
3 = SHORT
4 = LONG
5 = RATIONAL分数类型,由两个Long组成,第1个是分子,第2个是分母
6 = SBYTE
7 = UNDEFINED
8 = SSHORT
9 = SLONG
10 = SRATIONAL
11 = FLOAT
12 = DOUBLE
第二个DE中的信息1597791- 0-1-3-0-1-0-0-0-80-4-0-0
标签编号 0100 ImageWidth
数据类型 0003 3为Integer型
该类型数据的数量 00000001 数量为1
属性值的存放偏移量 00000480 数量为1152
。。。。。以下类推
第十五个DE中的信息 1597947- 3D-1-3-0-1-0-0-0-1-0-0-0
标签编号 013D Predictor
数据类型 0003 3为Integer型
该类型数据的数量 0001 为1
属性值的存放偏移量 0001 ?
表四 标签编号
Code
Name
Short description
Dec
Hex
254
00FE
NewSubfileType
A general indication of the kind of data contained in this subfile.
255
00FF
SubfileType
A general indication of the kind of data contained in this subfile.
256
0100
ImageWidth
The number of columns in the image, i.e., the number of pixels per row.
257
0101
ImageLength
The number of rows of pixels in the image.
258
0102
BitsPerSample
Number of bits per component.
259
0103
Compression
Compression scheme used on the image data.
262
0106
PhotometricInterpretation
The color space of the image data.
263
0107
Threshholding
For black and white TIFF files that represent shades of gray, the technique used to convert from gray to black and white pixels.
264
0108
CellWidth
The width of the dithering or halftoning matrix used to create a dithered or halftoned bilevel file.
265
0109
CellLength
The length of the dithering or halftoning matrix used to create a dithered or halftoned bilevel file.
266
010A
FillOrder
The logical order of bits within a byte.
270
010E
ImageDescription
A string that describes the subject of the image.
271
010F
Make
The scanner manufacturer.
272
0110
Model
The scanner model name or number.
273
0111
StripOffsets
For each strip, the byte offset of that strip.
274
0112
Orientation
The orientation of the image with respect to the rows and columns.
277
0115
SamplesPerPixel
The number of components per pixel.
278
0116
RowsPerStrip
The number of rows per strip.
279
0117
StripByteCounts
For each strip, the number of bytes in the strip after compression.
280
0118
MinSampleValue
The minimum component value used.
281
0119
MaxSampleValue
The maximum component value used.
282
011A
XResolution
The number of pixels per ResolutionUnit in the ImageWidth direction.
283
011B
YResolution
The number of pixels per ResolutionUnit in the ImageLength direction.
284
011C
PlanarConfiguration
How the components of each pixel are stored.
288
0120
FreeOffsets
For each string of contiguous unused bytes in a TIFF file, the byte offset of the string.
289
0121
FreeByteCounts
For each string of contiguous unused bytes in a TIFF file, the number of bytes in the string.
290
0122
GrayResponseUnit
The precision of the information contained in the GrayResponseCurve.
291
0123
GrayResponseCurve
For grayscale data, the optical density of each possible pixel value.
296
0128
ResolutionUnit
The unit of measurement for XResolution and YResolution.
305
0131
Software
Name and version number of the software package(s) used to create the image.
306
0132
DateTime
Date and time of image creation.
315
013B
Artist
Person who created the image.
316
013C
HostComputer
The computer and/or operating system in use at the time of image creation.
320
0140
ColorMap
A color map for palette color images.
338
0152
ExtraSamples
Description of extra components.
33432
8298
Copyright
Copyright notice.
269
010D
DocumentName
The name of the document from which this image was scanned.
285
011D
PageName
The name of the page from which this image was scanned.
286
011E
XPosition
X position of the image.
287
011F
YPosition
Y position of the image.
292
0124
T4Options
Options for Group 3 Fax compression
293
0125
T6Options
Options for Group 4 Fax compression
297
0129
PageNumber
The page number of the page from which this image was scanned.
301
012D
TransferFunction
Describes a transfer function for the image in tabular style.
317
013D
Predictor
A mathematical operator that is applied to the image data before an encoding scheme is applied.
318
013E
WhitePoint
The chromaticity of the white point of the image.
319
013F
PrimaryChromaticities
The chromaticities of the primaries of the image.
321
0141
HalftoneHints
Conveys to the halftone function the range of gray levels within a colorimetrically-specified image that should retain tonal detail.
322
0142
TileWidth
The tile width in pixels. This is the number of columns in each tile.
323
0143
TileLength
The tile length (height) in pixels. This is the number of rows in each tile.
324
0144
TileOffsets
For each tile, the byte offset of that tile, as compressed and stored on disk.
325
0145
TileByteCounts
For each tile, the number of (compressed) bytes in that tile.
326
0146
BadFaxLines
Used in the TIFF-F standard, denotes the number of 'bad' scan lines encountered by the facsimile device.
327
0147
CleanFaxData
Used in the TIFF-F standard, indicates if 'bad' lines encountered during reception are stored in the data, or if 'bad' lines have been replaced by the receiver.
328
0148
ConsecutiveBadFaxLines
Used in the TIFF-F standard, denotes the maximum number of consecutive 'bad' scanlines received.
330
014A
SubIFDs
Offset to child IFDs.
332
014C
InkSet
The set of inks used in a separated (PhotometricInterpretation=5) image.
333
014D
InkNames
The name of each ink used in a separated image.
334
014E
NumberOfInks
The number of inks.
336
0150
DotRange
The component values that correspond to a 0% dot and 100% dot.
337
0151
TargetPrinter
A description of the printing environment for which this separation is intended.
339
0153
SampleFormat
Specifies how to interpret each data sample in a pixel.
340
0154
SMinSampleValue
Specifies the minimum sample value.
341
0155
SMaxSampleValue
Specifies the maximum sample value.
342
0156
TransferRange
Expands the range of the TransferFunction.
343
0157
ClipPath
Mirrors the essentials of PostScript's path creation functionality.
344
0158
XClipPathUnits
The number of units that span the width of the image, in terms of integer ClipPath coordinates.
345
0159
YClipPathUnits
The number of units that span the height of the image, in terms of integer ClipPath coordinates.
346
015A
Indexed
Aims to broaden the support for indexed images to include support for any color space.
347
015B
JPEGTables
JPEG quantization and/or Huffman tables.
351
015F
OPIProxy
OPI-related.
400
0190
GlobalParametersIFD
Used in the TIFF-FX standard to point to an IFD containing tags that are globally applicable to the complete TIFF file.
401
0191
ProfileType
Used in the TIFF-FX standard, denotes the type of data stored in this file or IFD.
402
0192
FaxProfile
Used in the TIFF-FX standard, denotes the 'profile' that applies to this file.
403
0193
CodingMethods
Used in the TIFF-FX standard, indicates which coding methods are used in the file.
404
0194
VersionYear
Used in the TIFF-FX standard, denotes the year of the standard specified by the FaxProfile field.
405
0195
ModeNumber
Used in the TIFF-FX standard, denotes the mode of the standard specified by the FaxProfile field.
433
01B1
Decode
Used in the TIFF-F and TIFF-FX standards, holds information about the ITULAB (PhotometricInterpretation = 10) encoding.
434
01B2
DefaultImageColor
Defined in the Mixed Raster Content part of RFC 2301, is the default color needed in areas where no image is available.
512
0200
JPEGProc
Old-style JPEG compression field. TechNote2 invalidates this part of the specification.
513
0201
JPEGInterchangeFormat
Old-style JPEG compression field. TechNote2 invalidates this part of the specification.
514
0202
JPEGInterchangeFormatLength
Old-style JPEG compression field. TechNote2 invalidates this part of the specification.
515
0203
JPEGRestartInterval
Old-style JPEG compression field. TechNote2 invalidates this part of the specification.
517
0205
JPEGLosslessPredictors
Old-style JPEG compression field. TechNote2 invalidates this part of the specification.
518
0206
JPEGPointTransforms
Old-style JPEG compression field. TechNote2 invalidates this part of the specification.
519
0207
JPEGQTables
Old-style JPEG compression field. TechNote2 invalidates this part of the specification.
520
0208
JPEGDCTables
Old-style JPEG compression field. TechNote2 invalidates this part of the specification.
521
0209
JPEGACTables
Old-style JPEG compression field. TechNote2 invalidates this part of the specification.
529
0211
YCbCrCoefficients
The transformation from RGB to YCbCr image data.
530
0212
YCbCrSubSampling
Specifies the subsampling factors used for the chrominance components of a YCbCr image.
531
0213
YCbCrPositioning
Specifies the positioning of subsampled chrominance components relative to luminance samples.
532
0214
ReferenceBlackWhite
Specifies a pair of headroom and footroom image data values (codes) for each pixel component.
559
022F
StripRowCounts
Defined in the Mixed Raster Content part of RFC 2301, used to replace RowsPerStrip for IFDs with variable-sized strips.
700
02BC
XMP
XML packet containing XMP metadata
32781
800D
ImageID
OPI-related.
34732
87AC
ImageLayer
Defined in the Mixed Raster Content part of RFC 2301, used to denote the particular function of this Image in the mixed raster scheme.
32932
80A4
Wang Annotation
Annotation data, as used in 'Imaging for Windows'.
33445
82A5
MD FileTag
Specifies the pixel data format encoding in the Molecular Dynamics GEL file format.
33446
82A6
MD ScalePixel
Specifies a scale factor in the Molecular Dynamics GEL file format.
33447
82A7
MD ColorTable
Used to specify the conversion from 16bit to 8bit in the Molecular Dynamics GEL file format.
33448
82A8
MD LabName
Name of the lab that scanned this file, as used in the Molecular Dynamics GEL file format.
33449
82A9
MD SampleInfo
Information about the sample, as used in the Molecular Dynamics GEL file format.
33450
82AA
MD PrepDate
Date the sample was prepared, as used in the Molecular Dynamics GEL file format.
33451
82AB
MD PrepTime
Time the sample was prepared, as used in the Molecular Dynamics GEL file format.
33452
82AC
MD FileUnits
Units for data in this file, as used in the Molecular Dynamics GEL file format.
33550
830E
ModelPixelScaleTag
Used in interchangeable GeoTIFF files.
33723
83BB
IPTC
IPTC (International Press Telecommunications Council) metadata.
33918
847E
INGR Packet Data Tag
Intergraph Application specific storage.
33919
847F
INGR Flag Registers
Intergraph Application specific flags.
33920
8480
IrasB Transformation Matrix
Originally part of Intergraph's GeoTIFF tags, but likely understood by IrasB only.
33922
8482
ModelTiepointTag
Originally part of Intergraph's GeoTIFF tags, but now used in interchangeable GeoTIFF files.
34264
85D8
ModelTransformationTag
Used in interchangeable GeoTIFF files.
34377
8649
Photoshop
Collection of Photoshop 'Image Resource Blocks'.
34665
8769
Exif IFD
A pointer to the Exif IFD.
34675
8773
ICC Profile
ICC profile data.
34735
87AF
GeoKeyDirectoryTag
Used in interchangeable GeoTIFF files.
34736
87B0
GeoDoubleParamsTag
Used in interchangeable GeoTIFF files.
34737
87B1
GeoAsciiParamsTag
Used in interchangeable GeoTIFF files.
34853
8825
GPS IFD
A pointer to the Exif-related GPS Info IFD.
34908
885C
HylaFAX FaxRecvParams
Used by
展开阅读全文