oneness#910
Hi there
We bulk-scan documents into single page 1 bpp TIFF files that then need to be grouped and merged into multi-page TIFF files before being saved to a SQL dbase (preferably with CCITT4 compression). My code appears to be merging and saving the files but when I attempt to retrieve them I receive the following ;
"An unhandled exception of type 'Aurigma.GraphicsMill.Codecs.MediaUnsupportedException' occurred in aurigma.graphicsmill.dll
Additional information: The media format is not supported"
I believe the error must lie with the way in which I am creating or saving the file(s). I would prefer to be able to work with the multi-page file in memory rather than creating a physical file before saving to the dbase. I would appreciate any comments or advice on my code below:
We bulk-scan documents into single page 1 bpp TIFF files that then need to be grouped and merged into multi-page TIFF files before being saved to a SQL dbase (preferably with CCITT4 compression). My code appears to be merging and saving the files but when I attempt to retrieve them I receive the following ;
"An unhandled exception of type 'Aurigma.GraphicsMill.Codecs.MediaUnsupportedException' occurred in aurigma.graphicsmill.dll
Additional information: The media format is not supported"
I believe the error must lie with the way in which I am creating or saving the file(s). I would prefer to be able to work with the multi-page file in memory rather than creating a physical file before saving to the dbase. I would appreciate any comments or advice on my code below:
Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.Click
Dim m_uebGroup As UltraExplorerBarGroup
Dim m_pages As Integer
Dim m_fi As FileInfo
Dim m_di As DirectoryInfo
Dim m_srcDoc, m_srcSubDoc As String
Dim m_arrFiles As New ArrayList
Dim m_tifWriter As TiffWriter
Dim m_tifReader As TiffReader
Dim m_stream As MemoryStream
Dim m_bm As New GraphicsMill.Bitmap
Dim m_frame As TiffFrame
For Each m_uebGroup In uebImgListBar.Groups
If m_uebGroup.Items.Count() > 0 Then
m_srcDoc = Path.Combine(m_srcDirectoryPath, m_uebGroup.Items(0).Tag.ToString())
If File.Exists(m_srcDoc) Then
m_stream = New MemoryStream
'ensure that all frames in first document are loaded into stream
m_tifWriter = New TiffWriter(m_stream)
AddFrames(m_tifWriter, m_srcDoc)
'Now check that all frames in documents to be merged with
'first document are loaded into stream
m_pages = m_uebGroup.Items.Count
For i As Integer = 1 To m_pages - 1
m_srcSubDoc = Path.Combine(m_srcDirectoryPath, m_uebGroup.Items(i).Tag.ToString())
If File.Exists(m_srcSubDoc) Then
AddFrames(m_tifWriter, m_srcSubDoc)
m_arrFiles.Add(m_srcSubDoc)
Else
'Error
End If
Next
'test write to file
'ERROR occurs on following line
Dim bm_test As New GraphicsMill.Bitmap(m_stream)
bm_test.Save(Path.Combine(m_targetDirectoryPath, Path.ChangeExtension(m_srcDoc, "tif")))
'TODO: use m_stream.GetBuffer() to save to dbase as BLOB
'..........
End Sub
Private Sub AddFrames(ByRef tw As TiffWriter, ByVal src As String)
Dim m_tifReader As New TiffReader(src)
Dim m_bm As New GraphicsMill.Bitmap
For j As Integer = 0 To m_tifReader.FrameCount - 1
m_tifReader.LoadFrame(j).GetBitmap(m_bm)
Dim m_frame As New TiffFrame
m_frame.Compression = CompressionType.Ccitt4
m_frame.SetBitmap(m_bm)
tw.AddFrame(m_frame)
m_frame.Dispose()
Next
m_tifReader.Dispose()
m_bm.Dispose()
End Sub