以下代码通过JPEG DCT压缩成功将JPEG转换为TIFF,但输出为24位TIFF。 如何使用相同的压缩类型将其转换为 8位 TIFF?
Using bmp As New Bitmap(oImage.FilePath)
Using tif As Tiff = Tiff.Open("BitmapTo24BitColorTiff.tif", "w")
Dim raster As Byte() = getImageRasterBytes(bmp, PixelFormat.Format24bppRgb)
tif.SetField(TiffTag.IMAGEWIDTH, bmp.Width)
tif.SetField(TiffTag.IMAGELENGTH, bmp.Height)
tif.SetField(TiffTag.COMPRESSION, Compression.JPEG)
tif.SetField(TiffTag.PHOTOMETRIC, Photometric.RGB)
tif.SetField(TiffTag.ROWSPERSTRIP, bmp.Height)
tif.SetField(TiffTag.XRESOLUTION, bmp.HorizontalResolution)
tif.SetField(TiffTag.YRESOLUTION, bmp.VerticalResolution)
tif.SetField(TiffTag.BITSPERSAMPLE, 8)
tif.SetField(TiffTag.SAMPLESPERPIXEL, 3)
tif.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG)
Dim stride As Integer = raster.Length \ bmp.Height
' convertSamples(raster, bmp.Width, bmp.Height)
Dim i As Integer = 0, offset As Integer = 0
While i < bmp.Height
tif.WriteScanline(raster, offset, i, 0)
offset += stride
i += 1
End While
End Using
System.Diagnostics.Process.Start("BitmapTo24BitColorTiff.tif")
End Using