把导入的图片还原为图片文件

Sub Initialize()
Dim s As New NotesSession
Dim db As NotesDatabase
Set db = s.Currentdatabase
'Set db = New NotesDatabase( "YourServer/svr/somewhere", "database.nsf")

Call ExtractImageResources( db, "J:\temp" )

End Sub
Sub ExtractImageResources(db As NotesDatabase, DestinationDirectory As String)
' =========================================================
' Extracts all GIF and JPG image resource file to <DestinationDirectory>
' DestinationDirectory must exist.
' This code creates 1 tempfile in dest. directory.
' =========================================================
Dim session As New NotesSession
Dim DestinationDir As String
Dim debug As Integer
Dim nc As NotesNoteCollection
Dim exporter As NotesDXLExporter
Dim stream As NotesStream
Dim DXLTempfile As String
Dim inputStream As NotesStream
Dim domParser As NotesDOMParser
Dim RootNode As NotesDOMDocumentNode
Dim n1 As Integer
Dim i As Integer

Dim ImageResource_Nodes As NotesDOMNodeList
Dim MyNode As NotesDOMElementNode
Dim TempNode As NotesDOMElementNode
Dim TempChildNode As NotesDOMNode
Dim MyNodeList As NotesDOMNodeList
Dim attr As NotesDOMAttributeNode
Dim IRFilename As String
Dim MimeEntity As NotesMIMEEntity
Dim outStream As NotesStream
Dim doc As NotesDocument

On Error GoTo err1
debug = 1 ' set to 0 for no debg output
DestinationDir = Trim$(DestinationDirectory)
If Right$( DestinationDir, 1)<>"\" Then DestinationDir = DestinationDir+"\"

' ====================================================
' Define tempfiles - if you manage to make the DXL export/import
' work without tempfiles, let me know !
' =====================================================
DXLTempfile = DestinationDir & "tmp_fileresources.dxl"

' ========================
' Create DXL export stream
' ========================
On Error Resume Next
Kill( DXLTempfile)
On Error GoTo err1
Set stream = session.CreateStream
If Not stream.Open( DXLTempfile,"UTF-8") Then
MessageBox "Cannot create " & DXLTempfile,, "Error"
Exit Sub
End If
Call stream.Truncate

' ===============================
' Build collection of design elements
' ===============================
If debug = 1 Then Print "Building design note document collection"

' ================================
' Export DesignNoteCollection as DXL
' ================================
If debug = 1 Then Print "Exporting image resources to " & DXLTempfile
'Set exporter = session.CreateDXLExporter(nc, stream)
Dim docExport As NotesDocument
Set docExport = db.Getdocumentbyunid("047D60B5DA6AAE384825776800317812")
Set exporter = session.CreateDXLExporter(docExport, stream)
Call exporter.Process
Call stream.Close

' =========================
' Import DXL for parsing
' =========================
If debug = 1 Then Print "Creating DXL import stream from " & DXLTempfile
Set inputStream = session.CreateStream
Call inputStream.Open ( DXLTempfile ,"UTF-8")

' =========================
' Parse DXL
' =========================
Print "Parsing DXL"
Set domParser=session.CreateDOMParser(inputStream)
domParser.Process
' =======================
' Get the root node
' ======================
Set rootNode = domParser.Document
' =========================
' Get all ImageResourceNodes
' =========================
'Set ImageResource_Nodes = RootNode.GetElementsByTagName( "imageresource" )
Set ImageResource_Nodes = RootNode.GetElementsByTagName( "jpeg" )
If debug=1 Then Print "Found " & ImageResource_Nodes.NumberOfEntries & " image resources"
If ImageResource_Nodes.NumberOfEntries=0 Then
Print "No <imageresource> node found - exiting"
GoTo finish
End If

' =============================================
' Browse all <imageresource> nodes and extract images
' from <gif> / <jpeg> child nodes
' =============================================


IRFilename = "DLTitle.jpg"

Set TempNode = ImageResource_Nodes.GetItem(1)
Set TempChildNode = TempNode.firstchild
' TempChild.NodeValue contains the base64 encoded image data

' Create output stream / file
If debug=1 Then Print "Create output file " & DestinationDir & IRFilename
Set outStream = session.CreateStream
On Error Resume Next
Kill (DestinationDir & IRFilename)
On Error GoTo err1
Call outStream.Open( DestinationDir & IRFilename, "binary")

' Create Input Stream and write Base64 data to stream
Set stream = session.CreateStream
MsgBox CStr(TempChildNode.NodeValue)
Call stream.WriteText(TempChildNode.NodeValue)

' Decode base64 and write to outstream / file
If debug=1 Then Print "Decoding Base64 to binary"
Set doc = New NotesDocument(session.CurrentDatabase )
Set MimeEntity = doc.CreateMIMEEntity
Call MimeEntity.SetContentFromBytes(stream,"", ENC_BASE64)
Call MimeEntity.GetContentAsBytes(outStream, True)
Call MimeEntity.DEcodeContent()
Call outstream.Close
Call stream.close

Call inputstream.close

finish:
If debug=1 Then Print "Removing tempfiles"
On Error Resume Next
Kill(DXLTempfile)
On Error GoTo err1
Print
Exit Sub

err1:
Print Error$ & " in line " & Erl
MessageBox Error$ & " in line " & Erl
Exit Sub
End Sub
Python可以使用第三方库Pillow来还原和验证图片。Pillow是一个Python图像处理库,它提供了许多函数和方法来处理图像。要还原和验证图片,可以按照以下步骤进行操作: 1. 导入Pillow库:首先,我们需要在Python脚本中导入Pillow库。可以使用以下代码将其导入: ```python from PIL import Image ``` 2. 打开图片:使用Pillow库中的open函数来打开要处理的图片文件。例如,可以使用以下代码来打开一张图片: ```python image = Image.open('image.jpg') ``` 3. 还原图片:利用Pillow库的函数和方法,可以对打开的图片进行还原处理。具体的还原方法取决于图片的损坏情况和需要还原的内容。例如,可以使用Pillow库的修复函数来修复损坏的图片: ```python repaired_image = image.repair() ``` 4. 验证图片还原后的图片可以与原始图片进行比较,以验证还原的效果。可以使用Pillow库的compare函数来比较两张图片的差异。例如,可以使用以下代码来比较两张图片的差别: ```python diff = ImageChops.difference(original_image, repaired_image) ``` 如果差异很小,说明还原的效果较好;如果差异较大,说明还原的效果不理想。 5. 保存图片:最后,可以使用Pillow库的save函数将还原后的图片保存到新的文件中。例如,可以使用以下代码将还原后的图片保存为新的文件: ```python repaired_image.save('repaired_image.jpg') ``` 综上所述,可以使用Python和Pillow库来还原和验证图片。根据图片的损坏情况和需要还原的内容,可以调用Pillow库中的函数和方法进行相应的处理,然后将还原后的图片与原始图片进行比较以验证还原效果的好坏。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值