M
Martin Wirth
hi guys,
I have a problem with saving a System.Drawing.Bitmap bmp to disk.
This bitmap contains a thumbnail of another bitmap I previously loaded.
Whenever I try to issue "bmp.Save(....., jpeg format)" I get the GDI +
generic error.
I've seen a knowledge base article (814675) describing this issue. However I
cannot resolve it using the techniques presented in the article.
here's some code I use:
try
{
System.Drawing.Bitmap im = new System.Drawing.Bitmap(orig);
int width, height;
width = 150; height = 150;
System.Drawing.Image th = new Bitmap(width, height);
Graphics g = Graphics.FromImage(th);
g.CompositingQuality =
System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bicubic;
g.DrawImage(im, 0, 0, width, height);
g.Dispose();
im.Dispose();
// workaround for "save to same stream" problem.
// KB article 814675
// "PRB: Bitmap and Image Constructor Dependencies"
System.Drawing.Bitmap th2 = new Bitmap(th.Width, th.Height);
Graphics g2 = Graphics.FromImage(th2);
g2.DrawImage(th, 0, 0, th.Width, th.Height);
g2.Dispose();
th.Dispose();
// end of workaround
th2.Save(thumb, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception e){MessageBox.Show(this, e.Message, "Exception caught",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
does anyone know what's the problem here ? I 've tried lots of stuff but i
just can't get "thumbnailing" to work ...
Best regards,
martin wirth.
I have a problem with saving a System.Drawing.Bitmap bmp to disk.
This bitmap contains a thumbnail of another bitmap I previously loaded.
Whenever I try to issue "bmp.Save(....., jpeg format)" I get the GDI +
generic error.
I've seen a knowledge base article (814675) describing this issue. However I
cannot resolve it using the techniques presented in the article.
here's some code I use:
try
{
System.Drawing.Bitmap im = new System.Drawing.Bitmap(orig);
int width, height;
width = 150; height = 150;
System.Drawing.Image th = new Bitmap(width, height);
Graphics g = Graphics.FromImage(th);
g.CompositingQuality =
System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bicubic;
g.DrawImage(im, 0, 0, width, height);
g.Dispose();
im.Dispose();
// workaround for "save to same stream" problem.
// KB article 814675
// "PRB: Bitmap and Image Constructor Dependencies"
System.Drawing.Bitmap th2 = new Bitmap(th.Width, th.Height);
Graphics g2 = Graphics.FromImage(th2);
g2.DrawImage(th, 0, 0, th.Width, th.Height);
g2.Dispose();
th.Dispose();
// end of workaround
th2.Save(thumb, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception e){MessageBox.Show(this, e.Message, "Exception caught",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
does anyone know what's the problem here ? I 've tried lots of stuff but i
just can't get "thumbnailing" to work ...
Best regards,
martin wirth.