第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Sysytem.Drawing.Image 的 ASP.NET CORE MVC

使用 Sysytem.Drawing.Image 的 ASP.NET CORE MVC

C#
猛跑小豬 2023-07-09 10:02:59
我嘗試使用 System.Drawing.Image 在 ASP.NET Core MVC 中保存圖像,但出現(xiàn)此錯誤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
查看完整描述

1 回答

?
牧羊人nacy

TA貢獻1862條經(jīng)驗 獲得超7個贊

我記得我也遇到過同樣的問題,當您嘗試保存圖像的文件夾在物理路徑中不存在時,通常會發(fā)生這種情況,因此請嘗試創(chuàng)建該文件夾并重試,否則您必須創(chuàng)建該文件夾如果不存在使用以下代碼:


        Image image = Image.FromStream(stream);

        string folderName = @"YourFolderPath";

        string path = Path.Combine(_hostingEnvironment.ContentRootPath, folderName);

        bool exists = Directory.Exists(path);

        if (!exists)                   

        Directory.CreateDirectory(path);

        image.Save(path);

        image.Dispose();

        stream.Dispose();

我建議在您的 SaveToFolder 函數(shù)中使用它,但是,因為我可以看到您已經(jīng)在圖像路徑中添加了文件夾路徑,您應(yīng)該將其與函數(shù)一起傳遞,或者在創(chuàng)建函數(shù)中進行此檢查。


查看完整回答
反對 回復 2023-07-09
  • 1 回答
  • 0 關(guān)注
  • 144 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號