ASP. NET Image Processing

Source: Internet
Author: User
Tags bmp image

When using ASP, we often need to use third-party controls to implement some image functions. Now, with the release of ASP. NET, we do not need to use third-party controls to implement them, because ASP. NET already has powerful functions to implement some image processing. Now let's take a look at how to use this powerful feature of ASP. NET.

   1. Use of System. Drawing

The following example shows how to generate an image in the memory and then display the image on the webpage. We need to know that what we output here is not the HTML effect, but a real image. We can use "Save ..." Save the output image.

Let's take a look at the effect:



We can see that this image is a gradient with the words "have you seen it?". Of course, this effect is easy to implement in PhotoShop and other image processing software. However, some applications combined with databases cannot be designed in advance for all images. At this time, ASP is used. NET. Let's look at the source code:

<% @ Page language = "vb" contenttype = "image/jpeg" %>
<% @ Import namespace = "system. drawing" %>
<% @ Import namespace = "system. drawing. imaging" %>
<% @ Import namespace = "system. drawing. drawing2d" %>

<%
Clear Response
Response. clear

Create a 24-bit BMP image with a size of 120*30;
Dim imgOutput as New bitmap (120, 30, pixelformat. format24bpprgb)

Create a new image based on the above BMP;
Dim g as graphics = graphics. fromimage (imgOutput)

G. clear (color. Green)
G. smoothingMode = smoothingMode. antiAlias

G. drawString ("have you seen it? ", New font (" ", 16, fontstyle. bold), new SolidBrush (Color. White), New pointF (2, 4 ))

G. FillRectangle (New linearGradientBrush (New point (255,255,255,255), New point (), color. fromArgb (,), color. fromArgb)

ImgOutput. save (response. outputstream, imageformat.jpeg)

G. dispose ()
ImgOutput. dispose ()
Response. end
%>

In the above code, we can see that, unlike the database program, the image processing namespace system. drawing is introduced here. The program first clears Response to ensure there is no output; then, the program creates a 120 × 30 BMP image, and then creates a new image based on this, after the image is created, first, we will draw a string "have you seen it?". The string is a 16-character bold string with the white color and the position is (2, 4). Finally, we will implement the gradient effect.

The above example is very simple, but if combined with the database, we can achieve a lot of effects that may not be imagined by Using ASP.

There are two pages in this news. Currently, there are two pages in page 1st.


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.