Save an Image with a new file name [ImageSharp]

I have upgraded my project from .net framework to .net 6 (core). In my project, there are many places where Bitmap is used. I have read in the microsoft documentations that System.Drawing.Common will only support the Windows platform and even after adding the EnableUnixSupport configuration, it will not be supported in net7. I have the scenario where I save a file as Image (the format is .tiff) then I read from that path as bitmap and save as PNG ( due to some business rule) Following is the line of code I am trying change:

Bitmap.FromFile(completePath).Save(pngPath, ImageFormat.Png);

This is the code I have converted into. The only issue is how to save as a new file name as the Tiff file has tiff in the file name.

string extension = _GetExtension(img.ContentType);
       


 if (extension == Constants.TiffExtension)
            {
           
            fileName = fileName.Replace(Constants.TiffExtension, "PNG");
           
            using (var outputStream = new FileStream(completePath, FileMode.CreateNew))
            {
                var image = SixLabors.ImageSharp.Image.Load(completePath);

                image.SaveAsync(outputStream, new PngEncoder()); //how to save new file name?
            }
           
        }


Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)