display image (asp) in c#

how to display image from database(in binary) to a page

Page 1 of 1

0 Replies - 3795 Views - Last Post: 07 October 2009 - 01:49 AM Rate Topic: -----

#1 cs_starter  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 01-December 08

display image (asp) in c#

Posted 07 October 2009 - 01:49 AM

Hi, i need help in finding our how to display image to a page. But the image src will be coming from sql database in binary format.
The code I have is in c# wpf, but I need it in asp c#. Can anyone pls. help? I appreciate it. thanks!

	  public ImageSource ConvertImage(byte[] imageParam)
	  {
		  try
		  {
			  MemoryStream memoryStream = new MemoryStream(imageParam);
			  System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(memoryStream);

			  IntPtr bitmapPtr = bitmap.GetHbitmap();
			  System.Windows.Controls.Image image = new System.Windows.Controls.Image();
			  System.Windows.Media.ImageSource imageSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
															 bitmapPtr,
															 IntPtr.Zero,
															 System.Windows.Int32Rect.Empty,
															 System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
			  bitmap.Dispose();
			  memoryStream.Close();
			  return imageSource;
		  }
		  catch (Exception)
		  {
			  return new BitmapImage(new Uri("Images/CompanyLogo.jpg", UriKind.Relative));
		  }
	  }




I can get the image source in binary file by using stored proc. But the main concern is how do I convert it to string or an object so I can use it as Image source for an image??

Is This A Good Question/Topic? 0
  • +

Page 1 of 1