Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving an Image with a different Compression

Status
Not open for further replies.

andegre

MIS
Oct 20, 2005
275
US
I am trying to save images as .tif 's and the default compression for the tif is lzw. Does anyone know how to save a tif in Tif Group 4 compression?

Here is the code that I'm using to save:
img.Save("Path_and_filename_with_tif_extension", System.Drawing.Imaging.ImageFormat.tif)

Thanks,

andegre
 
Hopefully..this will get you started. Its untested, but is along the lines of what you will have to do.
Code:
Imports System.Drawing.Imaging
Dim im As Image
Dim en As New EncoderParameters(1)
Dim p As New EncoderParameter(Encoder.Compression, System.Drawing.Imaging.EncoderValue.CompressionCCITT4)
en.Param(0) = p

Dim tiffCodec As ImageCodecInfo = GetImageCodec("image/tiff")

im.Save("test.tiff", tiffCodec, en)

Private Function GetImageCodec(ByVal mimeType As String) As ImageCodecInfo
        Dim codecs As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders
     For Each codec As ImageCodecInfo In codecs
        If String.Compare(codec.MimeType, mimeType, True) = 0 Then
            Return codec
        End If
     Next
     Return Nothing
End Function

Some further help may be available here...but the code is all in C


Sweep
...if it works dont f*** with it
curse.gif
 
Curious, what is the For Each doing exactly?

Thanks, by the way...
 
To be honest, for the codec section...all I did was translate the C+ code.

Sweep
...if it works dont f*** with it
curse.gif
 
Is this all for VB.NET? That's what I'm coding in. I haven't gotten a chance to try it today. I'll let you know tomorrow if that works for me.

Thanks again Squeakin...
 
Hey Squeakin...what is:
Dim tiffCodec As ImageCodecInfo = GetImageCodec("image/tiff")

im.Save("test.tiff", tiffCodec, en)

specifically the ("image/tiff") is this just the filename with the new tiff extension?

also,
im.save("test.tiff"...) isn't the tiff only supposed to have one (1) 'f'?

Thanks,
 
The code I posted was just a pointer...not tested by me, but should hopefully have put you in the right direction. I dont even know what the tiffcodec= line does myself. Change tiff to tif in all cases. Have you made any progress so far with this?


Sweep
...if it works, you know the rest..
Always remember that Google is your friend

curse.gif
 
yeah, I got the code in but have not tested, VB recognizes everything so that's a start.

I'll go test it right now.
 
andegre

Did you have any success with this?

Sweep
...if it works, you know the rest..
Always remember that Google is your friend

curse.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top