Click here to Skip to main content
15,914,071 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Our company has an application that receives bitonal TIFF images via fax or scanner and saves them to a database; currently, we display the images from the database using an ActiveX control, but now we want to use a Silverlight control to display those images instead. However, we are not able to display or save the images as bitonal TIFF images; using the following code in our ashx handler, we get a blank image:

VB
pageno = Convert.ToInt32(context.Request.QueryString("page"))
   'Get image data from database
   Dim bmp() As Byte = ShowDocumentImage(documentID)
   'Get current page of TIFF image as bitmap
   Dim newBmp As Bitmap = GetTifPage(bmp, pageno)
   Dim info As Imaging.ImageCodecInfo = Nothing
   Dim ice As Imaging.ImageCodecInfo
   For Each ice In Imaging.ImageCodecInfo.GetImageEncoders()
       If ice.MimeType = "image/tiff" Then
          info = ice
       End If
   Next
   Dim enc As Imaging.Encoder = Imaging.Encoder.SaveFlag
   Dim ep As New Imaging.EncoderParameters(2)
   ep.Param(0) = New Imaging.EncoderParameter(enc, CLng(Imaging.EncoderValue.MultiFrame))
   ep.Param(1) = New Imaging.EncoderParameter(enc, CLng(Imaging.EncoderValue.CompressionCCITT4))
   If newBmp IsNot Nothing Then
       newBmp.Save(context.Response.OutputStream, info, ep)
       newBmp.Dispose()
   End If

Instead, we have to save them as JPEG, which does display to the user but which also increases the bit depth and the size of the files; it also increases the time it takes to save the image. It takes about 6 seconds to convert a 1728x2079 JPEG to a byte array so that it can be uploaded to the database.

Is there a way to display and save the image as a bitonal TIFF, and/or a faster way to convert the image to a byte array?
Posted

1 solution

My first option is trying to convert to a PNG and then saves to DataBase.

I'll improve this solution later. Let me try this one.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900