How to display images of binary streams (using the img control) and the img Control

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.