Problem prototype: http://expert.9cbs.net/expert/topic/2517/2517974.xml?temp=.4831049
In ASP, we often need to display images stored in the database in a binary in the web page. The general picture shows no problem, because this article has been very much, I will no longer explain. But sometimes pictures in the database are entered by other office software, or by other ways, such as directly adding them in Access. At this time, the picture is saved in the database in the database in the OLE object, and some other information is saved in front of the picture, such as the path and file name of the image, and so on. If we use the general output mode, it will be wrong, causing pictures that cannot be displayed.
Fortunately, JPEG, BMP and other image formats have a SOI Marker at the beginning of the image content. This Marker is FFD8 for JPEG, and for BMP is 424D. So, we can ignore this Marker location. The previous content is directly output from here. Take SQL Server as an example, the code is as follows:
<% '----------------------------------------------- -------------------------------------- 'function: function ShowJpegField (field)' author: inelm (Archimond [Akmond]) from 9CBS 'DATE: 2003-12-6 Update' Features: Number of SOI Marker in the byte array of JPEG images and outputs the true image information from that position 'Note: JPEG format SOI MARKER: FFD8 'BMP Format: 424D' Parameters: Image Field 'Return Value: No' Call Example: Showjpegfield (RS ("Picture1")) 'Note: Before calling this function, you need to declare response.write. MIME type is "image / jpeg" ----------------------------------------- ------------------------------------------- Function Showjpegfield (Field) DIM Size, i, j 'To output the total byte of the field size = field.actualsize
'Location of SOI Marker for i = 1 To size if ASCB (MIDB (Field, I, 1)) = & HFF and ASCB (MIDB (Field, i 1, 1)) = & HD8 THEN EXIT for end if Next
'Ignore the previous use, start output the real picture information from SOI Marker for J = I to size response.binaryWrite MIDB (Field, J, 1) NEXTEND FUNCTION%>
<% '-------- Main program start -------------------------- DIM Connset conn = server. CreateObject ("AdoDb.Connection") Conn.open ("provider = SQLOLEDB.1; Password = sa; persist security info = true; user id = sa; initial catalog = 123; data source = mark") SQL = "SELECT * From xinxi_mishuchu "set = conn.execute (SQL)
'Declaration Output Type, Empty Output Buffer Response.Buffer = TrueResponse.clearResponse.contettype = "Image / JPEG"
'Call function output picture showjpegfield (RS ("Picture1")))
'After you have finished your business! rs.close: set rs = nothingconn.close: set conn = Nothing%>
If it is a picture in other formats, such as BMP, GIF, etc., the output method is similar, but it is different.
Since the author is limited, the wrong is inevitable, you are welcome to criticize.