①bmp转tif
Dim bmp As Bitmap = New Bitmap(f)
Dim strTifDescFile As String = "C:/abc.tif"
'黑白双色图片
Dim tifImageCodecInfo As ImageCodecInfo
tifImageCodecInfo = GetEncoderInfo(ImageFormat.Tiff)
Dim tifEncoderParameter1 As EncoderParameter
Dim tifEncoderParameter2 As EncoderParameter
Dim tifEncoderParameters As EncoderParameters
tifEncoderParameter1 = New EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8)
tifEncoderParameter2 = New EncoderParameter(System.Drawing.Imaging.Encoder.Compression, EncoderValue.CompressionCCITT4)
tifEncoderParameters = New EncoderParameters(2)
tifEncoderParameters.Param(0) = tifEncoderParameter1
tifEncoderParameters.Param(1) = tifEncoderParameter2
bmp.Save(strTifDescFile, tifImageCodecInfo, tifEncoderParameters)
②图片转Byte()
Dim bytes As Byte() = System.IO.File.ReadAllBytes("C:/abc.tif")
③以流的方式读取磁盘上的文件
直接读取文件,文件会被锁死,无法对文件进行修改。以文件流的方式读取,读取后不会锁死磁盘上的文件
Public Function readImageFileByFileStream(ByVal filePath As String) As Image
Using reader As New System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Return System.Drawing.Image.FromStream(reader)
End Using
End Function
Dim img As Image = readImageFileByFileStream("C:/abc.bmp")
pictureBox1.Image = img