Hello all,
Can anybody tell me how to use CommerceBuilder to generate icon/thumbnail images? Maybe a more specific question would be: are there objects, methods, and properties available to generate these images using code?
Thanks much.
Generating images
Re: Generating images
You don't need CommerceBuilder for that - it's in the System.Drawing namespace.
Code: Select all
private static System.Drawing.Image resizeImage(System.Drawing.Image imgToResize, System.Drawing.Size size)
{
int sourceWidth = Convert.ToInt32(imgToResize.Width);
int sourceHeight = Convert.ToInt32(imgToResize.Height);
float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)size.Width / (float)sourceWidth);
nPercentH = ((float)size.Height / (float)sourceHeight);
if (nPercentH < nPercentW)
nPercent = nPercentH;
else
nPercent = nPercentW;
int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);
Bitmap b = new Bitmap(destWidth, destHeight);
Graphics g = Graphics.FromImage((System.Drawing.Image)b);
g.InterpolationMode =InterpolationMode.HighQualityBicubic;
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
g.Dispose();
return (System.Drawing.Image)b;
}
Nick Cole
http://www.ethofy.com
http://www.ethofy.com
Re: Generating images
Ahh, yes. Common sense. This is a forest/trees moment.
Thanks for the reminder.
Thanks for the reminder.