Note that you can also create a bitmap object from a file, but use this
The graphic format saved in the database is that the browser cannot be identified.
When you save an image into the database, you should know what format you need to use to save
You can save each byte in the file, or save graphics through Access / FoxPro
For an OLE format.
What format saves an image that you use to use what format in the ASP is used to read the graphic.
Specifically, if you save the graphic as BMP, GIF, JPEG in Access / FoxPro
This must use the OLE object of Access / FoxPro, that is, use Access's insertion object
Dialog is completed, this is when you use
Image / BMP is not explained when the browser is explained.
Now suppose that saved in the database is the graphic format you want.
(GIF, JPEG, BMP, TIFF, etc.) Now to see how to put them from
Read it in the database.
Two key technologies are used in Access to save graphics
1. Used BMP format
2.78 bytes of file headers
<%
Response.expires = 0
Response.buffer = TRUE
Response.clear
Response.contentType = "image / bmp"
%>
Then you have to do it is to remove the file header of the 78 bytes of OLE object.
<%
Const oleheadersize = 78
nfieldsize = rs ("photo"). ActualSize
OleHeader = RS ("photo"). getChunk (OleHeadersize)
ImageBytes = RS ("photo"). getChunk (nfieldsize - oleheadersize)
Response.binaryWrite ImageBytes
%>
Now give an example:
If you have to get information about a worker, this information includes an introduction and his image.
And to display text and graphics at the same time.
The code is as follows: (where the THEIMG is a proxy page)
THEIMG.ASP
<%
Response.expires = 0
Response.buffer = TRUE
Response.clear
Response.contentType = session ("iMageType")
Response.binarywrite session ("ImageBytes")
Session ("iMagType") = ""
Session ("ImageBytes") = ""
Response.end
%>
Function setImageFordisplay (Field, ContentType)
OleHeadersize = 78
ContentType = LCase (ContentType)
Select Case ContentType
Case "GIF", "JPEG", "BMP"
ContentType = "Image /" & ContentType
Bytes = Field.Value
Case "OLE"
ContentType = "image / bmp"
nfieldsize = field.actualsize
OleHeader = Field.getChunk (OleHeadersize)
Bytes = Field.getChunk (nfieldsize - oleheadersize) End SELECT
Session ("ImageBytes") = bytes
Session ("ImageType" = ContentType
END FUNCTION
'Note that only 4 formats in the program: GIF, JPEG, BMP, OLE.
<%
SQL = "SELECT * from Employees"
SET ORS = Server.createObject ("AdoDb.Recordset")
Ors.cursorLocation = 3
Ors.open SQL, "DSN = NW"
SetimageFordisplay ORS ("photo"), "ole"
SET ORS.ActiveConnection = Nothing
%>
To display the image, just need to be in another ASP, assume it as getEmpinfo.asp
But there is still a problem because of the same "THEIMG.ASP" in the graphics of each employee.
File, you should modify it again:
" g>
Finally, how do you display a variety of images?
In other words, if there are multiple fields in the database, what should I do?
In fact, the solution is very simple, just add a parameter to setimagefordisplay.
That is to save a session variable for saving graphics.
E.g:
SetimageFordisplay Ors1 ("Photo"), "OLE", "EMPPHOTO"
SetImageFordisplay Ors2 ("LOGO"), "GIF", "Complogo"
">>>
>>>>
Use this method to complete the following features:
1. Graphics fields can be removed from the database. (The only thing you need to know is what format in the database
BMP? GIF? JPEG? OLE?)
2. Use session variables to save the number of bytes of graphics and Content Type
ASP needs this information to connect to the attributes in
3. Just put theimg to the place you want to display the graphic, you can display the image.