ASP.NET image processing details

xiaoxiao2021-03-06  118

Author: Unknown, please contact me

When using ASP, we often use third-party controls to implement some image functions. Now, ASP.NET is launched, we have no need to use third-party controls, because ASP.NET has a powerful function to implement some image processing. Now let's take a look at how to use this powerful features of ASP.NET.

First, use of system.drawing

The following examples generate a picture in memory, then display this picture through the web page. What you need to know is that we are output here that it is not an HTML effect, but a real picture (image), we can use "Save As ..." to save the output image.

Let's take a look at the effect:

We see that this picture is "seeing a few words on a gradient background, of course, this effect is easy to achieve in image processing software such as Photoshop, but some applications with databases We cannot All pictures are designed in advance, this time, it is very important to use ASP.NET to implement these features. Let's see the source code:

<% @ page language = "vb" ContentType = "image / jpeg"%>

<% @ import namespace = "system.drawing"%>

<% @ import namespace = "system.drawing.imaging"%>

<% @ import namespace = "system.drawing.drawing2d"%>

<%

'Clearing Response

Response.clear

'Create a 120 * 30 size, 24bit of BMP image;

DIM IMGOUTPUT AS New Bitmap (120, 30, Pixelformat.Format24bppRGB)

'Establish a new image according to the above BMP;

DIM G as graphics = graphics.fromimage (IMGOUTPUT)

g.clear (color.green)

g.smoothingmode = smoothingmode.ntialias

g.drawstring ("Have you seen it?", New Font ("Black Body", 16, FontStyle.Bold, New Solidbrush (Color.White), New Pointf (2, 4))

G. FillRectangle (New Lineargradientbrush (New Point (0), New Point (120, 30), Color.Fromargb (0, 0, 0), Color.Fromargb (255, 255, 255, 255)), 0, 0, 120, 30)

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

g.dispose ()

IMGOUTPUT.DISPOSE ()

Response.end

%>

In the above code, we have different and the database program, which is specifically introduced into the image processing namespace system.drawing, etc. The program first cleared the response, ensuring no output; then, the program established a 120-large BMP image, and then established a new image on this basis. After building an image, we first "draw" string "See it," the string is 16 large crude black body, the color is white, the location is (2, 4); Finally, we achieve the gradient effect. The above example is simple, but if we combine with the database, we can achieve many effects that use ASP may not dare.

Second, read and change the image file size

Read the picture? Can you use HTML directly? Of course, we only provide a selection and method to implement this feature, the specific use of this feature, we may need more learning in practice. Let's look at the program source code:

<% 'Import All Relevant Namespaces%>

<% @ import namespace = "system"%>

<% @ import namespace = "system.drawing"%>

<% @ import namespace = "system.drawing.imaging"%>

<% @ Import namespace = "system.io"%>