小编Ran*_*hid的帖子

如何在ASP.NET Core 2.0中上载后调整图像大小

我想调整图像大小并将此图像以不同的大小多次保存到文件夹中.我已经尝试过ImageResizer或CoreCompat.System.Drawing,但是这些库与.Net core 2不兼容.我已经搜索了很多关于这个,但我找不到任何合适的解决方案.像在MVC4我用过:

public ActionResult Upload(HttpPostedFileBase file)
{
if (file != null)
{
    var versions = new Dictionary<string, string>();

    var path = Server.MapPath("~/Images/");

    //Define the versions to generate
    versions.Add("_small", "maxwidth=600&maxheight=600&format=jpg";);
    versions.Add("_medium", "maxwidth=900&maxheight=900&format=jpg");
    versions.Add("_large", "maxwidth=1200&maxheight=1200&format=jpg");

    //Generate each version
    foreach (var suffix in versions.Keys)
    {
        file.InputStream.Seek(0, SeekOrigin.Begin);

        //Let the image builder add the correct extension based on the output file type
        ImageBuilder.Current.Build(
            new ImageJob(
                file.InputStream,
                path + file.FileName + suffix,
                new Instructions(versions[suffix]),
                false,
                true));
    }
}

return RedirectToAction("Index");
}
Run Code Online (Sandbox Code Playgroud)

但是在Asp.Net核心2.0中我被卡住了.我不知道如何在.Net核心2中实现这一点.任何人都可以帮助我.

system.drawing resize-image asp.net-core-2.0

9
推荐指数
2
解决办法
5024
查看次数

C#:通用参数与对象类型参数

我有两种重载方法,一种是期望对象类型参数,另一种是通用参数列表。我试图了解何时调用哪个函数。我正在传递字符串对象,它正在调用通用params方法。

class Program
{
    static void Main(string[] args)
    {
        string s = "string";
        Invoke(s);
        Console.ReadLine();
    }

    static void Invoke(object s)
    {
        Console.WriteLine("Object param invoked");
    }

    static void Invoke<T>(params T[] values)
    {
        Console.WriteLine("Params method invoked");
    }
}
Run Code Online (Sandbox Code Playgroud)

它的输出为:“ Params方法已调用”。

但我不确定为什么总是调用此方法。我也尝试传递int参数,但再次调用了params方法。如果有人可以帮我解释一下。谢谢。

.net c#

2
推荐指数
1
解决办法
126
查看次数