跳至主要内容

net.core 读取图片到数组



其实跟webform方法一样
public IActionResult Index()
{
    FileStream fs = new FileStream("1.jpg", FileMode.Open);
    int filelength = 0;
    filelength = (int)fs.Length; //获得文件长度
    Byte[] fl = new Byte[filelength]; //建立一个字节数组
    fs.Read(fl, 0, filelength); //按字节流读取
    fs.Close();

    return File(fl.ToArray(), @"image/png");
}

评论

此博客中的热门博文