找不到Image.FromFile文件 [英] Image.FromFile File Not Found
本文介绍了找不到Image.FromFile文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Drawing;
using System.IO;
namespace BurgerShop.Models
{
public class FoodDbInitializer : DropCreateDatabaseAlways<FoodContext>
{
public byte[] ImageToByteArray(Image image)
{
MemoryStream ms = new MemoryStream();
image.Save(ms, image.RawFormat);
return ms.ToArray();
}
protected override void Seed(FoodContext context)
{
Burger hamburger = new Burger
{
Id = 1,
Name = "Гамбургер",
Price = 49,
Image = ImageToByteArray(Image.FromFile("BurgerShop\\Content\\img\\Burgers\\1.jpg"))
};
base.Seed(context);
}
}
}
当我尝试从文件中读取图像时,我有FileNotFoundException
.我的文件路径中有该图像,因此奇怪的是编译器找不到文件.请帮帮我!
When I'm trying to read the image from file I have FileNotFoundException
. I have that image in my file path, so it's strange that compiler can't find a file. Help me please!
推荐答案
Burger hamburger = new Burger
{
Id = 1,
Name = "Гамбургер",
Price = 49,
Image = File.ReadAllBytes(Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content\\img\\Burgers\\1.jpg")))
};
我已经找到答案了,并且可以奏效,谢谢所有参与我的问题的人)
I already found the answer and it works, thank you to everyone, who have participated in my problem)
这篇关于找不到Image.FromFile文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文