Have a Template Column having an Image element in it and set ImageUrl to an aspx page like below.
<TemplateColumn>
<asp:Image
ID="LogoImage" ImageUrl='<%# "GetImage.aspx?IMAGE_ID=" +
Convert.ToString(DataBinder.Eval(Container.DataItem, "image_id")) %>'
runat="server" ToolTip='<%#DataBinder.Eval(Container.DataItem,
"image_name") %>' AlternateText='Image'/>
</TemplateColumn>
In the .aspx page have the below code in page load.
private const string IMAGE_ID= "IMAGE_ID";
protected void Page_Load(object sender, EventArgs e)
{
int imageId= 0;
if (Request.QueryString.Count > 0)
{
if (Request.QueryString[IMAGE_ID] != null)
{
if (int.TryParse(Request.QueryString[IMAGE_ID], out imageId))
{
LogoManager logoManager = new LogoManager();
byte[] binaryImage = logoManager.GetLogo(logoId);
System.Drawing.Image uploadedImage = System.Drawing.Image.FromStream(new System.IO.MemoryStream(binaryImage));
if (uploadedImage != null)
{
int ImageWidthInPixels = uploadedImage.Width;
int ImageHeightInPixels = uploadedImage.Height;
//Bitmap
if (ImageWidthInPixels > Settings.Default.MaxImageWidth) ImageWidthInPixels = Settings.Default.MaxImageWidth;
if (ImageHeightInPixels > Settings.Default.MaxImageHeight) ImageHeightInPixels = Settings.Default.MaxImageHeight;
Bitmap b = new
System.Drawing.Bitmap(ImageWidthInPixels,ImageHeightInPixels,
PixelFormat.Format24bppRgb);//" the size of background. The picture
can't be larger than it.
Graphics g = Graphics.FromImage(b);
g.Clear(Color.White);
g.DrawImage(uploadedImage, 0, 0, ImageWidthInPixels, ImageHeightInPixels);
Response.ContentType = "image/jpeg";
b.Save(Response.OutputStream, ImageFormat.Jpeg); //Use this line, you can output the image to page.
b.Dispose();
}
}
}
}
}