How to display image inside web form from Byte Array with C#

前端 未结 3 913
温柔的废话
温柔的废话 2020-12-16 04:41

This is my code, all it does is clear the web page and draw the image, so the rest of the form disappears! I need to show the image inside the form.

This is my User

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-16 05:23

    You could write a page .aspx or a handler maybe .ashx that send the content of the picture back to the browser. You could pass information in the url. Then use the url to this page with an html tag or html control to display it.

    EDIT: You need to use a Control. You could convert the binary data to base64 and output the content to the html page.

    I give you an example with an img html tag:

    
    

    You can also use base64 encoding for image with CSS:

    background-image: url(data:image/jpeg;base64,IVB)
    

    To convert into base64 from C# you can use:

    using System;
    

    and:

    Convert.ToBase64String(Foto);
    

提交回复
热议问题