文谷首页 | 业界传真 | 网络技术 | 服务器 | 数据库 | 存储技术 | 系统安全 | 无线技术 | Cisco | .Net | Windows | Linux | Unix | Java
电子商务 | 网站工程 | 网页设计 | 平面设计 | 多媒体 | 编程语言 | Oracle | MSSQL | Photoshop | ASP | PHP | 实用技巧 | 进程查询 | 文谷论坛
 Sybase   Oracle   SQL server   Informix   MySQL   Access   VFP   DB2   PostgreSQL   其它数据库
您现在的位置: IT文谷 >> 数据库技术 >> Access >> 文章正文
从Access数据库恢复BMP图像并显示在WEB页面(microsoft)2006-3-26 13:17:57从Access数据库恢复BMP图像并显示在WEB页面(microsoft)2006-3-26 13:17:57从Access数据库恢复BMP图像并显示在WEB页面(microsoft)
从Access数据库恢复BMP图像并显示在WEB页面(microsoft)2006-3-26 13:17:57从Access数据库恢复BMP图像并显示在WEB页面(microsoft)2006-3-26 13:17:57从Access数据库恢复BMP图像并显示在WEB页面(microsoft)
从Access数据库恢复BMP图像并显示在WEB页面(microsoft)

从Access数据库恢复BMP图像并显示在WEB页面(microsoft)2006-3-26 13:17:57从Access数据库恢复BMP图像并显示在WEB页面(microsoft)2006-3-26 13:17:57从Access数据库恢复BMP图像并显示在WEB页面(microsoft)
HOWTO: Retrieving Bitmap from Access and Displaying In Web Page

--------------------------------------------------------------------------------
The information in this article applies to:

Active Server Pages
Microsoft Visual Basic Professional and Enterprise Editions for Windows, versions 5.0, 6.0
ActiveX Data Objects (ADO), versions 1.0, 1.5, 2.0, 2.1 SP2, 2.5
Microsoft Internet Information Server versions 4.0, 5.0
Microsoft Data Access Components version 2.5

--------------------------------------------------------------------------------


SUMMARY
This article shows by example how to extract the bitmap photos in the Microsoft Access 97 Northwind.mdb
database, and view them from a Web browser using Active Server Pages (ASP). In order to accomplish this
task, an ActiveX DLL must be created that strips the Access and OLE headers from the field. This article
shows how to create this ActiveX DLL, and how to implement it.



MORE INFORMATION
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this
code "as is" without warranty of any kind, either express or implied, including but not limited to the
implied warranties of merchantability and/or fitness for a particular purpose.

This article demonstrates how to use Visual Basic to retrieve a bitmap stored in an OLE Object field.
Because the definition of OLE object storage is not documented, the following code searches the object's
OLE header for characters consistent with the start of the graphic. This method may not work in all
circumstances.

Be aware that Internet Explorer 3.0 is unable to display true color bitmaps. For this reason, the bitmaps
stored in the Access database should be no higher than 256 colors.

Step-by-Step Example to Extract the Photos
Create a new project in Visual Basic and make the project an ActiveX DLL.


Add a reference to ActiveX Data Objects (ADO) by clicking the Project menu and selecting References.
Select "Microsoft OLE DB ActiveX Data Objects 1.0 Library" and click OK.


Add a new module to the project by selecting the Project menu and clicking Add Module. Select Module and
click Open.


Place the following code in the (general) (declarations) section of MODULE1.BAS:

      ' Enter the following Declare statement as one single line:
      Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
       (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)

      Type PT
        Width As Integer
        Height As Integer
      End Type

      Type OBJECTHEADER
        Signature As Integer
        HeaderSize As Integer
        ObjectType As Long
        NameLen As Integer
        ClassLen As Integer
        NameOffset As Integer
        ClassOFfset As Integer
        ObjectSize As PT
        OleInfo As String * 256
      End Type



Place the following code in the (general) (declarations) section of CLASS1.CLS:

        Function DisplayBitmap(ByVal OleField As Variant)
        Dim Arr() As Byte
        Dim ObjHeader As OBJECTHEADER
        Dim Buffer As String
        Dim ObjectOffset As Long
        Dim BitmapOffset As Long
        Dim BitmapHeaderOffset As Integer
        Dim ArrBmp() As Byte
        Dim i As Long

        'Resize the array, then fill it with
        'the entire contents of the field
        ReDim Arr(OleField.ActualSize)
        Arr() = OleField.GetChunk(OleField.ActualSize)

        'Copy the first 19 bytes into a variable
        'of the OBJECTHEADER user defined type.
        CopyMemory ObjHeader, Arr(0), 19

        'Determine where the Access Header ends.
        ObjectOffset = ObjHeader.HeaderSize + 1

        'Grab enough bytes after the OLE header to get the bitmap header.
        Buffer = ""
        For i = ObjectOffset To ObjectOffset + 512
            Buffer = Buffer & Chr(Arr(i))
        Next i

        'Make sure the class of the object is a Paint Brush object
        If Mid(Buffer, 12, 6) = "PBrush" Then
            BitmapHeaderOffset = InStr(Buffer, "BM")
            If BitmapHeaderOffset > 0 Then

                'Calculate the beginning of the bitmap
                BitmapOffset = ObjectOffset + BitmapHeaderOffset - 1

                'Move the bitmap into its own array
                ReDim ArrBmp(UBound(Arr) - BitmapOffset)
                CopyMemory ArrBmp(0), Arr(BitmapOffset), UBound(Arr) -
                 BitmapOffset + 1

                'Return the bitmap
                DisplayBitmap = ArrBmp
            End If
        End If
      End Function



Rename the Project by selecting the Project menu, and clicking on "Project1 Properties" and type your new
name in the "Project Name" field. This example assumes that you named the project "MyProject" and will
refer to that name in future steps.


Make the project Apartment Model Threaded by selecting the "Unattended Execution" check box. Click OK.


Rename the Class in the Property Pane. This example assumes that you named the class "MyClass" and refers
to that name in future steps.


Compile the DLL by clicking the File menu and selecting "Make MyProject.dll."


Create an ASP page named "bitmap.asp" that contains the following code:

      <%@ LANGUAGE="VBSCRIPT" %>
      <%
      '   You need to set up a System DSN named 'NWind' that points to
      '   the Northwind.mdb database
      Set DataConn = Server.CreateObject("ADODB.Connection")
      DataConn.Open "DSN=NWind", "admin", ""
      Set cmdTemp = Server.CreateObject("ADODB.Command")
      Set RS = Server.CreateObject("ADODB.Recordset")
      cmdTemp.CommandText = "SELECT Photo FROM Employees
        WHERE EmployeeID = 1"
      cmdTemp.CommandType = 1
      Set cmdTemp.ActiveConnection = DataConn
      RS.Open cmdTemp, , 0, 1
      Response.ContentType = "image/bmp"
      Set Bitmap = Server.CreateObject("MyProject.MyClass")
      Response.BinaryWrite Bitmap.DisplayBitmap(RS("Photo"))
      RS.Close
      %>



Create an HTML page named "BitmapTest.htm" that contains the following code:

      <HTML>
      <HEAD>
      <TITLE>Bitmap Test</TITLE>
      </HEAD>
      <BODY>
  &
从Access数据库恢复BMP图像并显示在WEB页面(microsoft)2006-3-26 13:17:57从Access数据库恢复BMP图像并显示在WEB页面(microsoft)2006-3-26 13:17:57从Access数据库恢复BMP图像并显示在WEB页面(microsoft)
  • 上一篇文章:

  • 下一篇文章:
  • 进入论坛讨论

    相关文章
    _disable_logging对于性能的影响
    针对Oracle数据库的优化器详细介绍
    索引与Null值对于Hints及执行计划的影响
    了解 Oracle ADF:入门示例
    DataGuard数据库服务器硬盘故障处理
    用sql比较两个数据库是否一致
    用触发器生成数据库表的数据操作日志
    查询Oracle各组件的版本信息
    Oracle入门基础:绑定变量测试
    Oracle的db_name和instance_name
    一个容易忽视的Oracle数据安全问题
    Oracle时间信息特性
    热门文章最新推荐

    版权与免责声明:
    ① 本网转载其他媒体稿件是为传播更多的信息,此类稿件不代表本网观点,版权归原作者所有,本网不承担此类稿件侵权行为的连带责任。
    ② 在本网BBS上发表言论者,文责自负。
    ③ 如您因版权等问题需要与本网联络,请在30日内联系 。
    从Access数据库恢复BMP图像并显示在WEB页面(microsoft)2006-3-26 13:17:57从Access数据库恢复BMP图像并显示在WEB页面(microsoft)2006-3-26 13:17:57从Access数据库恢复BMP图像并显示在WEB页面(microsoft)
    从Access数据库恢复BMP图像并显示在WEB页面(microsoft)2006-3-26 13:17:57从Access数据库恢复BMP图像并显示在WEB页面(microsoft)2006-3-26 13:17:57从Access数据库恢复BMP图像并显示在WEB页面(microsoft)

    数据库专题
    人气排行
    普通文章SQL Server数据库的备份与恢
    普通文章从MDF文件恢复Sql Server200
    普通文章SQL中,单引号与&等特殊符号
    普通文章SQL Server定期自动备份
    普通文章通过ODBC连接的SQL SERVER实
    普通文章SQL入门:删除数据
    普通文章sqlldr的用法总结
    普通文章XP下access数据不能更新,数据
    普通文章在SQL Server的存储过程中调
    普通文章SQL Server的有效安装
    最近更新
    推荐文章如何恢复/修复MS SQL数据库的
    普通文章Mysql和phpMyAdmin的设置
    普通文章phpmyadmin设置和常见问题
    普通文章PhpMyAdmin配置示例
    普通文章php+mysql中文乱码的解决
    普通文章phpmyadmin配置
    推荐文章Oracle函数列表速查
    普通文章_disable_logging对于性能的
    普通文章针对Oracle数据库的优化器详
    普通文章索引与Null值对于Hints及执行
    全站热点       
    最新推荐
    关于文谷 | 联系文谷 | 免责声明 | 文谷论坛
    Tel: 0577-65690019      E-mail: ichenjian@gmail.com    MSN:ichenjian@hotmail.com    QQ:2911194
    Copyright © 2004-2008 wengu.com 文谷 All Rights Reserved
    浙ICP备05000327号