图片与二进制文件的互转

//图片转成二进制
    public byte[] getBytes(string filePath)  
    {
        System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open);
        byte[] imgData = new byte[fs.Length];
        fs.Read(imgData, 0, (int)fs.Length);
        return imgData;
    }

    //二进制转成图片  
    private System.Drawing.Image convertByteToImg(byte[] imgData)
    {
        System.IO.MemoryStream ms = new System.IO.MemoryStream(imgData);
        System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
        return img;
    }

你可能感兴趣的:(图片与二进制文件的互转)