ASP.NET read binary
-
Hey......... I using code below, but it not display image MemoryStream mstream = new MemoryStream(); SqlCommand cmdImg = new SqlCommand("SELECT Image FROM TAB_Employee WHERE EmpID='" + EmpID + "'", gCnn); byte[] image = (byte[])cmdImg.ExecuteScalar(); mstream.Write(image, 0, image.Length); Bitmap bitmap = new Bitmap(mstream); // Response.ContentType = "image/gif"; bitmap.Save(Response.OutputStream, ImageFormat.Gif); it display as binary
Socheat
-
Hey......... I using code below, but it not display image MemoryStream mstream = new MemoryStream(); SqlCommand cmdImg = new SqlCommand("SELECT Image FROM TAB_Employee WHERE EmpID='" + EmpID + "'", gCnn); byte[] image = (byte[])cmdImg.ExecuteScalar(); mstream.Write(image, 0, image.Length); Bitmap bitmap = new Bitmap(mstream); // Response.ContentType = "image/gif"; bitmap.Save(Response.OutputStream, ImageFormat.Gif); it display as binary
Socheat
You could try something like this:
string query = "SELECT Image FROM TAB_Employee WHERE EmpID='" + EmpID + "'";
SqlCommand cmdImg = new SqlCommand(query, gCnn);
byte[] image = (byte[])cmdImg.ExecuteScalar();
MemoryStream mstream = new MemoryStream(image);
Bitmap bitmap = new Bitmap(System.Drawing.Image.FromStream(mstream));
Response.ContentType = "image/gif";
bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
bitmap.Dispose();Best of luck :)
Cheers Disgyza Programmer Analyst
-
You could try something like this:
string query = "SELECT Image FROM TAB_Employee WHERE EmpID='" + EmpID + "'";
SqlCommand cmdImg = new SqlCommand(query, gCnn);
byte[] image = (byte[])cmdImg.ExecuteScalar();
MemoryStream mstream = new MemoryStream(image);
Bitmap bitmap = new Bitmap(System.Drawing.Image.FromStream(mstream));
Response.ContentType = "image/gif";
bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
bitmap.Dispose();Best of luck :)
Cheers Disgyza Programmer Analyst
Dear, I tried to use like what you wrote already, but my out put still the same why? Can u help me again?
Socheat
-
Dear, I tried to use like what you wrote already, but my out put still the same why? Can u help me again?
Socheat
Ok what i think you need to do is: Place the connection code in a new WebForm and then on the page that your showing your image set the image ImageUrl property to the new webform. E.g. Image.aspx is the new webform Image.aspx contains the new code listed in the post above. WebForm1.aspx is the page with your image Set the ImageUrl property to the new webform. Image.ImageUrl = "Image.aspx"; When the ImageUrl try to load it will load the new Image.aspx page. Since you are changing the ContentType it should load the page as an Image. Let me know if this works for you, if not i'm sure there are a ton of different ways to make this work for you. Best of luck!!! :-D
Cheers Disgyza Programmer Analyst
-
Ok what i think you need to do is: Place the connection code in a new WebForm and then on the page that your showing your image set the image ImageUrl property to the new webform. E.g. Image.aspx is the new webform Image.aspx contains the new code listed in the post above. WebForm1.aspx is the page with your image Set the ImageUrl property to the new webform. Image.ImageUrl = "Image.aspx"; When the ImageUrl try to load it will load the new Image.aspx page. Since you are changing the ContentType it should load the page as an Image. Let me know if this works for you, if not i'm sure there are a ton of different ways to make this work for you. Best of luck!!! :-D
Cheers Disgyza Programmer Analyst
Dear, I tried to use like you said Image.ImageUrl ="Image.aspx"; It does not show anyanything. Does Image.ImageUrl="Image.aspx", ImageUrl can get url?
Socheat
-
Dear, I tried to use like you said Image.ImageUrl ="Image.aspx"; It does not show anyanything. Does Image.ImageUrl="Image.aspx", ImageUrl can get url?
Socheat
Dear, Thank you, it work now.............
Socheat
-
Dear, Thank you, it work now.............
Socheat