3

im trying to write a list of bitmaps to a tif

in standard .net code, the tif becomes a huge file, which i understand is due to the fact that it does not support jpeg compression

research shows that libtiff should be able to handle that, though i cant find any simple example for writing bitmaps to the file

heres what i have (basically copy pasted from the docs)

Sub MakeTiff(Input As List(Of Bitmap))
        Dim fileName As String = "random.tif"
        Using output As Tiff = Tiff.Open(fileName, "w")
            For Each item In Input
                output.SetField(TiffTag.IMAGEWIDTH, 100)
                output.SetField(TiffTag.IMAGELENGTH, 100)
                output.SetField(TiffTag.SAMPLESPERPIXEL, 1)
                output.SetField(TiffTag.BITSPERSAMPLE, 8)
                output.SetField(TiffTag.ORIENTATION, Orientation.TOPLEFT)
                output.SetField(TiffTag.ROWSPERSTRIP, 100)
                output.SetField(TiffTag.XRESOLUTION, 88.0)
                output.SetField(TiffTag.YRESOLUTION, 88.0)
                output.SetField(TiffTag.RESOLUTIONUNIT, ResUnit.INCH)
                output.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG)
                output.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK)
                output.SetField(TiffTag.COMPRESSION, Compression.NONE)
                output.SetField(TiffTag.FILLORDER, FillOrder.MSB2LSB)
                Dim bd = item.GetData
                Dim offset = 0
                For i = 0 To bd.Height
                    output.WriteScanline(bd.Bytes, offset, i, 0)
                    offset += bd.Stride
                Next
                output.WriteDirectory()
            Next
        End Using
        Process.Start(fileName)
    End Sub

but the end result is a corrupted file.

i dont really understand all these settings, all i need is just to add the jpgs somehow to the tiff

can anyone help out with a code snippet? or another free/lowcost compressed tiff creator?

thanks

0 Answers0