Change Img To Byte - CSharp System.Drawing

CSharp examples for System.Drawing:Image Operation

Description

Change Img To Byte

Demo Code


using System.Drawing.Imaging;
using System.Drawing;
using System.IO;//from w  w  w  .j  a v  a 2  s. co  m
using System.Security.Cryptography;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;

public class Main{

        public static byte[] ChangeImgToByte(string strImagePath)
        {
            Image image = Image.FromFile(strImagePath);
            MemoryStream ms = new MemoryStream();
            image.Save(ms, ImageFormat.Jpeg);
            ms.Flush();
            ms.Seek(0, SeekOrigin.Begin);
            byte[] buffer = new byte[ms.Length];
            ms.Read(buffer, 0, (int)ms.Length);
            return buffer;
        }
}

Related Tutorials