开发者

Convert Image to Byte[]

开发者 https://www.devze.com 2023-04-09 07:36 出处:网络
I have an image that sits inside some folder in my MVC3 application. In my controller, how do I convert that image into 开发者_运维技巧a Byte array.byte[] buffer = File.ReadAllBytes(\"foo.png\");

I have an image that sits inside some folder in my MVC3 application. In my controller, how do I convert that image into 开发者_运维技巧a Byte array.


byte[] buffer = File.ReadAllBytes("foo.png");

and because that's inside a controller you probably want to calculate the path relative to the root:

string imageFile = Path.Combine(Server.MapPath("~/App_Data"), "foo.png");
byte[] buffer = File.ReadAllBytes(imageFile);
0

精彩评论

暂无评论...
验证码 换一张
取 消