These days many people ask me how to control the camera in the ASP program to capture photos, ASP technology or 99 time to see a little bit, early rice to eat, but since someone asked, that is Shand, spent a night to call the ASP program camera to take photos of the problem is done, is recorded below, So that students with similar needs can take less detours.
Technology to use:
1.asp Program for Base64 encoding and decoding, the use of MSXML components, in fact, is mainly used to capture the camera binary image data processing, because it is impossible for users to take photos after the manual upload, and the program has no way to control the implementation of automatic file upload, So in front of the page to take photos of the photo data to do Base64 code processing, and then submitted to the server to do Base64 decoding processing.
2.activex Technology
Control a variety of cameras to take photos, with a pure Web page is certainly not possible, the photo-chip function here is the use of ActiveX technology, made an ActiveX control, the realization of the photo cutting, black and white processing, scaling and so on, similar to the photo image cutting function, The key point of implementation is to select the cropping area with the mouse and drag the cropping area. After the acquisition of the photo data in the program to do a standard Base64 code processing, easy network data transmission.
3. Data transmission
In fact, this is not only related to camera controls or camera photos, all of the Base64 data transmitted in the HTTP communication protocol has this situation, because HTTP method is divided into get and post, and the get way is limited to the implementation of individual browsers, If the maximum amount of data can not be greater than how many k, so in the HTTP communication protocol to transmit large amounts of data, to select the Post method to deal with.
The interaction between 4.activex technology and the ASP program in the service area
The operation of the camera in the client browser is the ActiveX control, but the data of the ActiveX control can not be directly submit to the server side processing, that is, the ASP code you want to take the camera directly from the photo data is not access, It needs to take the ActiveX control in the client browser to take photos of the data, so that the server-side ASP program code can access to the photo data, so you need to have a "proxy" or "midway" things to do this thing, in fact, frankly speaking is very simple, Is that our ActiveX data can not be directly submitted, you want to put in the text box or hidden hidden elements inside to submit to the ASP program.
5. Photo Data preservation
The server-side received photo data is a base64 string, how can these strings be converted into binary picture data? This also involves a base64 data decoding to write binary files after the problem, since it involves writing files, you need to Web project security permissions to do some settings, lazy way is to everyone Full Control permissions on it.
The above is the technical thinking and implementation plan, to point Dry bar, directly on the code:
<%@ Language=vbscript codepage=65001%>
<%
Private Function DecodeBase64 (base64)
Dim DM, EL
Set DM = CreateObject ("Microsoft.XMLDOM")
Set EL = dm.createelement ("tmp")
EL. DataType = "Bin.base64"
EL. Text = Base64
DecodeBase64 = EL. nodeTypedValue
End Function
Dim data
Data=decodebase64 (Request. Form ("Pic_data"))
Set Stm=server.createobject ("ADODB. Stream ")
' STM. Mode=adsavecreateoverwrite ' adModeReadWrite
Stm.type=1
Stm.open
Stm. Write (data)
Stm. SaveToFile Server.MapPath ("./") & "/" & Request. Form ("desc") & ". jpg", 2
Stm. Close
Set stm=nothing
Response.Write "
Response.Write "desc:" & request. Form ("desc")
Response.End
%>
Gorgeous split line The following HTML page source code for taking photos of the foreground operation camera
---------------------------------------------------------------------------------------------------
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>video Cap Control demo</title>
<script type= "Text/javascript" src= "/js/jquery-1.4.2.min.js" ></script>
<script type= "Text/javascript" src= "Test1.js" ></script>
<body>
<form action= "test1.asp" id= "Cap_form" method= "POST" >
<input type= "hidden" id= "Picdata" name= "Picdata" >
<object classid= "Clsid:34681db3-58e6-4512-86f2-9477f1a9f3d8"
Id= "WebVideoCap1" codebase= "/cabs/package.cab#version=1,0,0,50" width= "636" height= "238" >
<param name= "Visible" value= "0" >
<param name= "AutoScroll" value= "0" >
<param name= "AutoSize" value= "0" >
<param name= "Axborderstyle" value= "1" >
<param name= "Caption" value= "Webvideocap" >
<param name= "Color" value= "4278190095" >
<param name= "Font" value= "Song Body" >
<param name= "KeyPreview" value= "0" >
<param name= "PixelsPerInch" value= ">"
<param name= "Printscale" value= "1" >
<param name= "Scaled" value= "-1" >
<param name= "DropTarget" value= "0" >
<param name= "HelpFile" value>
<param name= "Popupmode" value= "0" >
<param name= "Screensnap" value= "0" >
<param name= "Snapbuffer" value= "ten" >
<param name= "Docksite" value= "0" >
<param name= "doublebuffered" value= "0" >
<param name= "parentdoublebuffered" value= "0" >
<param name= "Usedockmanager" value= "0" >
<param name= "Enabled" value= "-1" >
<param name= "alignwithmargins" value= "0" >
<param name= "Parentcustomhint" value= "-1" >
<param name= "Jpegbase64data" value>
<param name= "Bmpbase64data" value>
</object>
<input type= "hidden" name= "Pic_data" id= "Pic_data"/>
Photo Description: <input type= "text" name= "desc" id= "desc"/>
<input type= "button" value= "Photography" id= "Btn_cap"/>
<input type= "button" value= "Submit" id= "Btn_submit"/>
</form>
</body>
Code Download Address dot here
---------------------------------------------------------------------------------