I am using AsyncFileUpload controls to upload jpg, jpeg, png, gif and svg file and resize the image to display as thumbnail on the application screen. I am able to resize all the image formats except svg.
In AsyncFileUpload_UploadedComplete Method I am calling a function that will resize the original image to Thumbnail.
instead of saving as bmp, I passed the file as stream to convert to thumbnail.
using (MemoryStream memory = new MemoryStream())
{
using (FileStream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite))
{
bmp.Save(memory, ImageFormat.Jpeg);
byte[] bytes = memory.ToArray();
fs.Write(bytes, 0, bytes.Length);
}
}
For this I have installed SVG package from NuGet.
Now the problem is when I check in the code in Git, it is successful, but the pipeline fails giving the below error, as this is a Website application, the package,config is checked in and build succeeded but Deployment fails. As this is a Website application
the dll automatically added into bin, and package.config. So implemented in the asp.net page with Using Svg;
error CS0246: The type or namespace name 'Svg' could not be found (are you missing a using directive or an assembly reference?)
Issue resolved by pushing the Svg and its dependent dlls to Git.
Member
12 Points
91 Posts
Converting svg file to image
Jun 01, 2020 10:20 AM|SasikalaSankaran|LINK
Hi All,
I am using AsyncFileUpload controls to upload jpg, jpeg, png, gif and svg file and resize the image to display as thumbnail on the application screen. I am able to resize all the image formats except svg.
In AsyncFileUpload_UploadedComplete Method I am calling a function that will resize the original image to Thumbnail.
Calling method:
GenerateThumbnail(AsyncFileUpload.PostedFile.InputStream, AsyncFileUpload.PostedFile.ContentType, thumbFilename, fileGuid);
Method:
private void GenerateDBThumbnail(Stream source, string contentType, string imageName, string fileGuid)
{
if (contentType.ToLower().IndexOf("image/") < 0) return;
using (var image = Image.FromStream(source))
{
// Image resize;
}
}
For svg file error hits in the line: using (var image = Image.FromStream(source)) as " Parameter is not valid".
Kindly help me on this.
Thanks,
Sasikala.
All-Star
194490 Points
28079 Posts
Moderator
Re: Converting svg file to image
Jun 01, 2020 01:08 PM|Mikesdotnetting|LINK
An svg file is not a supported Image file. It is an XML file. You could use the browser to convert it: https://stackoverflow.com/questions/3975499/convert-svg-to-image-jpeg-png-etc-in-the-browser
Member
12 Points
91 Posts
Re: Converting svg file to image
Jun 09, 2020 05:24 AM|SasikalaSankaran|LINK
Hi,
Thanks for your reply. Finally I was able to achieve thumbnail for SVG image file by converting it in to png.
Implemented as per the below link.
https://dotnetfiddle.net/sY3EAs.
instead of saving as bmp, I passed the file as stream to convert to thumbnail.
using (MemoryStream memory = new MemoryStream())
{
using (FileStream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite))
{
bmp.Save(memory, ImageFormat.Jpeg);
byte[] bytes = memory.ToArray();
fs.Write(bytes, 0, bytes.Length);
}
}
For this I have installed SVG package from NuGet.
Now the problem is when I check in the code in Git, it is successful, but the pipeline fails giving the below error, as this is a Website application, the package,config is checked in and build succeeded but Deployment fails. As this is a Website application the dll automatically added into bin, and package.config. So implemented in the asp.net page with Using Svg;
error CS0246: The type or namespace name 'Svg' could not be found (are you missing a using directive or an assembly reference?)
Issue resolved by pushing the Svg and its dependent dlls to Git.
Thanks,
Sasilkala.