Hello Friends ...
How To Change Image extensions When User Uploading Image In Mvc....
I am Using ImageReSizer nuget Package Manage.
Given Below Is My Code:-
public static string UploadFile(HttpPostedFileBase file,string file_Name,int height,int width)
{
var path = Path.Combine(HttpContext.Current.Request.MapPath(UploadPath), file_Name);
file.SaveAs(path);
ResizeSettings resizeSetting = new ResizeSettings
{
Width = width,
Height = height,
Format = "."
};
ImageBuilder.Current.Build(file, path, resizeSetting);
return file_Name;
}


Nitin SontakkeRank #264 · 9.6K reputationPosted Dec 11, 2016, 10:29 PM EST
Dr.Ajay KashyapRank #2,900 · 496 reputationPosted Dec 11, 2016, 10:46 PM EST
Mangesh GRank #294 · 8.6K reputationPosted Dec 11, 2016, 10:55 PM EST
Dr.Ajay KashyapRank #2,900 · 496 reputationPosted Dec 12, 2016, 12:47 AM EST
Mangesh Gaherwar sir ..system web httppostedfilebase to string convert Error
MayankRank #4,018 · 371 reputationPosted Dec 12, 2016, 1:43 AM EST
{
var file = Request.Files[0];
actualFileName = file.FileName;
fileName = Guid.NewGuid() + ".png";
//fileName = Guid.NewGuid() + Path.GetExtension(file.FileName);
int size = file.ContentLength;
try
{
file.SaveAs(Path.Combine(Server.MapPath("~/FileUpload"), fileName));
}
catch (Exception)
{
Message = "File upload failed! Please try again";
}
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Dec 12, 2016, 2:17 AM EST
Fabio Silva LimaRank #750 · 3.1K reputationPosted Dec 12, 2016, 2:30 PM EST
Maen BadwanRank #2,520 · 556 reputationPosted Dec 15, 2016, 4:08 AM EST
If you want to change the actual image data from JPG to PNG (not only the extension), you can use LEADTOOLS programming SDK which supports loading and saving many image file formats including JPEG and PNG.
For example, the following code shows how you can load any supported image format (JPEG image) and save it to PNG file format on disk or in memory:
+-------------------+
using (Leadtools.Codecs.RasterCodecs _leadCodecs = new Leadtools.Codecs.RasterCodecs())
{
//Load the original JPEG image to a RasterImage object
Leadtools.RasterImage JPEGImage = _leadCodecs.Load(file.FileName);
//Save the RasterImage object to a temp PNG file on disk
_leadCodecs.Save(JPEGImage, "TempFile.png", RasterImageFormat.Png, 24);
//the following code saves the RasterImage object to a MemoryStream
System.IO.MemoryStream Memstream = new System.IO.MemoryStream();
_leadCodecs.Save(destinationImage, Memstream, RasterImageFormat.Png, 24);
Memstream.Seek(0, SeekOrigin.Begin);
}
+-------------------+
More details can be found here:
https://www.leadtools.com/sdk/formats
Note that you can add the above code in a web-service and call it from inside your ASP.NET MVC application, or you can use the code directly in your ASP.NET server side code
Disclaimer: I am an employee of this library.
Dr.Ajay KashyapRank #2,900 · 496 reputationPosted Dec 15, 2016, 6:43 PM EST
Mohammed Deeb HammoudehRank #1,485 · 1.1K reputationPosted Dec 19, 2016, 2:16 AM EST