How to display images of binary streams (using the img control) and the img Control
Previously
Can I use the normal Format to display my binary stream images? It must be okay, that is, it is a little troublesome to write the code. img should write it like this:
You are right. Its address points to An aspx page, which has a strange point,
After the WebForm1 is created, you do not need to write any front-end code. The front-end and back-end code of WebForm1 is as follows:
Front-end:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "WebForm1.aspx. cs" Inherits = "display the image. WebForm1" %>
Background code:
Using System; using System. collections. generic; using System. IO; using System. linq; using System. web; using System. web. UI; using System. web. UI. webControls; using: displays images in the databases crawled by crawlers. models; namespace: displays the image {public partial class WebForm1: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {int id = int. parse (Request ["id"]. toString (); DataClasses1DataContext db = new DataClasses1DataContext (); Response. contentType = "application/binary;"; // This image can be read from the database. // byte [] img = DBHelper. readImg (); byte [] img = db. pictureUrl. where (p => p. id = id ). first (). pictureUrl1.ToArray (); Response. binaryWrite (img); Response. flush (); Response. end ();}}}
The front and back-end code on our homepage is as follows:
Front-end:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %><!DOCTYPE html>
Background code:
Using System; using System. collections. generic; using System. drawing; using System. IO; using System. linq; using System. text; using System. web; using System. web. mvc; using: displays images in the databases crawled by crawlers. models; namespace: displays images in the databases crawled by crawlers. controllers {public class HomeController: Controller {// GET:/Home/DataClasses1DataContext db = new DataClasses1DataContext (); public ActionResult Index () {ViewBag. pictures = db. pictureUrl; return View ();}}}
The final running result: