(原創) 如何用程式的方式載入jpg圖形檔案? (.NET) (GDI+) (ASP.NET) (Image Processing)

來源:互聯網
上載者:User

Abstract
雖然HTML本身就提供了tag可直接顯示jpg圖形檔案,但若需對圖形本身作Pixel By Pixel的影像處理,如『影像辨識』,就必須用程式的方式將jpg圖形檔案載入,然後才能做後續的處理,以下的程式將示範如何在.NET平台使用C#載入jpg圖形檔案。

Introduction

 1<!-- (C) OOMusou 2006.09.29 oomusou@hotmail.com-->
 2<%@ Page Language="C#" %>
 3
 4<%@ Import Namespace="System.Drawing" %>
 5<%@ Import Namespace="System.Drawing.Imaging" %>
 6<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 7
 8<script runat="server">
 9  /// <summary>
10  /// Demo how to read image from Jpeg format for further 
11  /// image processing. 
12  /// </summary>
13  protected void Page_Load(object sender, EventArgs e) {
14
15    // Bitmap uses System.Drawing namespace.
16    Bitmap jpg = new Bitmap(Server.MapPath("lena.jpg"));
17
18    // Graphics uses System.Drawing namespace.
19    Graphics canvas = Graphics.FromImage(jpg);
20
21    // Specify HTML's content type.
22    Response.Clear();
23    Response.ContentType = "image/jpeg";
24
25    // ImageFormat uses System.Drawing.Imaging namespace.
26    jpg.Save(Response.OutputStream, ImageFormat.Jpeg);
27
28    // You should always call the Dispose method to release 
29    // the Graphics and related resources created by the 
30    // FromImage method.
31    jpg.Dispose();
32    canvas.Dispose();
33  }
34</script>
35
36<html xmlns="http://www.w3.org/1999/xhtml">
37<head runat="server">
38  <title></title>
39</head>
40<body>
41  <form id="form1" runat="server">
42    <div>
43    </div>
44  </form>
45</body>
46</html>
47

See Also
(原創) 如何使用ANSI C/ISO C++讀寫24位元的bmp圖檔? (初級) (C/C++)
(原創) 如何使用ANSI C讀寫32位元的BMP圖檔? (C/C++) (C) (Image Processing)
(原創) 如何使用ANSI C讀寫24/32位元的BMP圖檔? (C/C++) (C) (Image Processing)
(原創) 如何使用C++/CLI讀/寫jpg檔? (初級) (C++/CLI)

Reference
Steven A. Smith, Rob Howard, The ASP Alliance, ASP.NET 開發手劄, 上奇科技出版事業處

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.