1

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:

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?

Eugene Joy
  • 11
  • 1

1 Answers1

0

As far as I know, support for TIFF images in Silverlight is very limited.

There are 3-rd party libraries that can help you with your task. I am personally recommend you to try LibTiff.Net library. The library is completely free (even for commercial use) and open source.

Source code package of LibTiff.Net contains Silverlight Test Application that shows how to asynchronously load and display TIFF images in a Silverlight app. It can display various TIFF flavors including bitonal ones.

You might find this answer to a similar question useful too.

Community
  • 1
  • 1
Bobrovsky
  • 13,789
  • 19
  • 80
  • 130