Hi, I created a web project on the server, and when I upload an image shows me the error Error: A generic error occurred in GDI +.
I have read many links on the net that talk about this issue, and although I made the changes, nothing went wrong.
I was thinking if the case is not an issue of permissions to folders.
In fact I have two folders one inside the other.
This is the code to resize the image:
public Bitmaps ResizeImage (Stream stream, int? width, int? height)
(
System.Drawing.Bitmap bmpOut = null;
const int defaultWidth = 800;
const int defaultHeight = 600;
int width = lnWidth == null? defaultWidth: (int) width;
int height = lnHeight == null? defaultHeight: (int) height;
try
(
LoBMP bitmap = new Bitmap (stream);
ImageFormat loFormat = loBMP.RawFormat;
decimal lnRatio;
lnNewWidth int = 0;
lnNewHeight int = 0;
if (loBMP.Width <& & lnWidth loBMP.Height <lnHeight)
(
loBMP return;
)
if (loBMP.Width> loBMP.Height)
(
lnRatio = (decimal) lnWidth / loBMP.Width;
lnNewWidth = lnWidth;
decimal = lnTemp loBMP.Height lnRatio *;
lnNewHeight = (int) lnTemp;
)
else
(
lnRatio = (decimal) lnHeight / loBMP.Height;
lnNewHeight = lnHeight;
decimal = lnTemp loBMP.Width lnRatio *;
lnNewWidth = (int) lnTemp;
)
bmpOut = new Bitmap (lnNewWidth, lnNewHeight);
Graphics g = Graphics.FromImage (bmpOut);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.FillRectangle (Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
g.DrawImage (loBMP, 0, 0, lnNewWidth, lnNewHeight);
loBMP.Dispose ();
)
catch
(
return null;
)
bmpOut return;
)
and this is the code that I insert in the codebehind:
string filepath = AppDomain.CurrentDomain.BaseDirectory + img_veterinario / ";
string = filepathM AppDomain.CurrentDomain.BaseDirectory + img_veterinario / img_veterinarioM;
Reseize Reseize R = new ();
Bitmap = photosFileOriginal r.ResizeImage (fucasiclinici.PostedFile.InputStream, 400, 400);
Bitmap = photosFileMiniatura r.ResizeImage (fucasiclinici.PostedFile.InputStream, 72, 72);
String filename = Path.GetFileName (fucasiclinici.PostedFile.FileName);
photosFileOriginal.Save (Path.Combine (filepath, filename));
photosFileMiniatura.Save (Path.Combine (filepathM, filename));
Can you help me?
Thanks