What would be the most optimized way to resize an image for a PictureBox in Itemdatabound or itemDatabinding for a report? I have quite a few images and am tying not to have to manually resize them.
I seem to be missing something
private void detail_ItemDataBound(object sender, EventArgs e) |
{ |
Telerik.Reporting.Processing.DetailSection procDetail = sender as Telerik.Reporting.Processing.DetailSection; |
Telerik.Reporting.Processing.PictureBox procPictureBox = procDetail.Items["pictureBox1"] as Telerik.Reporting.Processing.PictureBox; |
DataRowView row = procDetail.DataItem as DataRowView; |
string strPath = HttpContext.Current.Server.MapPath(@"~\Img\Product\" + (string)row["ProdImgLRes"]); |
using (Bitmap bmpIn = new Bitmap(System.Drawing.Image.FromFile(strPath))) |
{ |
int w = bmpIn.Width; |
int h = bmpIn.Height; |
int intWidth = 90; |
int intHeight = (int)(h * intWidth) / w; |
Bitmap bmpOut = new Bitmap(intWidth, intHeight); |
using (Graphics g = Graphics.FromImage(bmpIn)) |
{ |
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; |
g.DrawImage(bmpOut, 0, 0, intWidth, intHeight); |
} |
MemoryStream ms = new MemoryStream(); |
bmpOut.Save(ms, ImageFormat.Bmp); |
procPictureBox.Image = Image.FromStream(ms); |
} |
Thanks,
Dave