Resizing image proportionally in ASP.NET C# by specifying either Height or Width

后端 未结 5 786
一整个雨季
一整个雨季 2021-02-11 07:33

I need a code that will allow me to resize images, but with the following functionality:

1) resize image upon upload

2) Resize image proportionally by specifying

5条回答
  •  无人共我
    2021-02-11 08:06

    Last day I found imageresizer and its great. and good API. Works Great. Downloaded from Visual studio 2010 Extension Manager: http://nuget.org/.

    Easy Steps to download API in VS-2010:

    1). Install Extension http://nuget.org/.

    enter image description here

    3). Find and Install ImageResizing
    enter image description here

    4).Then Code: (I m using here cropping. you can use any) Documentation on imageresizing.net

    string uploadFolder = Server.MapPath(Request.ApplicationPath + "images/");
    FileUpload1.SaveAs(uploadFolder + FileUpload1.FileName);
    
    
    //The resizing settings can specify any of 30 commands.. See http://imageresizing.net for details.
    ResizeSettings resizeCropSettings = new ResizeSettings("width=200&height=200&format=jpg&crop=auto");
    
    //Generate a filename (GUIDs are safest).
    string fileName = Path.Combine(uploadFolder, System.Guid.NewGuid().ToString());
    
    //Let the image builder add the correct extension based on the output file type (which may differ).
    fileName = ImageBuilder.Current.Build(uploadFolder + FileUpload1.FileName, fileName, resizeCropSettings, false, true);

    Try!!! its very awsumm and easy to use. thanks.

提交回复
热议问题