如何显示数据库中以 OLE 对象方式存储的 JPEG 图片

问题原型: http://expert.csdn.net/Expert/topic/2517/2517974.xml?temp=.4831049

    在 ASP 中, 我们经常需要在 Web 页面上显示以二进制方式保存在数据库中的图片。 一般的图片显示没有什么问题, 因为这方面的文章已经很多了, 我就不再阐述。 但有时候数据库中的图片是通过其他办公软件输入的, 或者通过其他方式, 比如在 Access 中直接添加。 这时, 图片以 OLE 对象的方式保存在数据库中, 在图片真实内容的前面, 还保存了一些其他的信息, 比如图片的路径和文件名,等等。 如果我们还用一般的输出方式的话, 就会出错, 导致图片不能显示。

    幸好 jpeg, bmp 等图象格式中在图片内容的开头都有一个 SOI marker,这个 marker 对于 jpeg 来说是 FFD8, 而对于 bmp424D. 这样一来, 我们只要找到这个 marker 的位置, 就可以忽略前面的内容而直接从这里开始输出图片。以 SQL server 为例,代码如下:

<%
'-------------------------------------------------------------------------------------
' 函数&

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Word 中添加 OLE 对象,可以使用 Java 的 COM Bridge 组件,通过调用 Word 的 COM 接口实现。 以下是一个示例代码,演示如何在 Word 中添加 Excel 表格: ```java import com.jacob.activeX.ActiveXComponent; import com.jacob.com.Dispatch; import com.jacob.com.Variant; public class WordOLE { public static void main(String[] args) { ActiveXComponent word = new ActiveXComponent("Word.Application"); word.setProperty("Visible", new Variant(true)); Dispatch documents = word.getProperty("Documents").toDispatch(); Dispatch document = Dispatch.call(documents, "Add").toDispatch(); Dispatch selection = Dispatch.get(word, "Selection").toDispatch(); // 添加 OLE 对象 Dispatch shapes = Dispatch.get(selection, "Shapes").toDispatch(); Dispatch oleObject = Dispatch.call(shapes, "AddOLEObject", "Excel.Sheet", "C:\\example\\example.xlsx", false, false, "", 0, "", 0).toDispatch(); // 调整 OLE 对象的位置和大小 Dispatch frame = Dispatch.get(oleObject, "Anchor").toDispatch(); Dispatch.call(frame, "Select"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveRight"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(selection, "MoveDown"); Dispatch.call(frame, "Select"); Dispatch.call(oleObject, "Activate"); // 保存并关闭文档 Dispatch.call(document, "SaveAs", "C:\\example\\example.docx"); Dispatch.call(document, "Close", new Variant(false)); Dispatch.call(word, "Quit"); } } ``` 在这个例子中,我们使用了 jacob 库来调用 COM 接口。首先,我们打开 Word 应用程序并创建一个新文档。然后,我们获取当前的选区并在其中添加 OLE 对象。接下来,我们使用选区调整 OLE 对象的位置和大小,然后激活它以确保它能够正常工作。最后,我们保存并关闭文档,并退出 Word 应用程序。 请注意,在此过程中,我们需要提供 Excel 表格的路径和类型。在本例中,我们将路径设置为 "C:\\example\\example.xlsx",并将类型设置为 "Excel.Sheet"。您需要根据您的情况进行更改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值