图像文件格式BMP文档格式.docx
- 文档编号:22249592
- 上传时间:2023-02-03
- 格式:DOCX
- 页数:27
- 大小:61.10KB
图像文件格式BMP文档格式.docx
《图像文件格式BMP文档格式.docx》由会员分享,可在线阅读,更多相关《图像文件格式BMP文档格式.docx(27页珍藏版)》请在冰豆网上搜索。
Adevice-independentbitmap(DIB)isaformatusedtodefinedevice-independentbitmapsinvariouscolorresolutions.ThemainpurposeofDIBsistoallowbitmapstobemovedfromonedevicetoanother(hence,thedevice-independentpartofthename).ADIBisanexternalformat,incontrasttoadevice-dependentbitmap,whichappearsinthesystemasabitmapobject(createdbyanapplication...).ADIBisnormallytransportedinmetafiles(usuallyusingtheStretchDIBits()function),BMPfiles,andtheClipboard(CF_DIBdataformat).
ThefollowingsectionsdiscussthedatastoredintheBMPfileorDIBindetail.ThisisthestandardBMPfileformat.[1]SomeapplicationscreatebitmapimagefileswhicharenotcompliantwiththecurrentMicrosoftdocumentation.Also,notallfieldsareused;
avalueof0willbefoundintheseunusedfields.
Filestructure
Thebitmapimagefileconsistsoffixed-sizestructures(headers)aswellasvariable-sizestructuresappearinginapredeterminedsequence.Manydifferentversionsofsomeofthesestructurescanappearinthefile,duetothelongevolutionofthisfileformat.
Diag.1–Thestructureofthebitmapimagefile
Referringtothediagram1,thebitmapfileiscomposedofstructuresinthefollowingorder:
StructureName
Optional
Size
Purpose
Comments
BitmapFileHeader
No
14Bytes
TostoregeneralinformationabouttheBitmapImageFile
Notneededafterthefileisloadedinmemory
DIBHeader
Fixed-size
(however7differentversionsexist)
Tostoredetailedinformationaboutthebitmapimageanddefinethepixelformat
ImmediatelyfollowstheBitmapFileHeader
Extrabitmasks
Yes
3or4DWORDs[2]
(12or16Bytes)
Todefinethepixelformat
PresentonlyincasetheDIBHeaderistheBITMAPINFOHEADER
ColorTable
Semi-optional
Variable-size
Todefinecolorsusedbythebitmapimagedata(PixelArray)
Mandatoryforcolordepths<
=8
Gap1
Structurealignment
AnartifactoftheFileOffsettoPixelArrayintheBitmapFileHeader
PixelArray
Todefinetheactualvaluesofthepixels
ThepixelformatisdefinedbytheDIBHeaderorExtrabitmasks.EachrowinthePixelArrayispaddedtoamultipleof4bytesinsize
Gap2
AnartifactoftheICCProfileDataoffsetfieldintheDIBHeader
ICCColorProfile
Todefinethecolorprofileforcolormanagement
Canalsocontainapathtoanexternalfilecontainingthecolorprofile.Whenloadedinmemoryas"
non-packedDIB"
itislocatedbetweenthecolortableandgap1.[3]
DIBsinmemory
AbitmapimagefileloadedintomemorybecomesaDIBdatastructure–animportantcomponentoftheWindowsGDIAPI.Thein-memoryDIBdatastructureisalmostthesameastheBMPfileformat,butitdoesnotcontainthe14-bytebitmapfileheaderandbeginswiththeDIBheader.ForDIBsloadedinmemory,thecolortablecanalsoconsistof16bitentries,thatconstituteindexestothecurrentlyrealizedpalette[4](anadditionallevelofindirection),insteadofexplicitRGBcolordefinitions.Inallcases,thepixelarraymustbeginatamemoryaddressthatisamultipleof4bytes.Innon-packedDIBsloadedinmemory,theoptionalcolorprofiledatashouldbelocatedimmediatelyafterthecolortableandbeforethegap1andpixelarray[3](unlikeindiag.1).
Whenthesizeofgap1andgap2iszero,thein-memoryDIBdatastructureiscustomarilyreferredtoas"
packedDIB"
andcanbereferredtobyasinglepointerpointingtothebeginningoftheDIBheader.Inallcases,thepixelarraymustbeginatamemoryaddressthatisamultipleof4bytes.Insomecasesitmaybenecessarytoadjustthenumberofentriesinthecolortableinordertoforcethememoryaddressofthepixelarraytoamultipleof4bytes.[4]For"
packedDIBs"
loadedinmemory,theoptionalcolorprofiledatashouldimmediatelyfollowthepixelarray,asdepictedindiag.1(withgap1=0andgap2=0).[3]
"
PackedDIBs"
arerequiredbyWindowsclipboardAPIfunctionsaswellasbysomeWindowspatternedbrushandresourcefunctions.[5]
Bitmapfileheader
Thisblockofbytesisatthestartofthefileandisusedtoidentifythefile.AtypicalapplicationreadsthisblockfirsttoensurethatthefileisactuallyaBMPfileandthatitisnotdamaged.ThefirsttwobytesoftheBMPfileformatarethecharacter'
B'
thenthecharacter'
M'
in1-byteASCIIencoding.Alloftheintegervaluesarestoredinlittle-endianformat(i.e.least-significantbytefirst).
Offset#
0000h
2bytes
theheaderfieldusedtoidentifytheBMP&
DIBfileis0x420x4Dinhexadecimal,sameasBMinASCII.Thefollowingentriesarepossible:
BM–Windows3.1x,95,NT,...etc.
BA–OS/2structBitmapArray
CI–OS/2structColorIcon
CP–OS/2constColorPointer
IC–OS/2structIcon
PT–OS/2Pointer
0002h
4bytes
thesizeoftheBMPfileinbytes
0006h
reserved;
actualvaluedependsontheapplicationthatcreatestheimage
0008h
000Ah
theoffset,i.e.startingaddress,ofthebytewherethebitmapimagedata(pixelarray)canbefound.
DIBheader(bitmapinformationheader)
Thisblockofbytestellstheapplicationdetailedinformationabouttheimage,whichwillbeusedtodisplaytheimageonthescreen.
TheblockalsomatchestheheaderusedinternallybyWindowsandOS/2andhasseveraldifferentvariants.Allofthemcontainadword(32bit)field,specifyingtheirsize,sothatanapplicationcaneasilydeterminewhichheaderisusedintheimage.
ThereasonthattherearedifferentheadersisthatMicrosoftextendedtheDIBformatseveraltimes.ThenewextendedheaderscanbeusedwithsomeGDIfunctionsinsteadoftheolderones,providingmorefunctionality.SincetheGDIsupportsafunctionforloadingbitmapfiles,typicalWindowsapplicationsusethatfunctionality.Oneconsequenceofthisisthatforsuchapplications,theBMPformatsthattheysupportmatchtheformatssupportedbytheWindowsversionbeingrun.Seethetablebelowformoreinformation.
HeaderName
OSsupport
FeaturesAdded(incremental)
inBitmapFilesWrittenby
12
BITMAPCOREHEADER
OS21XBITMAPHEADER
OS/2andalsoallWindowsversionssinceWindows3.0
64
BITMAPCOREHEADER2
OS22XBITMAPHEADER
OS/2
Addshalftoning.AddsRLEandHuffman1Dcompression.
40
BITMAPINFOHEADER
allWindowsversionssinceWindows3.0
RemovesRLE-24andHuffman1Dcompression.Adds16bppand32bpppixelformats.AddsoptionalRGBbitmasks.
AdobePhotoshop
52
BITMAPV2INFOHEADER
Undocumented.
RemovesoptionalRGBbitmasks.AddsmandatoryRGBbitmasks.
56
BITMAPV3INFOHEADER
Addsmandatoryalphachannelbitmask.
108
BITMAPV4HEADER
allWindowsversionssinceWindows95/NT4
Addscolorspacetypeandgammacorrection
124
BITMAPV5HEADER
Windows98/2000andnewer
AddsICCcolorprofiles
VersionsafterBITMAPCOREHEADERonlyaddfieldstotheendoftheheaderofthepreviousversion.Forexample:
BITMAPV2INFOHEADERaddsfieldstoBITMAPINFOHEADERandBITMAPV3INFOHEADERaddsfieldstoBITMAPV2INFOHEADER(or,BITMAPINFOHEADERisastrippedversionofBITMAPV2INFOHEADER)
Forcompatibilityreasons,mostapplicationsusetheolderDIBheadersforsavingfiles.WithOS/2beingobsolete,fornowthecommonformatistheBITMAPINFOHEADERheader.Seenexttableforitsdescription.Allvaluesarestoredasunsignedintegers,unlessexplicitlynoted.
Offset#
0Eh
4
thesizeofthisheader(40bytes)
12h
thebitmapwidthinpixels(signedinteger).
16h
thebitmapheightinpixels(signedinteger).
1Ah
2
thenumberofcolorplanesbeingused.Mustbesetto1.
1Ch
thenumberofbitsperpixel,whichisthecolordepthoftheimage.Typicalvaluesare1,4,8,16,24and32.
1Eh
thecompressionmethodbeingused.Seethenexttableforalistofpossiblevalues.
22h
theimagesize.Thisisthesizeoftherawbitmapdata(seebelow),andshouldnotbeconfusedwiththefilesize.
26h
thehorizontalresolutionoftheimage.(pixelpermeter,signedinteger)
2Ah
theverticalresolutionoftheimage.(pixelpermeter,signedinteger)
2Eh
thenumberofcolorsinthecolorpalette,or0todefaultto2n.
32h
thenumberofimportantcolorsused,or0wheneverycolorisimportant;
generallyignored.
Note:
Theimagesizefieldcanbe0forBI_RGBbitmaps.
Thecompressionmethodfield(bytes#30-33)canhavethefollowingvalues:
Value
Identifiedby
Compr
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 图像文件 格式 BMP