Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
oneness  
#1 Posted : Tuesday, April 04, 2006 6:59:50 PM(UTC)
oneness

Rank: Member

Groups: Member
Joined: 4/3/2006(UTC)
Posts: 4

Hi again

I've had a go at simplifying things just so that I can get something working in the interim. Now atleast I am able to merge single-page tifs, compress and save them to the dbase - after first writing the merged file to disk (and if I view the merged file in the Microsoft Document Imaging app I can see that the files were merged correctly). But I have only had partial success at retrieving/loading the multi-page tif documents from the dbase - I can only view the first frame and the TiffReader.FrameCount returns 1. Saving the byte array (returned from the dbase) as a tif file also only creates a single-page tif. Once again I have included a code snippet and I'm hoping someone will be able to shed some light;

This is what I'm using to merge and save to dbase:

Code:
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, m_targetDoc As String
       
 
        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
                    Dim m_bm As New GraphicsMill.Bitmap
                    m_bm.Load(m_srcDoc)
                    m_di = New DirectoryInfo(m_targetDirectoryPath)
                    If Not m_di.Exists Then m_di.Create()
                    m_targetDoc = Path.Combine(m_targetDirectoryPath, Path.ChangeExtension(m_uebGroup.Text, "tif"))
                    Dim m_tifWriter As New TiffWriter(m_targetDoc)
                    Dim m_frame As New TiffFrame
                    m_frame.Compression = CompressionType.Ccitt4
                    m_frame.SetBitmap(m_bm)
                    m_tifWriter.AddFrame(m_frame)
                    m_frame.Dispose()

                    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
                            m_bm.Load(m_srcSubDoc)
                            m_frame = New TiffFrame
                            m_frame.Compression = CompressionType.Ccitt4
                            m_frame.SetBitmap(m_bm)
                            m_tifWriter.AddFrame(m_frame)
                            m_frame.Dispose()
                            
                        Else
                            'Error
                        End If
                    Next

                    m_bm.Dispose()
                    m_tifWriter.Dispose()

                    ImportImage(m_targetDoc)

                   .............

End Sub

Private Sub ImportImage(ByVal FilePath As String)

                    Dim strm As New MemoryStream
                    Dim bm As New Aurigma.GraphicsMill.Bitmap(FilePath)

                    bm.Save(strm, New TiffEncoderOptions(CompressionType.Ccitt4))


                    ''// create a new media object
                    Dim objMedia As New Objects.Media
                    objMedia.MediaBatchID = objMediaBatch.MediaBatchID
                    objMedia.MediaTypeID = 1 '// this is an image
                    ''// set the image property to the compressed image byte array

                    objMedia.Image = strm.ToArray()

                    .........

    End Sub


And this is what I'm using to display from the dbase:

Code:
                   ..............

                   ' test - try writing byte array from dbase to file 
                    Dim strmtest As New MemoryStream(media.Image)
                    Dim bmtest As New GraphicsMill.Bitmap(strmtest)
                    bmtest.Save("D:\My Documents\Projects\ImageMerger\Ian\out\test.tif")

                    'write byte array from dbase to stream
                    Dim objStream As New MemoryStream
                    objStream.Write(media.Image, 0, media.Image.Length)
                    ' create tifreader
                    Me.rdrFormat = FormatManager.CreateFormatReader(objStream)
                    If Me.rdrFormat.MediaFormat = FormatManager.TiffFormat Then

                        m_frameCount = Me.rdrFormat.FrameCount ' returns 1 - even when there should be more

                        Dim frame As TiffFrame = CType(Me.rdrFormat.LoadFrame(0), TiffFrame)
                        frame.GetBitmap(Me.vwrDocument.Bitmap)
                        frame.Dispose()
                    Else

...............

Edited by user Thursday, December 20, 2007 4:52:03 PM(UTC)  | Reason: Not specified

Alex Kon  
#2 Posted : Tuesday, April 04, 2006 9:36:44 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Member
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hello,

It's hard to debug without seeing all code, but the following lines looks suspicious - you load a single bitmap into memory stream:
Code:
Dim strm As New MemoryStream
Dim bm As New Aurigma.GraphicsMill.Bitmap(FilePath)
bm.Save(strm, New TiffEncoderOptions(CompressionType.Ccitt4))
<...skipped...>
objMedia.Image = strm.ToArray()
and after that you read it again:
Code:
Dim objStream As New MemoryStream
objStream.Write(media.Image, 0, media.Image.Length)
' create tifreader
Me.rdrFormat = FormatManager.CreateFormatReader(objStream)
If Me.rdrFormat.MediaFormat = FormatManager.TiffFormat Then
m_frameCount = Me.rdrFormat.FrameCount ' returns 1 - even when there should be more

Perhaps this is a reason why FramesCount property value is always 1. If I am wrong, try to reproduce the problem in less specific code or try to use the code snippet I have posted in another your topic on this forum. You can contact me by email if you don't want to publish code on the public forum.

Edited by user Thursday, December 20, 2007 4:52:47 PM(UTC)  | Reason: Not specified

oneness  
#3 Posted : Thursday, April 06, 2006 4:03:41 PM(UTC)
oneness

Rank: Member

Groups: Member
Joined: 4/3/2006(UTC)
Posts: 4

Hi Alex,

You're quite right, I am doing both but in two different places - I only showed them both together here because I wasn't sure where exactly I was going wrong, so that you could see where I was merging and saving to dbase and then also how I was later retrieving and displaying from dbase.

Anyway, thanks to your tips in the reply to my earlier post I have managed to sort it all out.

Keep well

Ian.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.