In ASP, we often need to display a picture in a database that is stored in binary form on a Web page.
The general picture shows no problem, because this article has a lot of, I will no longer elaborate.
But sometimes the pictures in the database are entered through other Office software, or in other ways, such as directly in Access.
At this point, the picture is stored in the database as an OLE object, and in front of the real content of the picture, some other information, such as the path and file name of the picture, and so on, are saved.
If we still use the normal output method, it will make an error, resulting in the picture can not be displayed.
Fortunately, JPEG, BMP and other image format in the image content at the beginning of a SOI marker, this marker for JPEG is FFD8, and for BMP is 424D. So, we just have to find this marker position, we can ignore the previous content and directly from here to start output pictures. Take SQL server, for example, with the following code:
<%
'-------------------------------------------------------------------------------------
' Function: function Showjpegfield (field)
' Author: Inelm (archimond "Archimonde") from CSDN
' Date:2003-12-6 update
' function: Get the SOI marker start position in the byte array that holds the JPEG picture, and output the real picture information from that location
' Note: SOI marker:ffd8 in JPEG format
' BMP format: 424D
' Parameters: Picture fields
' Return value: None
' Invocation Example: Showjpegfield (RS ("Picture1"))
' Note: Before calling this function, you need to declare that the MIME type of Response.Write is ' image/jpeg '
'-------------------------------------------------------------------------------------
function Showjpegfield (field)
Dim size, I, J
' The total number of bytes to output the field
size = field. ActualSize
' Loops to find the 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 useless information in front, start outputting the real picture information from SOI marker
For j = i to size
Response. BinaryWrite MidB (Field, J, 1)
Next
End Function
%>
<%
'--------The main program starts------------------------------
Dim conn
Set conn = Server.CreateObject ("ADODB. Connection ")
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.