Link to home
Start Free TrialLog in
Avatar of LostinSpace
LostinSpaceFlag for Australia

asked on

Insert Multi Page Tiff into Firebird database in vb.net

I'm trying to break apart  a multipage tiff and have each page inserted into a firebird db as a separate blob for each page.

I've found examples of how to loop through each page of the tiff but am unsure of how to convert the single page image already load into memory into a filestream which  is needed for the blob insert.

I cant use this
Dim fs As FileStream = New FileStream(curfilename, FileMode.OpenOrCreate, FileAccess.Read)
as the the file stream will be the entire tiff - not a single page of the file.

Also how do you discard the original tiff and individual images from memory once all the inserts have been completed

Thanks in advance


Sub Split_MultipageTiff(ByVal filename)
        Dim image As Image = image.FromFile(filename)
        Dim single_page_image As Image
        Dim guid = image.FrameDimensionsList(0)
        Dim dimension = New FrameDimension(guid)
        Dim totalFrame = image.GetFrameCount(dimension)
        Dim file_suffix As String = Path.GetExtension(filename)
        Dim file_Prefix As String = Path.GetFileNameWithoutExtension(filename)
        Dim Newfile_Name As String
 
        Dim sqlConnection1 As New FirebirdSql.Data.FirebirdClient.FbConnection(connectionstring)
        Dim cmd As New FirebirdSql.Data.FirebirdClient.FbCommand
        Dim fs As FileStream = new FileStream(??????
        Dim rawdata() As Byte = New Byte(fs.Length) {}
 
        For i As Integer = 0 To totalFrame - 1
            Newfile_Name = file_Prefix + "_" + Convert.ToString(i) + file_suffix
            image.SelectActiveFrame(dimension, i)
            single_page_image = image.Clone
            '??????Convert single_page_image into a rawdata()
 
            Try
                cmd.CommandText = "INSERT INTO ELMO (FILETIMESTAMP, FILENAME, IMAGE_SCAN) VALUES (@FILETIMESTAMP, @FILENAME, @BLOBDATA);"
                cmd.Parameters.Add("@BLOBDATA", rawdata)
 
etc

Open in new window

SOLUTION
Avatar of Juan_Barrera
Juan_Barrera
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial