|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
缺乏可以共同遵循的行业标准,ASP还处在发展初期,大家对它的理解不同,如产品和服务标准,收费标准等,不利于行业的健康发展。HOWTO:RetrievingBitmapfromAccessandDisplayingInWebPage
--------------------------------------------------------------------------------
Theinformationinthisarticleappliesto:
ActiveServerPages
MicrosoftVisualBasicProfessionalandEnterpriseEditionsforWindows,versions5.0,6.0
ActiveXDataObjects(ADO),versions1.0,1.5,2.0,2.1SP2,2.5
MicrosoftInternetInformationServerversions4.0,5.0
MicrosoftDataAccessComponentsversion2.5
--------------------------------------------------------------------------------
SUMMARY
ThisarticleshowsbyexamplehowtoextractthebitmapphotosintheMicrosoftAccess97Northwind.mdb
database,andviewthemfromaWebbrowserusingActiveServerPages(ASP).Inordertoaccomplishthis
task,anActiveXDLLmustbecreatedthatstripstheAccessandOLEheadersfromthefield.Thisarticle
showshowtocreatethisActiveXDLL,andhowtoimplementit.
MOREINFORMATION
WARNING:ANYUSEBYYOUOFTHECODEPROVIDEDINTHISARTICLEISATYOUROWNRISK.Microsoftprovidesthis
code"asis"withoutwarrantyofanykind,eitherexpressorimplied,includingbutnotlimitedtothe
impliedwarrantiesofmerchantabilityand/orfitnessforaparticularpurpose.
ThisarticledemonstrateshowtouseVisualBasictoretrieveabitmapstoredinanOLEObjectfield.
BecausethedefinitionofOLEobjectstorageisnotdocumented,thefollowingcodesearchestheobjects
OLEheaderforcharactersconsistentwiththestartofthegraphic.Thismethodmaynotworkinall
circumstances.
BeawarethatInternetExplorer3.0isunabletodisplaytruecolorbitmaps.Forthisreason,thebitmaps
storedintheAccessdatabaseshouldbenohigherthan256colors.
Step-by-StepExampletoExtractthePhotos
CreateanewprojectinVisualBasicandmaketheprojectanActiveXDLL.
AddareferencetoActiveXDataObjects(ADO)byclickingtheProjectmenuandselectingReferences.
Select"MicrosoftOLEDBActiveXDataObjects1.0Library"andclickOK.
AddanewmoduletotheprojectbyselectingtheProjectmenuandclickingAddModule.SelectModuleand
clickOpen.
Placethefollowingcodeinthe(general)(declarations)sectionofMODULE1.BAS:
EnterthefollowingDeclarestatementasonesingleline:
PublicDeclareSubCopyMemoryLib"kernel32"Alias"RtlMoveMemory"
(lpvDestAsAny,lpvSourceAsAny,ByValcbCopyAsLong)
TypePT
WidthAsInteger
HeightAsInteger
EndType
TypeOBJECTHEADER
SignatureAsInteger
HeaderSizeAsInteger
ObjectTypeAsLong
NameLenAsInteger
ClassLenAsInteger
NameOffsetAsInteger
ClassOFfsetAsInteger
ObjectSizeAsPT
OleInfoAsString*256
EndType
Placethefollowingcodeinthe(general)(declarations)sectionofCLASS1.CLS:
FunctionDisplayBitmap(ByValOleFieldAsVariant)
DimArr()AsByte
DimObjHeaderAsOBJECTHEADER
DimBufferAsString
DimObjectOffsetAsLong
DimBitmapOffsetAsLong
DimBitmapHeaderOffsetAsInteger
DimArrBmp()AsByte
DimiAsLong
Resizethearray,thenfillitwith
theentirecontentsofthefield
ReDimArr(OleField.ActualSize)
Arr()=OleField.GetChunk(OleField.ActualSize)
Copythefirst19bytesintoavariable
oftheOBJECTHEADERuserdefinedtype.
CopyMemoryObjHeader,Arr(0),19
DeterminewheretheAccessHeaderends.
ObjectOffset=ObjHeader.HeaderSize+1
GrabenoughbytesaftertheOLEheadertogetthebitmapheader.
Buffer=""
Fori=ObjectOffsetToObjectOffset+512
Buffer=Buffer&Chr(Arr(i))
Nexti
MakesuretheclassoftheobjectisaPaintBrushobject
IfMid(Buffer,12,6)="PBrush"Then
BitmapHeaderOffset=InStr(Buffer,"BM")
IfBitmapHeaderOffset>0Then
Calculatethebeginningofthebitmap
BitmapOffset=ObjectOffset+BitmapHeaderOffset-1
Movethebitmapintoitsownarray
ReDimArrBmp(UBound(Arr)-BitmapOffset)
CopyMemoryArrBmp(0),Arr(BitmapOffset),UBound(Arr)-
BitmapOffset+1
Returnthebitmap
DisplayBitmap=ArrBmp
EndIf
EndIf
EndFunction
RenametheProjectbyselectingtheProjectmenu,andclickingon"Project1Properties"andtypeyournew
nameinthe"ProjectName"field.Thisexampleassumesthatyounamedtheproject"MyProject"andwill
refertothatnameinfuturesteps.
MaketheprojectApartmentModelThreadedbyselectingthe"UnattendedExecution"checkbox.ClickOK.
RenametheClassinthePropertyPane.Thisexampleassumesthatyounamedtheclass"MyClass"andrefers
tothatnameinfuturesteps.
CompiletheDLLbyclickingtheFilemenuandselecting"MakeMyProject.dll."
CreateanASPpagenamed"bitmap.asp"thatcontainsthefollowingcode:
<%@LANGUAGE="VBSCRIPT"%>
<%
YouneedtosetupaSystemDSNnamedNWindthatpointsto
theNorthwind.mdbdatabase
SetDataConn=Server.CreateObject("ADODB.Connection")
DataConn.Open"DSN=NWind","admin",""
SetcmdTemp=Server.CreateObject("ADODB.Command")
SetRS=Server.CreateObject("ADODB.Recordset")
cmdTemp.CommandText="SELECTPhotoFROMEmployees
WHEREEmployeeID=1"
cmdTemp.CommandType=1
SetcmdTemp.ActiveConnection=DataConn
RS.OpencmdTemp,,0,1
Response.ContentType="image/bmp"
SetBitmap=Server.CreateObject("MyProject.MyClass")
Response.BinaryWriteBitmap.DisplayBitmap(RS("Photo"))
RS.Close
%>
CreateanHTMLpagenamed"BitmapTest.htm"thatcontainsthefollowingcode:
<HTML>
<HEAD>
<TITLE>BitmapTest</TITLE>
</HEAD>
<BODY>
<HR>
<imgsrc="Bitmap.asp">
<HR>
</BODY>
</HTML>
对用户来说可预见费用、节约费用,可以做到花少钱办大事。由于省去了购买软件和硬件等的前期费用,用户可以租用较高级的应用软件。ASP的收费是根据软件的类型、客制化程度、用户数量、服务期限来定的,对客户来说这笔费用是可以预见的。方便于客户应用软件的升级。 |
|