我尝试使用 System.Drawing.Image 在 ASP.NET Core MVC 中保存图像,但出现此错误A generic error occurred in GDI+
,并且不知道如何修复它。
我在这行代码中收到错误: newImg.Save(_hostingEnvironment.ContentRootPath, img.RawFormat);
位于方法中SaveToFolder
。
这是我的 IRepository 中的所有代码:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net.Mime;
using System.Threading.Tasks;
using AstroPhotoWebSite_v3.Data;
using AstroPhotoWebSite_v3.Interfaces;
using AstroPhotoWebSite_v3.Models;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
namespace AstroPhotoWebSite_v3.Repositories
{
public class GalaxysRepository : IRepository<GalaxysModel>
{
private readonly ApplicationDbContext _context;
private readonly IHostingEnvironment _hostingEnvironment;
private ApplicationDbContext context;
public GalaxysRepository(ApplicationDbContext context, IHostingEnvironment hostingEnvironment)
{
this.context = _context;
_hostingEnvironment = hostingEnvironment;
}
public List<GalaxysModel> Entities => _context.Galaxys.ToList();
private Size NewImageSize(Size imageSize, Size newSize)
{
Size finalSize;
double tempval;
if (imageSize.Height > newSize.Height || imageSize.Width > newSize.Width)
{
if (imageSize.Height > imageSize.Width)
{
tempval = newSize.Height / (imageSize.Height * 1.0);
}
else
牧羊人nacy
相关分类