[英]C# Picture become black after uploading and then saving it - ASP.NET MVC 5
Please bear with me, my English is still improving... Below given code is what I am using to get an uploaded image saved in "UploadedImage" folder in ASP.NET MVC 5 project.请耐心等待,我的英语仍在进步中……下面给出的代码是我用来获取保存在 ASP.NET MVC 5 项目的“UploadedImage”文件夹中的上传图像的代码。 But when I use my almost high-end PC having i7 processor, 16GB of RAM, 4GB Graphics Card, all works like a charm.
但是,当我使用配备 i7 处理器、16GB RAM、4GB 显卡的近乎高端的 PC 时,一切都运行良好。 But problem arises when I use my laptop having i3 processor and 8GB of ram or a PC having i3 processor having 4GB RAM.... What I get is only a black image.
但是,当我使用配备 i3 处理器和 8GB 内存的笔记本电脑或配备 i3 处理器和 4GB 内存的 PC 时,问题就出现了……我得到的只是一张黑色图像。
public ActionResult Index(FormCollection form)
{ if (string.IsNullOrEmpty(form["image-data"])) return
View();
var t = form["image-data"].Substring(form["image-data"].LastIndexOf(',') + 1);
byte[] bytes = Convert.FromBase64String(t);
string fileName = form["email"].Replace("@", "at");
fileName = fileName.Replace(fileName[fileName.LastIndexOf(".")].ToString(), "dot");
var fullPath = Path.Combine(Server.MapPath("~/UploadedImage/"), fileName + ".png");
Image image;
using (var streamBitmap = new MemoryStream(bytes))
{
using (image = Image.FromStream(streamBitmap))
{
image.Save(fullPath);
}
}
Please help me, I could not get any help from anywhere, thanks in advance请帮助我,我无法从任何地方得到任何帮助,在此先感谢
You can try this method to upload file/images您可以尝试使用此方法上传文件/图片
var Upload_Path = "get file path";
string fileExtension = Path.GetExtension(file);
fileExtension = fileExtension.ToLower();
var path = System.IO.Path.Combine(Server.MapPath(Upload_Path),"name.jpg");
Model.ProfileImage.SaveAs(path);
in model you can use在 model 你可以使用
[DisplayName("Picture")]
public HttpPostedFileBase ProfileImage { get; set; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.