最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
?.NET中的动态生成图像组件
时间:2022-07-02 12:01:09 编辑:袖梨 来源:一聚教程网
Y'know, there's this really cool library in .NET for dynamically creating images on the fly. However, this article has nothing to do with that, so if that's what you're looking for, stop now. What this article is about is very simple -- how to use a single line of code (via a component call) to output the contents of an image residing on the server's hard drive. Why not just use an IMG tag? Well, we want this page to used as the SRC of an IMG tag, so it has to actually have a content-type of "image/gif" and use BinaryWrite to display the image. To do this in Classic ASP requires a custom component (or a third party component such as Persits ASPUpload, which has a SendBinary method that does this). In fact, let's take a look at how this works with a quick sample before we do it in .NET. Below is the complete code required to display a static image using ASPUpload. You can see this file in action by clicking here.
displayimage.asp:
1 <% OPTION EXPLICIT %>
2
3 <%
4 objUpload.SendBinary Server.MapPath("/images/aspalliance_fade_468x60.gif"), True
5 %>
Now, let's do this in .NET. We can use the System.Drawing library to open an image and display it, using the following code:
displayimage.aspx:
1 <%@ Page language="c#" AutoEventWireup="false" Trace="false" Debug="false" %>
2 <% @Import Namespace="System.Drawing" %>
3 <% @Import Namespace="System.IO" %>
4 <% @Import Namespace="System.Drawing.Imaging" %>
displayimage.asp:
1 <% OPTION EXPLICIT %>
2
3 <%
4 objUpload.SendBinary Server.MapPath("/images/aspalliance_fade_468x60.gif"), True
5 %>
Now, let's do this in .NET. We can use the System.Drawing library to open an image and display it, using the following code:
displayimage.aspx:
1 <%@ Page language="c#" AutoEventWireup="false" Trace="false" Debug="false" %>
2 <% @Import Namespace="System.Drawing" %>
3 <% @Import Namespace="System.IO" %>
4 <% @Import Namespace="System.Drawing.Imaging" %>
相关文章
- 蚂蚁庄园今日课堂答题2024年11月14日 11-16
- 《尼尔:机械纪元》武器黑之倨傲属性及特殊能力介绍 11-15
- 《尼尔:机械纪元》机械生命体的枪获得方法介绍 11-15
- 《尼尔:机械纪元》武器机械生命体的枪属性及特殊能力介绍 11-15
- 《尼尔:机械纪元》天使之圣翼获得方法介绍 11-15
- 《尼尔:机械纪元》武器天使之圣翼属性及特殊能力介绍 11-15