M
Maurice Mertens
Hello,
I'm having troubles with saving a tiff-file with a certain compression
and colordepth. This is the code I use:
----------------------------------------------------------------------
private sub MakeTiff
dim imgSource as new bitmap(strTifSourceFile)
Dim TiffCodecInfo As System.Drawing.Imaging.ImageCodecInfo
Dim CompressionEncoder As System.Drawing.Imaging.Encoder
Dim Params As System.Drawing.Imaging.EncoderParameters
Dim myencoder As System.Drawing.Imaging.Encoder
myencoder = System.Drawing.Imaging.Encoder.ColorDepth
Dim myImageCodecInfo As System.Drawing.Imaging.ImageCodecInfo
myImageCodecInfo = GetEncoderInfo
(System.Drawing.Imaging.ImageFormat.Tiff)
Dim format As System.Drawing.Imaging.ImageFormat
Dim Index As Integer
'Get the CodecInfo for TIFF format
TiffCodecInfo = GetEncoderInfo
(System.Drawing.Imaging.ImageFormat.Tiff)
'Colordepth
Dim myEncoderParameterColor As New
System.Drawing.Imaging.EncoderParameter(myencoder, 24L)
'Compression
CompressionEncoder = System.Drawing.Imaging.Encoder.Compression
Dim myEncoderParameterCompression = New
System.Drawing.Imaging.EncoderParameter(CompressionEncoder, CLng
(System.Drawing.Imaging.EncoderValue.CompressionLZW))
'Create an EncoderParameters object.
Params = New System.Drawing.Imaging.EncoderParameters(2)
Params.Param(0) = myEncoderParameterCompression
Params.Param(1) = myEncoderParameterColor
imgSource.Save("c:\test.tif", TiffCodecInfo, Params)
end sub
Private Function GetEncoderInfo(ByVal format As
System.Drawing.Imaging.ImageFormat) As
System.Drawing.Imaging.ImageCodecInfo
Dim index As Integer
Dim encoders() As System.Drawing.Imaging.ImageCodecInfo
encoders = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()
For index = 0 To (encoders.Length - 1)
If UCase(encoders(index).FormatDescription) = UCase
(format.ToString) Then
Return encoders(index)
End If
Next index
End Function
-----------------------------------------------------------------
I can set the colordepth in this part:
'Colordepth
Dim myEncoderParameterColor As New
System.Drawing.Imaging.EncoderParameter(myencoder, 24L)
I can set the compression in this part:
'Compression
CompressionEncoder = System.Drawing.Imaging.Encoder.Compression
Dim myEncoderParameterCompression = New
System.Drawing.Imaging.EncoderParameter(CompressionEncoder, CLng
(System.Drawing.Imaging.EncoderValue.CompressionLZW))
PROBLEM:
The Tif-source file is a 475kb file 200dpi, black and white. I want to
save a rotated version of this tif-file, same size, same dpi, same
colors. I can;t get it done.
(1) I can't set the colordepth to less then 24L. When I do this I get an
error in the GDI+. I would like to have a Tif-file with a colordepth
of 1 bit. Is this possible?
(2) When setting the compression to CompressionLZW or CompressionNone it
works fine. But I can;t select the other compressions. When I do so I
also get an error.
--
Met vriendelijke groet / With regards / Saludos,
Moviat Automatisering
Maurice Mertens
mauricem@moviat_KillSpamWordForEMail.nl
tel: +31 162 470 534
fax: +31 162 470 502
I'm having troubles with saving a tiff-file with a certain compression
and colordepth. This is the code I use:
----------------------------------------------------------------------
private sub MakeTiff
dim imgSource as new bitmap(strTifSourceFile)
Dim TiffCodecInfo As System.Drawing.Imaging.ImageCodecInfo
Dim CompressionEncoder As System.Drawing.Imaging.Encoder
Dim Params As System.Drawing.Imaging.EncoderParameters
Dim myencoder As System.Drawing.Imaging.Encoder
myencoder = System.Drawing.Imaging.Encoder.ColorDepth
Dim myImageCodecInfo As System.Drawing.Imaging.ImageCodecInfo
myImageCodecInfo = GetEncoderInfo
(System.Drawing.Imaging.ImageFormat.Tiff)
Dim format As System.Drawing.Imaging.ImageFormat
Dim Index As Integer
'Get the CodecInfo for TIFF format
TiffCodecInfo = GetEncoderInfo
(System.Drawing.Imaging.ImageFormat.Tiff)
'Colordepth
Dim myEncoderParameterColor As New
System.Drawing.Imaging.EncoderParameter(myencoder, 24L)
'Compression
CompressionEncoder = System.Drawing.Imaging.Encoder.Compression
Dim myEncoderParameterCompression = New
System.Drawing.Imaging.EncoderParameter(CompressionEncoder, CLng
(System.Drawing.Imaging.EncoderValue.CompressionLZW))
'Create an EncoderParameters object.
Params = New System.Drawing.Imaging.EncoderParameters(2)
Params.Param(0) = myEncoderParameterCompression
Params.Param(1) = myEncoderParameterColor
imgSource.Save("c:\test.tif", TiffCodecInfo, Params)
end sub
Private Function GetEncoderInfo(ByVal format As
System.Drawing.Imaging.ImageFormat) As
System.Drawing.Imaging.ImageCodecInfo
Dim index As Integer
Dim encoders() As System.Drawing.Imaging.ImageCodecInfo
encoders = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()
For index = 0 To (encoders.Length - 1)
If UCase(encoders(index).FormatDescription) = UCase
(format.ToString) Then
Return encoders(index)
End If
Next index
End Function
-----------------------------------------------------------------
I can set the colordepth in this part:
'Colordepth
Dim myEncoderParameterColor As New
System.Drawing.Imaging.EncoderParameter(myencoder, 24L)
I can set the compression in this part:
'Compression
CompressionEncoder = System.Drawing.Imaging.Encoder.Compression
Dim myEncoderParameterCompression = New
System.Drawing.Imaging.EncoderParameter(CompressionEncoder, CLng
(System.Drawing.Imaging.EncoderValue.CompressionLZW))
PROBLEM:
The Tif-source file is a 475kb file 200dpi, black and white. I want to
save a rotated version of this tif-file, same size, same dpi, same
colors. I can;t get it done.
(1) I can't set the colordepth to less then 24L. When I do this I get an
error in the GDI+. I would like to have a Tif-file with a colordepth
of 1 bit. Is this possible?
(2) When setting the compression to CompressionLZW or CompressionNone it
works fine. But I can;t select the other compressions. When I do so I
also get an error.
--
Met vriendelijke groet / With regards / Saludos,
Moviat Automatisering
Maurice Mertens
mauricem@moviat_KillSpamWordForEMail.nl
tel: +31 162 470 534
fax: +31 162 470 502