c# - Storing and retrieving images from Database -
c# - Storing and retrieving images from Database -
i created asp.net/c# application upload image mysql database. process executes without error whatever image upload getting output of 100x100 white image. procedure followed is.
1) created database field picture , type binary(255).
2) uploaded image cmd.parameters.add("@picture", odbctype.binary, 255).value = fileupload1.filebytes;
3) doing above new record beingness inserted , value of below kind generated. 89504e470d0a1a0a0000000d49484452000002600000010008020000009b155d400000100049444154789cd4dc05745b57a2377a15c26088d99651b2248b999959b2c0966cc9cccccc8e1ddb01439899d3a4499a869999e33037d0340d34d4b4d5dbaee7e6f6b5337367eefad67bf3adf55f676dd98e221f6b9ddffeef738e20db5cbf826c77fd3638d8eafa6587ebd79daedfc0f6afd9eefae5ab372fd6bf7db9e5e7b7075dae4daf5e1c76b98ebb5cfb7ef935a5b31b028b32ea53f6ec3a77efe60fb919156e34222b297ee3aedd2e97ebe6dd870b96acd8b0efc0891bb76ae7ce8ba9a8dc70f1f2c917afaeb95ce75c1f276cd988b0180329c4c4aaf2d2
//--------------- uploading module completed -----------------//
1) created aspx page
<asp:image id="img" runat="server" imageurl="~/myimage.ashx" />
2) left aspx.cs file without code
3) added ashx file
<%@ webhandler language="c#" class="myimage" %> using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; using system.io; using system.drawing.imaging; public class myimage : ihttphandler { public void processrequest(httpcontext context) { context.response.contenttype = "image/png"; var info = "89504e470d0a1a0a0000000d49484452000002600000010008020000009b155d400000100049444154789cd4dc05745b57a2377a15c26088d99651b2248b999959b2c0966cc9cccccc8e1ddb01439899d3a4499a869999e33037d0340d34d4b4d5dbaee7e6f6b5337367eefad67bf3adf55f676dd98e221f6b9ddffeef738e20db5cbf826c77fd3638d8eafa6587ebd79daedfc0f6afd9eefae5ab372fd6bf7db9e5e7b7075dae4daf5e1c76b98ebb5cfb7ef935a5b31b028b32ea53f6ec3a77efe60fb919156e34222b297ee3aedd2e97ebe6dd870b96acd8b0efc0891bb76ae7ce8ba9a8dc70f1f2c917afaeb95ce75c1f276cd988b0180329c4c4aaf2d2"; var buffer = stringtobytearray(data); context.response.outputstream.write(buffer, 0, buffer.length); } private byte[] stringtobytearray(string hex) { homecoming enumerable .range(0, hex.length) .where(x => x % 2 == 0) .select(x => convert.tobyte(hex.substring(x, 2), 16)) .toarray(); } public bool isreusable { { homecoming false; } } } by executing code white 100x100 image beingness displayed in output colorful input. double checked contenttype , uploaded various images of various sizes , formats whatever getting output of same white image. what's wrong in code? corrections?
you can seek saving image base64 encoded string, converting image when want render on web page.
here link on how it.
base64string image , visa versa
here link how used in project, not quite image or database concept same.
when using method in webpage you'll use
<img src="${downloadurl}" /> c# asp.net image-processing
Comments
Post a Comment