Logged In: YES
user_id=1660900
Originator: NO

My project has a bunch of 22k TIF image scans that we need to turn into PDF files, so you can imagine how ecstatic I was this evening when I figured out how to get TIF images to work with Report.NET . Otto has made references before to using MemoryStreams to accomplish this, but no code was ever posted. Well, after incorporating elements from 16 different web pages (including one on Encoder.ColorDepth), I bring you the following code.

Note - in order to display images in a PDF file, they have to have at least 8-bit color depth, so you can't just do a straight conversion to JPEG if your TIF file is less than that (as mine are).

So... here's what the line looks like if you are dealing with a JPEG file:

my_iso_image = New RepImage(MapPath("MaterialCerts/" & heat_number & ".jpg"), 550, 713)

That just grabs an image from a file location. The following code replaces the line above, if we want to use a different file extension (in this case, ".tif")

'---- Create an image object, and read in the file
Dim original_image As Image
original_image = System.Drawing.Image.FromFile(MapPath("MaterialCerts/" & heat_number & ".tif"))

'---- Now create an encoder, and some encoder parameter objects to hold our changes to
' color depth, and our quality setting
Dim myImageCodecInfo As ImageCodecInfo
Dim myEncoder As Encoder
Dim myEncoderParameter As EncoderParameter
Dim myEncoderParameter2 As EncoderParameter
Dim myEncoderParameters As EncoderParameters

'---- Get an ImageCodecInfo object that represents the JPEG codec.
myImageCodecInfo = GetEncoderInfo("image/jpeg")

'---- Create an Encoder object based on the GUID for the ColorDepth parameter category.
myEncoder = Encoder.ColorDepth

'---- Create an EncoderParameters object. An EncoderParameters object has an array of
' EncoderParameter objects. In this case, there will be two EncoderParameter
' objects in the array.
myEncoderParameters = New EncoderParameters(2)

'---- Save the image with a color depth of 8 bits per pixel.
myEncoderParameter = New EncoderParameter(myEncoder, CType(8L, Int32))
myEncoderParameters.Param(0) = myEncoderParameter

'---- Don't allow the JPEG encoder to compress the image
myEncoderParameter2 = New EncoderParameter(Encoder.Quality, CType(100L, Int32))
myEncoderParameters.Param(1) = myEncoderParameter2

'---- Instead of saving the Image to a file location, save it to a MemoryStream!
Dim ms As New MemoryStream()
original_image.Save(ms, myImageCodecInfo, myEncoderParameters)

'---- Because Report.NET is brilliant, it can read an image from a memory stream
my_iso_image = New RepImage(ms, 550, 713)

Months ago I wished I'd known how to do this. I only hope that this brief bit of code can help out anyone in a similar situation. I saw at least two feature requests asking for features that would accomplish the function above, so I hope it will at least help those people.