'ImageConverter' 无法将位图转换为字节数组。得到错误
'ImageConverter' can't convert a Bitmap to a byte array. gets error
错误是:
“'ImageConverter' 无法将 'System.Drawing.Bitmap' 转换为 'System.Byte'。”
dim YZ_2D_blobmap( 150 * 100 * 3 ) as byte
dim heatmap_PictureBox_Bitmap as Bitmap
' . . .heatmap_PictureBox_Bitmap loaded with 150 x 100 bitmap
YZ_2D_blobmap = Bitmap_to_Bytes( heatmap_PictureBox_Bitmap ) <<<<<<< error
bytes_to_file( YZ_2D_blobmap, YZ_2D_BLOBMAP_BLB_PATHNAME )
Function Bitmap_to_Bytes( img as Bitmap ) as byte()
dim bytes_ImageConverter as ImageConverter = New ImageConverter()
return bytes_ImageConverter.ConvertTo( img, GetType( byte ))
end function
Sub bytes_to_file( byte_buffer, pathname )
system.io.file.writeAllBytes( pathname, byte_buffer )
End Sub
您告诉 ImageConverter
将 Bitmap
转换为 Byte
而不是 Byte
数组。这个:
return bytes_ImageConverter.ConvertTo( img, GetType( byte ))
应该是这样的:
Return bytes_ImageConverter.ConvertTo(img, GetType(Byte()))
错误信息甚至告诉你:
'ImageConverter' is unable to convert 'System.Drawing.Bitmap' to
'System.Byte'.
没有关于数组的内容。
错误是: “'ImageConverter' 无法将 'System.Drawing.Bitmap' 转换为 'System.Byte'。”
dim YZ_2D_blobmap( 150 * 100 * 3 ) as byte
dim heatmap_PictureBox_Bitmap as Bitmap
' . . .heatmap_PictureBox_Bitmap loaded with 150 x 100 bitmap
YZ_2D_blobmap = Bitmap_to_Bytes( heatmap_PictureBox_Bitmap ) <<<<<<< error
bytes_to_file( YZ_2D_blobmap, YZ_2D_BLOBMAP_BLB_PATHNAME )
Function Bitmap_to_Bytes( img as Bitmap ) as byte()
dim bytes_ImageConverter as ImageConverter = New ImageConverter()
return bytes_ImageConverter.ConvertTo( img, GetType( byte ))
end function
Sub bytes_to_file( byte_buffer, pathname )
system.io.file.writeAllBytes( pathname, byte_buffer )
End Sub
您告诉 ImageConverter
将 Bitmap
转换为 Byte
而不是 Byte
数组。这个:
return bytes_ImageConverter.ConvertTo( img, GetType( byte ))
应该是这样的:
Return bytes_ImageConverter.ConvertTo(img, GetType(Byte()))
错误信息甚至告诉你:
'ImageConverter' is unable to convert 'System.Drawing.Bitmap' to 'System.Byte'.
没有关于数组的内容。