发布一个位图文件与Byte流间转换的方法集。
方法1 从内存中直接获取位图的Byte[]
import this
// using System.Runtime.InteropServices;
private unsafe byte [] BmpToBytes_Unsafe (Bitmap bmp)
... {
还原方法
unsafe Bitmap BytesToBmp ( byte [] bmpBytes, Size imageSize)
... {
方法2 通过将位图文件写入内存流的方式获取byte[]
Bitmap bytes have to be created via a direct memory copy of the bitmap
private byte [] BmpToBytes_MemStream (Bitmap bmp)
... {
// Bitmap bytes have to be created using Image.Save()
private Image BytesToImg ( byte [] bmpBytes)
... {
方法3 使用序列化的方式获得位图的byte[]
import these
// using System.Runtime.Serialization;
// using System.Runtime.Serialization.Formatters.Binary;
private byte [] BmpToBytes_Serialization (Bitmap bmp)
... {
private Bitmap BytesToBmp_Serialized ( byte [] bmpBytes)
... {
方法4 获取位图对象句柄、
IntPtr getImageHandle (Image img)
... {
获得句柄后,想怎么操作都可以喽
转自一个不明英文论坛