Results 1 to 14 of 14

Thread: [RESOLVED] Drawing image to Multi-page tiff file.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Resolved [RESOLVED] Drawing image to Multi-page tiff file.

    Ok what's happening is I'm pulling in a Tiff file that can have multiple pages. I selected the first frame, draw a stamp image to it and save it as a different file name.

    When I do this, it is only saving the first page of the tiff file. How do I get all of the pages to save?

    Here is my code:

    vb Code:
    1. NetDMS.exportDocumentImageWithAnnotations(_workflow, disn, "C:\JCEmailFld", "emailDocument" + currEmailDoc.ToString)
    2.             Dim documentFile As Bitmap = Bitmap.FromStream(ImageIO.GetStream("C:\JCEmailFld\" + "emailDocument" + currEmailDoc.ToString + ".TIF"))
    3.             Dim stampFile As Bitmap = Bitmap.FromStream(ImageIO.GetStream("\\server\Stamps\DClerkCertifiedCopy.gif"))
    4.  
    5.             For i As Integer = 235 To 255
    6.                 stampFile.MakeTransparent(Color.FromArgb(i, i, i))
    7.             Next
    8.  
    9.             Dim docketGID As Guid = documentFile.FrameDimensionsList(0)
    10.             Dim frameDimension As New Drawing.Imaging.FrameDimension(docketGID)
    11.             documentFile.SelectActiveFrame(frameDimension, 0)
    12.  
    13.             Try
    14.                 Dim g As Graphics = Graphics.FromImage(CType(documentFile, Image))
    15.                 g.DrawImage(CType(stampFile, Image).Clone(), CInt(stampFile.Width / 2), ((documentFile.Height - stampFile.Height) - CInt(stampFile.Height / 2)), stampFile.Width, stampFile.Height)
    16.                 g.Dispose()
    17.             Catch ex As Exception
    18.                 MessageBox.Show("Error applying stamp: " + ex.Message)
    19.             End Try
    20.  
    21.             documentFile.Save("C:\JCEmailFld\emailFinalDocument" + currEmailDoc.ToString + ".TIF", ImageFormat.Tiff)
    22.  
    23.             documentFile.Dispose()
    24.             stampFile.Dispose()

    Thanks,

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Drawing image to Multi-page tiff file.

    Ok, I figured out what to do to get the pages all together after I add the stamp to the first page. I have another problem though.

    I'm using an Export function provided by our third party DMS software vendor.

    The resulting tiff image (when exported) has a compressionLZW, and for some reason the tifftopdf function they provided doesn't like that compression and the pdf's are unreadable. But if it exports the the file with a compressionCCITT4 then the tifftopdf function makes a good pdf file.

    My problem is, when I open the image to add the stamp, when I save it, it has a compression of LZW, even though the original file had the CCITT4.

    My code is below...

    I'm getting an error on the line:

    'documentFile.Save("C:\JCEmailFld\" + disn(1) + currEmailDoc.ToString + ".TIF", info, ep)'

    The error is "Parameter not valid". And it's referring to the compression encoderparameter I'm sure, because if I change it to the Encodervalue.compressionLZW it doesn't complain.

    Code:
    
     Dim enc As Encoder = Encoder.SaveFlag
                Dim enc2 As Encoder = Encoder.Compression
                Dim ep As New EncoderParameters(2)
    
    
    
                Dim info As ImageCodecInfo = Nothing
    
                For Each ice As ImageCodecInfo In ImageCodecInfo.GetImageEncoders
                    MessageBox.Show(ice.MimeType.ToString)
                    If ice.MimeType = "image/tiff" Then
    
                        info = ice
    
                    End If
    
                Next
    
                ep.Param(0) = New EncoderParameter(enc2, CType(EncoderValue.CompressionCCITT4, Long))
                ep.Param(1) = New EncoderParameter(enc, CType(EncoderValue.MultiFrame, Long))
    
                Dim fileExt As String = NetDMS.exportDocumentImageWithAnnotations(_workflow, disn(0), "C:\JCEmailFld", "emailDocument" + currEmailDoc.ToString)
                Dim documentFile As Image = Image.FromFile("C:\JCEmailFld\" + "emailDocument" + currEmailDoc.ToString + fileExt)
    
    
                Dim temp As New Bitmap(documentFile.Width, documentFile.Height, PixelFormat.Format32bppArgb)
                temp.SetResolution(documentFile.HorizontalResolution, documentFile.VerticalResolution)
    
                Try
                    Dim graph As Graphics = Graphics.FromImage(CType(temp, Image))
                    graph.DrawImage(CType(documentFile, Image).Clone, New Point(0, 0))
                    graph.Dispose()
                Catch ex As Exception
    
                End Try
                documentFile = CType(temp, Image)
    
                Dim stampFile As Bitmap = Bitmap.FromFile("\\visiflowserver1\visiflow\netDMS\Stamps\DClerkCertifiedCopy.gif")
    
                For i As Integer = 235 To 255
                    stampFile.MakeTransparent(Color.FromArgb(i, i, i))
                Next
    
                documentFile.SelectActiveFrame(FrameDimension.Page, 0)
    
                Try
                    Dim g As Graphics = Graphics.FromImage(CType(documentFile, Image))
                    g.DrawImage(CType(stampFile, Image).Clone(), CInt(stampFile.Width / 4), ((documentFile.Height - stampFile.Height) - CInt(stampFile.Height / 2)), stampFile.Width, stampFile.Height)
                    g.Dispose()
                Catch ex As Exception
                    MessageBox.Show("Error applying stamp: " + ex.Message)
                End Try
    
                If fileExt = ".TIF" Then
                    documentFile.Save("C:\JCEmailFld\" + disn(1) + currEmailDoc.ToString + ".TIF", info, ep)
                    ep.Param(1) = New EncoderParameter(enc, CType(EncoderValue.FrameDimensionPage, Long))
                    For k As Integer = 1 To documentFile.GetFrameCount(FrameDimension.Page) - 1
                        documentFile.SelectActiveFrame(FrameDimension.Page, k)
                        documentFile.SaveAdd(documentFile, ep)
                    Next
    
                    ep.Param(1) = New EncoderParameter(enc, CType(EncoderValue.Flush, Long))
                    documentFile.SaveAdd(ep)
                Else
                    documentFile.Save("C:\JCEmailFld\" + disn(1) + currEmailDoc.ToString + ".BMP", ImageFormat.Bmp)
                End If
    
                documentFile.Dispose()
                stampFile.Dispose()
    Thanks,

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Drawing image to Multi-page tiff file.

    Ok so I've boiled down the specific problem now. I can open a bunch of single page tif files, and then add them to each other with the imagecodecinfo and encoder parameters and the compression saves and is all good.

    The problem comes, when I open a tif file, draw an image to it, save it as a tif with the imageformat, and then re open it and save it with the imagecodecinfo and the encoder params.

    Here is a snippet of code that throws the error.

    vb Code:
    1. Dim comEncoder As Encoder = Encoder.Compression
    2.         Dim savEncoder As Encoder = Encoder.SaveFlag
    3.  
    4.         Dim ep As New EncoderParameters(2)
    5.         ep.Param(0) = New EncoderParameter(comEncoder, CLng(EncoderValue.CompressionCCITT4))
    6.         ep.Param(1) = New EncoderParameter(savEncoder, CLng(EncoderValue.MultiFrame))
    7.  
    8.         Dim codecInfo As ImageCodecInfo = GetCodecInfo("image/tiff")
    9.  
    10.         Dim finalImageName As String = ""
    11.         Dim edittedPageName As String = ""
    12.  
    13.         Dim bitmap As Bitmap = bitmap.FromFile("C:\JCEmailFld\MultiPageCCITT4Compression.tif") 'has indexed pixel format.
    14.         Dim stamp As Bitmap = bitmap.FromFile("\\visiflowserver1\visiflow\netDMS\Stamps\DClerkCertifiedCopy.gif")
    15.         Dim nonindexedstamp As Bitmap 'object that holds the new nonindex pixel format stamp
    16.         'convert stamp to nonindexed pixelformat as well (format24bpprgb)
    17.  
    18.         If Not stamp.PixelFormat = PixelFormat.Format24bppRgb Then
    19.  
    20.             nonindexedstamp = New Bitmap(stamp.Width, stamp.Height, PixelFormat.Format24bppRgb)
    21.             Dim g As Graphics = Graphics.FromImage(CType(nonindexedstamp, Image))
    22.             g.DrawImage(CType(stamp, Image), New Point(0, 0))
    23.             g.Dispose()
    24.  
    25.         End If
    26.  
    27.         Dim pageFiles As New ArrayList
    28.  
    29.         'Save each page as an individual tiff file.
    30.         For i As Integer = 0 To bitmap.GetFrameCount(FrameDimension.Page) - 1
    31.             bitmap.SelectActiveFrame(FrameDimension.Page, i)
    32.             Dim filename As String = "C:\JCEmailFld\" + Now.ToFileTime.ToString + "_Page" + i.ToString + ".tif"
    33.             bitmap.Save(filename)
    34.             pageFiles.Add(filename)
    35.         Next
    36.         bitmap.Dispose()
    37.  
    38.         'get the first page.
    39.         Dim firstPage As Bitmap = bitmap.FromFile(pageFiles(0))
    40.         Dim edittedFirstPage As Bitmap 'The bitmap we'll store the newly editted first page to.
    41.  
    42.         'if the tif image has an indexed pixel format or an undefined one create a new
    43.         'bitmap image with format24bpprgb (or any other format besides indexed so we can
    44.         'get a graphics object to draw on).
    45.         If firstPage.PixelFormat = PixelFormat.Format1bppIndexed Or _
    46.            firstPage.PixelFormat = PixelFormat.Format4bppIndexed Or _
    47.            firstPage.PixelFormat = PixelFormat.Format8bppIndexed Or _
    48.            firstPage.PixelFormat = PixelFormat.Indexed Or _
    49.            firstPage.PixelFormat = PixelFormat.Undefined Then
    50.  
    51.             Dim temp As New Bitmap(firstPage.Width, firstPage.Height, PixelFormat.Format24bppRgb) 'the new bitmap we will draw the first page to.
    52.  
    53.             Dim g As Graphics = Graphics.FromImage(CType(temp, Image))
    54.             g.DrawImage(CType(nonindexedstamp, Image), New Point(0, 0))
    55.             g.Dispose()
    56.  
    57.             Dim newFileName As String = "C:\JCEmailFld\" + Now.ToFileTime.ToString + "_EdittedPage0.tif"
    58.             temp.Save(newFileName, ImageFormat.Tiff)
    59.             temp.Dispose()
    60.  
    61.             edittedFirstPage = bitmap.FromFile(newFileName)
    62.         End If
    63.  
    64.         'Save the edittedfirstpage as tiff with codecInfo and Mulitpage/Compression parameters.
    65.         edittedFirstPage.Save("C:\JCEmailFld\" + Now.ToFileTime.ToString + "_FinalImage.tif", codecInfo, ep)
    66.  
    67.         ep.Param(1) = New EncoderParameter(savEncoder, CLng(EncoderValue.FrameDimensionPage))
    68.  
    69.         For j As Integer = 1 To pageFiles.Count - 1
    70.  
    71.             Dim pageFile As Bitmap = bitmap.FromFile(pageFiles(j))
    72.             edittedFirstPage.SaveAdd(CType(pageFile, Image), ep)
    73.             pageFile.Dispose()
    74.  
    75.         Next
    76.  
    77.         ep.Param(1) = New EncoderParameter(savEncoder, CLng(EncoderValue.Flush))
    78.         edittedFirstPage.SaveAdd(ep)

    in the above code I get the "parameter not valid" error at the first save:

    vb Code:
    1. 'Save the edittedfirstpage as tiff with codecInfo and Mulitpage/Compression parameters.
    2.         edittedFirstPage.Save("C:\JCEmailFld\" + Now.ToFileTime.ToString + "_FinalImage.tif", codecInfo, ep)

    If i take out the part where I draw the stamp to the first page, the first page will save with the compression and multipage parameters just fine.

    How can I edit the tif and get it to save to where I can open back up and add more tif files to it?

    Thanks,

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Drawing image to Multi-page tiff file.

    Ok I have it working now. You have to convert the tiff image back to Format1bppIndexed for it to save the compression right.

    I found some code that converted a Format32bppPArgb to Format1bppIndexed from BobPowell.Net

    Here is the working code, now I just have to load all the additional tiff pages into memory so I don't have to have a temp directory.

    vb Code:
    1. Dim comEncoder As Encoder = Encoder.Compression
    2.         Dim savEncoder As Encoder = Encoder.SaveFlag
    3.  
    4.         Dim ep As New EncoderParameters(2)
    5.         ep.Param(0) = New EncoderParameter(comEncoder, CLng(EncoderValue.CompressionCCITT4))
    6.         ep.Param(1) = New EncoderParameter(savEncoder, CLng(EncoderValue.MultiFrame))
    7.  
    8.         Dim codecInfo As ImageCodecInfo = GetCodecInfo("image/tiff")
    9.  
    10.         Dim finalImageName As String = ""
    11.         Dim edittedPageName As String = ""
    12.  
    13.         Dim bitmap As Image = Image.FromFile("C:\JCEmailFld\MultiPageCCITT4Compression.tif") 'has indexed pixel format.
    14.  
    15.         MessageBox.Show(bitmap.PixelFormat.ToString)
    16.  
    17.         Dim stamp As Image = Image.FromFile("\\visiflowserver1\visiflow\netDMS\Stamps\DClerkCertifiedCopy.gif")
    18.         Dim nonindexedstamp As Image 'object that holds the new nonindex pixel format stamp
    19.  
    20.         'convert stamp to nonindexed pixelformat as well (format24bpprgb), the same format as the first tiff page will be.
    21.         If Not stamp.PixelFormat = PixelFormat.Format24bppRgb Then
    22.  
    23.             nonindexedstamp = New Bitmap(stamp.Width, stamp.Height, PixelFormat.Format32bppPArgb)
    24.             Dim g As Graphics = Graphics.FromImage(CType(nonindexedstamp, Image))
    25.             g.DrawImage(stamp, New Point(0, 0))
    26.             g.Dispose()
    27.  
    28.         End If
    29.  
    30.         'keep track of the pages for later combination.
    31.         Dim pageFiles As New ArrayList
    32.  
    33.         'Save each page as an individual tiff file.
    34.         For i As Integer = 0 To bitmap.GetFrameCount(FrameDimension.Page) - 1
    35.             bitmap.SelectActiveFrame(FrameDimension.Page, i)
    36.             Dim filename As String = "C:\JCEmailFld\" + Now.ToFileTime.ToString + "_Page" + i.ToString + ".tif"
    37.             bitmap.Save(filename, ImageFormat.Tiff)
    38.             pageFiles.Add(filename)
    39.         Next
    40.         bitmap.Dispose()
    41.  
    42.         'get the first page.
    43.         Dim firstPage As Bitmap = bitmap.FromFile(pageFiles(0))
    44.         Dim edittedFirstPage As Bitmap 'The bitmap we'll store the newly editted first page to.
    45.  
    46.         'if the tif image has an indexed pixel format or an undefined one create a new
    47.         'bitmap image with format24bpprgb (or any other format besides indeded so we can
    48.         'get a graphics object to draw on).
    49.         If firstPage.PixelFormat = PixelFormat.Format1bppIndexed Or _
    50.            firstPage.PixelFormat = PixelFormat.Format4bppIndexed Or _
    51.            firstPage.PixelFormat = PixelFormat.Format8bppIndexed Or _
    52.            firstPage.PixelFormat = PixelFormat.Indexed Or _
    53.            firstPage.PixelFormat = PixelFormat.Undefined Then
    54.  
    55.             Dim temp As New Bitmap(firstPage.Width, firstPage.Height, PixelFormat.Format32bppPArgb) 'the new bitmap we will draw the first page to.
    56.  
    57.             'draw the stamp to the first page (this is what is causing the problem for the Bitmap.save(filename,codecinfo,ep) call).
    58.             Dim g As Graphics = Graphics.FromImage(CType(temp, Image))
    59.             g.DrawImage(CType(firstPage, Image), 0, 0, firstPage.Width, firstPage.Height)
    60.             g.DrawImage(nonindexedstamp, CInt(nonindexedstamp.Width / 4), (temp.Height - nonindexedstamp.Height) - CInt(nonindexedstamp.Height / 2), nonindexedstamp.Width, nonindexedstamp.Height)
    61.             g.Dispose()
    62.  
    63.             Dim newFileName As String = "C:\JCEmailFld\" + Now.ToFileTime.ToString + "_EdittedPage0.tif"
    64.             'I thought saving the file with a tiff format first, the reopening to add the other pages would fix the problem,
    65.             'but it didn't.
    66.             temp.Save(newFileName, ImageFormat.Tiff)
    67.             temp.Dispose()
    68.             firstPage.Dispose()
    69.  
    70.             edittedFirstPage = bitmap.FromFile(newFileName)
    71.         End If
    72.  
    73.         'Now to convert the image back to an indexed1bbp format
    74.         Dim bmdo As BitmapData = edittedFirstPage.LockBits(New Rectangle(0, 0, edittedFirstPage.Width, edittedFirstPage.Height), ImageLockMode.ReadOnly, edittedFirstPage.PixelFormat)
    75.  
    76.         'and the new 1bpp bitmap
    77.         Dim bm As New Bitmap(edittedFirstPage.Width, edittedFirstPage.Height, PixelFormat.Format1bppIndexed)
    78.         Dim bmdn As BitmapData = bm.LockBits(New Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.ReadWrite, PixelFormat.Format1bppIndexed)
    79.  
    80.         'for diagnostics
    81.         Dim dt As DateTime = DateTime.Now
    82.  
    83.         'scan through the pixels Y by X
    84.         Dim y As Integer
    85.  
    86.         For y = 0 To edittedFirstPage.Height - 1
    87.  
    88.             Dim x As Integer
    89.  
    90.             For x = 0 To edittedFirstPage.Width - 1
    91.                 'generate the address of the colour pixel
    92.                 Dim index As Integer = y * bmdo.Stride + x * 4
    93.  
    94.                 'check its brightness
    95.                 If Color.FromArgb(Marshal.ReadByte(bmdo.Scan0, index + 2), Marshal.ReadByte(bmdo.Scan0, index + 1), Marshal.ReadByte(bmdo.Scan0, index)).GetBrightness() > 0.5F Then
    96.  
    97.                     Me.SetIndexedPixel(x, y, bmdn, True) 'set it if its bright.
    98.  
    99.                 End If
    100.  
    101.             Next x
    102.  
    103.         Next y
    104.  
    105.         'tidy up
    106.  
    107.         bm.UnlockBits(bmdn)
    108.  
    109.         edittedFirstPage.UnlockBits(bmdo)
    110.  
    111.         'Save the edittedfirstpage as tiff with codecInfo and Mulitpage/Compression parameters.
    112.         bm.Save("C:\JCEmailFld\" + Now.ToFileTime.ToString + "_FinalImage.tif", codecInfo, ep)
    113.  
    114.         ep.Param(1) = New EncoderParameter(savEncoder, CLng(EncoderValue.FrameDimensionPage))
    115.  
    116.         'loop and add the rest of the pages to the tiff file.
    117.         For j As Integer = 1 To pageFiles.Count - 1
    118.  
    119.             Dim pageFile As Bitmap = Drawing.Bitmap.FromFile(pageFiles(j))
    120.             MessageBox.Show(pageFile.PixelFormat.ToString())
    121.             bm.SaveAdd(CType(pageFile, Image), ep)
    122.             pageFile.Dispose()
    123.  
    124.         Next
    125.  
    126.         'finally, flush the image.
    127.         ep.Param(1) = New EncoderParameter(savEncoder, CLng(EncoderValue.Flush))
    128.         bm.SaveAdd(ep)
    129.  
    130.         bm.Dispose()
    131.         edittedFirstPage.Dispose()

    Here are the additional functions called:

    vb Code:
    1. Private Function GetCodecInfo(ByVal name As String) As ImageCodecInfo
    2.  
    3.         Dim codecs() As ImageCodecInfo = ImageCodecInfo.GetImageEncoders()
    4.  
    5.         For Each info As ImageCodecInfo In codecs
    6.  
    7.             If String.Equals(info.MimeType, name) Then
    8.                 Return info
    9.             End If
    10.  
    11.         Next
    12.         Return Nothing
    13.     End Function
    14.  
    15.     Private Sub SetIndexedPixel(ByVal x As Integer, ByVal y As Integer, ByVal bmd As BitmapData, ByVal pixel As Boolean)
    16.  
    17.         Dim index As Integer = y * bmd.Stride + (x >> 3)
    18.  
    19.         Dim p As Byte = Marshal.ReadByte(bmd.Scan0, index)
    20.  
    21.         Dim mask As Byte = &H80 >> (x And &H7)
    22.  
    23.         If pixel Then
    24.  
    25.             p = p Or mask
    26.  
    27.         Else
    28.  
    29.             p = p And CByte(mask ^ &HFF)
    30.  
    31.         End If
    32.  
    33.         Marshal.WriteByte(bmd.Scan0, index, p)
    34.  
    35.     End Sub 'SetIndexedPixel

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: [RESOLVED] Drawing image to Multi-page tiff file.

    Here is the final class I wrote to encompass what I was trying to accomplish along with allowing to draw to any page on the tiff and able to save the Tiff file with compressions: CCITT4, CCITT3, LZW, Rle and None.

    Everything would work for anyone wanting to use this class except for the SaveAsPDF Sub. You would need to make or get your own 3rd party tools for that functionality to work.

    It always converts each page of the tif file to Format32bppPArgb for potential editting. It may be more efficient to only convert when you actually call an editing method in the Page object.

    When Save is called, it converts each page to Format1bppIndexed, creates the multipage tif file and then saves it.

    I had to attach it, it was too big to paste in here... even just the TiffImage class.

    Here is how you'd use it though:

    vb Code:
    1. Dim tiffFile As New JCUtilities.Imaging.TiffImage("C:\JCEmailFld\MultiPageCCITT4Compression.tif", "C:\Images")
    2.         tiffFile.CompressionType = JCUtilities.Imaging.TiffImage.Compression.CCITT4
    3.         Dim img As Image = Image.FromFile("Server\Stamps\DClerkCertifiedCopy.gif")
    4.  
    5.         Dim MS As New IO.MemoryStream
    6.         img.Save(MS, ImageFormat.Tiff)
    7.         img.Dispose()
    8.  
    9.         Dim stamp As Image = Image.FromStream(MS)
    10.         MS.Flush()
    11.         MS.Close()
    12.  
    13.         tiffFile.Page(0).DrawImage(stamp, stamp.Width / 4, (tiffFile.Page(0).Bitmap.Height - stamp.Height) - CInt(stamp.Height / 2), stamp.Width, stamp.Height)
    14.         tiffFile.SaveAsPDF("C:\JCEmailFld\newfile.pdf")

    Justin
    Attached Files Attached Files
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  6. #6
    New Member
    Join Date
    Apr 2012
    Posts
    4

    Re: [RESOLVED] Drawing image to Multi-page tiff file.

    I used your ConvertToFormat1bppIndexedFrom32bppPArgb method. I am getting the larger image sizes than the original !! (The orignal size was 645 KB and the result file was

  7. #7
    New Member
    Join Date
    Apr 2012
    Posts
    4

    Re: [RESOLVED] Drawing image to Multi-page tiff file.

    I used your ConvertToFormat1bppIndexedFrom32bppPArgb method. I am getting the larger image sizes than the original !! (The orignal size was 645 KB and the result file was 6715 KB). Could you please tell me what might be the problem?

    Since we are using the lesser pixel format, I was expecting the image size would reduce a lot !!

    I am attaching my class file (in c#)

    Thanks in advance for helping me.
    Attached Files Attached Files

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: [RESOLVED] Drawing image to Multi-page tiff file.

    Can you post the image you're trying to convert to 1bpp?

    That way I can debug and run through it.

    Thanks,

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  9. #9
    New Member
    Join Date
    Apr 2012
    Posts
    4

    Re: [RESOLVED] Drawing image to Multi-page tiff file.

    Hi Justin,
    It happens to any tiff file, I used.
    Here is the workflow, I am following.
    The original Image is "Format1bppIndexed" and resolution is 2600 X 4200 (it varies depends on the images) with 300 dpi. Sometimes the images having with lot of white space during the image scan.
    According to our requirement, the image needs to be stretched to fit the full page view. So I resized the resolution as 1800 X 2400 and 96 dpi, to make it fit to full page, which worked perfectly.
    During this process, I had to convert the image to Format32bppRgb, which blotted the file size, causing to consume more memory when I open more images.
    I wanted to compress the file size, so used the method "ConvertToFormat1bppIndexedFrom32bppPArgb", which didn't reduce the file size.
    Earlier I used the code "resize-multipage-tiff" from a VB.NET forum, which also had the same size issue.

    Once again, thanks a lot for helping me.

    Thanks
    - Venkat
    Last edited by dear_vvr; Apr 2nd, 2012 at 02:32 PM.

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: [RESOLVED] Drawing image to Multi-page tiff file.

    Oh ok, well I'll give it a test and see what my result is in the actual file size. I kind of did away with keep all the images in memory. With big multi-page tiff files it just isn't practical as you'll use so much memory it's crazy.

    I just had it to where the user of the API call could specify a temp folder to create the individual page files and keep the paths in a list (of String).

    I'll post later with some more information.
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  11. #11
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: [RESOLVED] Drawing image to Multi-page tiff file.

    The other code he's referring to is here: www.vb dot net forums.com/graphics-gdi/31984-resize-multipage-tiff.html.
    This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.

    The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.

  12. #12
    New Member
    Join Date
    Apr 2012
    Posts
    4

    Re: [RESOLVED] Drawing image to Multi-page tiff file.

    Hi Justin,

    I ran the test on few more tiff files and the compression works fine.

    I tried with a 176KB file to resize with Format32bppRgb, the resultant size is 2372 KB.

    When I applied the ConvertToFormat1bppIndexedFrom32bppPArgb method, I came done to 162 KB.

    The same file to resize with Format24bppRgb, the size is 1718 KB.
    This time the method ConvertToFormat1bppIndexedFrom32bppPArgb didn't produce correct output file. Do I need to change the method "SetIndexedPixel" for this?

    Just FYI... the time took without compression is 3.8 sec and with calling the compression method, 10.5 sec, almost 2.5 times slower !!

    And I agree that, when we hold all the images in memory it is a problem. One of our client complains that, when he try to use 40 images (total 240 pages), the RAM zooms to 1 GB and the program throws "Insufficent memory exception" due to 32 bit OS limitations.

    Thanks
    Last edited by dear_vvr; Apr 2nd, 2012 at 03:50 PM.

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: [RESOLVED] Drawing image to Multi-page tiff file.

    I tried with a 176KB file to resize with Format32bppRgb, the resultant size is 2372 KB.

    When I applied the ConvertToFormat1bppIndexedFrom32bppPArgb method, I came done to 162 KB.

    The same file to resize with Format24bppRgb, the size is 1718 KB.
    This time the method ConvertToFormat1bppIndexedFrom32bppPArgb didn't produce correct output file. Do I need to change the method "SetIndexedPixel" for this?
    The method only correctly converts the file if the source image it's trying to convert to 1bppindexed is in the 32bppPArgb format. 24bppRgb will not convert correctly and may actually be corrupt, not sure though.

    What I would do is right of the bat make sure the image is in the 32bpp format, if not, make it so.

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: [RESOLVED] Drawing image to Multi-page tiff file.

    I'm not sure how or why (in-depth), the setPixel code works... When I came up with this solution, I was in a bind and a hurry. You can always go to that site and email the guy to see how you would use the setPixel on a 24bppRgb pixel formatted image.

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width