最新下载
热门教程
- 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" %>
相关文章
- 《无限暖暖》天星之羽获得位置介绍 12-20
- 《流放之路2》重铸台解锁方法介绍 12-20
- 《无限暖暖》瞄准那个亮亮的成就怎么做 12-20
- 《无限暖暖》魔气怪终结者完成方法 12-20
- 《无限暖暖》曙光毛团获得位置介绍 12-20
- 《无限暖暖》日光果获得位置介绍 12-20