陈斌彬的技术博客

Stay foolish,stay hungry

Webservice 通过图片文件路径读取图片

[WebMethod]
    public byte[] LoadImg()
    {
        FileInfo imgFile = new FileInfo(@"C:\Users\John123\Desktop\a.jpg");
        byte[] imgByte = new byte[imgFile.Length];  //1.初始化用于存放图片的字节数组 
        using (FileStream imgStream = imgFile.OpenRead()) //2.初始化读取图片内容的文件流
        {
            imgStream.Read(imgByte, 0, Convert.ToInt32(imgFile.Length));//3.将图片内容通过文件流读取到字节数组 
            return imgByte;
        }
    }

Resource Reference