protected void Button1_Click(object sender, EventArgs e) { SqlDataAdapter adp = new SqlDataAdapter("select pic from images where userid=" + 1, con); DataSet ds = new DataSet(); adp.Fill(ds); System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(ds.Tables[0].Rows[0][0].ToString())); // create the actual thumbnail image System.Drawing.Image thumbnailImage = image.GetThumbnailImage(900,900, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); // make a memory stream to work with the image bytes MemoryStream imageStream = new MemoryStream(); // put the image into the memory stream thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg); // make byte array the same size as the image byte[] imageContent = new Byte[imageStream.Length]; // rewind the memory stream imageStream.Position = 0; // load the byte array with the image imageStream.Read(imageContent, 0, (int)imageStream.Length); // return byte array to caller with image type byte[] bt; Response.ContentType = "image/jpeg"; bt = ((byte[])imageContent); Response.BinaryWrite(bt); //Response.BinaryWrite(imageContent); } public bool ThumbnailCallback() { return true; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)