仓酷云
标题:
ASP网页设计从Access数据库恢复BMP图象并显现在WEB...
[打印本页]
作者:
爱飞
时间:
2015-1-16 22:32
标题:
ASP网页设计从Access数据库恢复BMP图象并显现在WEB...
缺乏可以共同遵循的行业标准,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的收费是根据软件的类型、客制化程度、用户数量、服务期限来定的,对客户来说这笔费用是可以预见的。方便于客户应用软件的升级。
作者:
柔情似水
时间:
2015-1-18 05:25
不能只是将它停留在纸上谈兵的程度上。
作者:
小魔女
时间:
2015-1-18 09:22
ASP.Net和ASP的最大区别在于编程思维的转换,而不仅仅在于功能的增强。ASP使用VBS/JS这样的脚本语言混合html来编程,而那些脚本语言属于弱类型、面向结构的编程语言,而非面向对象,这就明显产生以下几个问题:
作者:
蒙在股里
时间:
2015-1-21 16:02
我想问如何掌握学习节奏(先学什么再学什么)最好详细点?
作者:
飘灵儿
时间:
2015-1-30 20:41
ASP.Net摆脱了以前ASP使用脚本语言来编程的缺点,理论上可以使用任何编程语言包括C++,VB,JS等等,当然,最合适的编程语言还是MS为.NetFrmaework专门推出的C(读csharp),它可以看作是VC和Java的混合体吧。
作者:
变相怪杰
时间:
2015-2-6 15:54
我可以结合自己的经验大致给你说一说,希望对你有所帮助,少走些弯路。
作者:
爱飞
时间:
2015-2-16 23:22
以上是语言本身的弱点,在功能方面ASP同样存在问题,第一是功能太弱,一些底层操作只能通过组件来完成,在这点上是远远比不上PHP/JSP,其次就是缺乏完善的纠错/调试功能,这点上ASP/PHP/JSP差不多。
作者:
冷月葬花魂
时间:
2015-3-5 12:14
接下来就不能纸上谈兵了,最好的方法其实是实践。实践,只能算是让你掌握语言特性用的。而提倡做实际的Project也不是太好,因为你还没有熟练的能力去综合各种技术,这样只能使你自己越来越迷糊。
作者:
飘飘悠悠
时间:
2015-3-19 18:30
我想问如何掌握学习节奏(先学什么再学什么)最好详细点?
欢迎光临 仓酷云 (http://ckuyun.com/)
Powered by Discuz! X3.2