using System; using System.Collections; using System.Data; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Xml.Linq; using System.IO; using System.Data.Sql; using System.Data.SqlClient; using System.Data.SqlTypes; using System.Drawing; using System.Drawing.Imaging; using System.ComponentModel; using System.Configuration; namespace IDRC { /// <summary> /// Summary description for $codebehindclassname$ /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class ShowImage : IHttpHandler { SqlConnection conn; byte [] pic = null; long Seq = 0; public void ProcessRequest(HttpContext context) { context.Response.ContentType = "image/jpeg"; string userid; if (context.Request.QueryString["userid"] != null) { userid = context.Request.QueryString["userid"]; } else { throw new ArgumentException("No parameter specified"); } // Convert Byte[] to Bitmap Bitmap newBmp = ConvertToBitmap(Show_Image(userid)); if (newBmp != null) { newBmp.Save(context.Response.OutputStream, ImageFormat.Jpeg); newBmp.Dispose(); } } protected Bitmap ConvertToBitmap(byte []bmp) { if (bmp != null) { TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap)); //ImageConverter img = new ImageConverter(); Bitmap b = (Bitmap)tc.ConvertFrom(bmp); return b; } return null; } public byte[] Show_Image(string userid)//, string query) { conn = new System.Data.SqlClient.SqlConnection(@"Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\Telehealth_Data.MDF;Integrated Security=True;User Instance=True"); string query = @"SELECT [staff_pic] FROM [staff_personal_info] WHERE [staff_member_id] = @userid "; SqlCommand cmd = new SqlCommand(query ,conn); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@userid", userid); try { conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { Seq = dr.GetBytes(0, 0, null, 0, int.MaxValue) -1; pic = new byte[Seq + 1]; dr.GetBytes(0, 0, pic, 0, Convert.ToInt32(Seq)); conn.Close(); } return pic; } catch { return null; } finally { conn.Close(); } } public bool IsReusable { get { return false; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)