I have made one desktop application and it throws an error
A generic error occurred in GDI+.
Here is my code:
//Generating Images
string newpath = "Thumbs";
var _path = Path.Combine(_imagesPath, newpath);
var thumbFilePath = GetPictureLocalPath(thumbFileName, _path);//"C:\\Users\\Developer\\Documents\\Server2\\Solr Plugin Branch Nop-310\\Presentation\\Nop.Web\\Content\\Images\\Thumbs\\"+thumbFileName;
if (!File.Exists(thumbFilePath))
{
using (var stream = new MemoryStream(pictureBinary))
{
Bitmap b = null;
//try-catch to ensure that picture binary is really OK. Otherwise, we can get "Parameter is not valid" exception if binary is corrupted for some reasons
// b = new Bitmap(stream);
try
{
//try-catch to ensure that picture binary is really OK. Otherwise, we can get "Parameter is not valid" exception if binary is corrupted for some reasons
b = new Bitmap(stream);
}
catch (ArgumentException exc)
{
string msg = exc.ToString();
string fullmsg = string.Format("Error generating picture thumb. ID={0}", pictureId);
InsertSystemLog(msg, fullmsg);
}
if (b == null)
{
//bitmap could not be loaded for some reasons
return url;
}
var newSize = CalculateDimensions(b.Size, _productThumbPictureSize);
if (newSize.Width < 1)
newSize.Width = 1;
if (newSize.Height < 1)
newSize.Height = 1;
using (var newBitMap = new Bitmap(newSize.Width, newSize.Height))
{
using (var g = Graphics.FromImage(newBitMap))
{
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawImage(b, 0, 0, newSize.Width, newSize.Height);
var ep = new EncoderParameters();
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 80L);
ImageCodecInfo ici = GetImageCodecInfoFromExtension(lastPart);
if (ici == null)
ici = GetImageCodecInfoFromMimeType("image/jpeg");
try
{ newBitMap.Save(thumbFilePath, ici, ep); }
catch (ArgumentException exc)
{
string msg = exc.ToString();
string fullmsg = string.Format("Unable to save Picture ID={0}", pictureId);
InsertSystemLog(msg, fullmsg);
}
}
}
I have seen one answer at this link about permission: A generic error occurred in GDI+, JPEG Image to MemoryStream
But this is a console application. So which permission I need to give to generate Images on file system.
Please can anyone help.