How to read graphics from Access database

zhaozj2021-02-11  200

How to read graphics from Access database

How to read images1 from the Access database. Graphics Format in Access and FoxPro Database When the browser encounters a flag, it will download the file according to the SRC property you set. This may be a graphic file or an ASP page. If it is a GIF binary ASP page browser, you need to know what the format is returned. For this reason, you need to specify Content Type, which is image / gif, image / bmpimage / jpeg or other. Response.contentType = "image / gif" But this will cause another problem, that is, we can only display the image of the GIF format, or say something saved in the database can only be GIF format. However, some databases are saved using GIF format, but others are saved using JPEG format, and even others are used to save graphics. So we have to set the response content type according to the format of the graph.

Note that you can also create a bitmap object from a file, but save the graphic format stored in the database in this way is that the browser cannot be recognized. 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 the graphic as an OLE format via Access / FoxPro. 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 (this must be used to use Access / FoxPro "in Access / FoxPro (this must be used with Access's Insert Object dialog), this is when you use Image / BMP is not explained when the browser is explained.

Now suppose to save in the database (GIF, JPEG, BMP, TIFF, etc.) now to see how to read them from the database.

Two critical techniques are used in Access to save graphics 1. Use the file header of the BMP format 2.78 bytes

<% Response.expires = 0 response.buffer = true response.clear response.contettype = "image / bmp"%> Then you want to dry is the file header of the 78-byte 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: (of theimg is a proxy page) THEIMG.ASP <% response.expires = 0 response.buffer = true response.clear response.contettype = session ("imagebook") response.binarywrite session ("ImageBytes" session ( "ImageType") = "" 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 = server.createObject ("adoDb.recordset") ors.cursorlocation = 3 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 that it is getempinfo.asp but this has a problem because of the graphics of each employee. With the same "THEIMG.ASP" file, you should make a small modification: " finally said, how Show multiple images? In other words, if there are multiple fields in the database, what should I do? In fact, the solution is simple, just add a parameter to setimageFordisplay plus a parameter to save a session variable. For example: 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. (You do what you need to know is what format BMP? GIF? JPEG? OLE?) 2. Adopting the session variable to save the character number of the graph and the Content Type ASP needs this information to connect to Attribute 3. Just put theimg to the place you want to display the graphic, you can display the image.

转载请注明原文地址:https://www.9cbs.com/read-4150.html

New Post(0)