圖片與二進制流的轉化

C#中圖片與二進制流的轉化

 

 

private Bitmap BytesToBitmap(byte[] Bytes)
    {
        MemoryStream stream = null;
        try
        {
            stream = new MemoryStream(Bytes);
            return new Bitmap((Image)new Bitmap(stream));
        }
        catch (ArgumentNullException ex)
        {
            throw ex;
        }
        catch (ArgumentException ex)
        {
            throw ex;
        }
        finally
        {
            stream.Close();
        }
    }
    private byte[] BitmapToBytes(Bitmap Bitmap)
    {
        MemoryStream ms = null;
        try
        {
            ms = new MemoryStream();
            Bitmap.Save(ms, ImageFormat.Gif);
            Bitmap.Save("C:/test.jpg", ImageFormat.Gif);
            byte[] byteImage = new Byte[ms.Length];
            byteImage = ms.ToArray();
            return byteImage;
        }
        catch (ArgumentNullException ex)
        {
            throw ex;
        }
        finally
        {
            ms.Close();
        }
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章