ASP. Net generates a simple image

Source: Internet
Author: User
Tags random seed

In this section, we generate a simple image as an entry-level training for ASP. NET graphics processing.
First, use Visual Studio. NET 2003 to create a Web application named GDITec. Create a new Web form named GDI_Sample1.aspx. We will write logic code for the form:

'----- Code begin -----

Imports System. Drawing

Imports System. Drawing. Bitmap

Imports System. Drawing. Graphics

Public Class WebForm1

Inherits System. Web. UI. Page

# Region "code generated by Web forms designer"

'The code generated by the Form Designer is omitted here.

# End Region

Private Sub Page_Load (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles MyBase. Load

'User code to place the initialization page here

'Declare a bitmap object

'Bitmap object is equivalent to a canvas. With a canvas, we can make a graph on it.

Dim objBitmap As Bitmap

Dim I As Integer

'Declare Random Seed to randomly generate coordinates of 1000 pixel points

Dim objRandom As Random

'Create Bitmap

ObjBitmap = New Bitmap (300,100)

'Set 1000 Pixels

ObjRandom = New Random

For 1 To 5000

ObjBitmap. SetPixel (objRandom. Next (300), objRandom. Next (100), Color. White)

Next

'Save the objGraphics object to the specified Stream object in the specified image format (Gif here,

And output it to the client. The save method has five reloads and can be saved to the hard disk. You can select different image formats.

ObjBitmap. Save (Response. OutputStream, Drawing. Imaging. ImageFormat. Gif)

End Sub

End Class

'--------- Code end -----

After saving the compilation, GDI_Sample1.aspx running result 11.1 is shown.

Figure 11.1 GDI_Sample1.aspx running result

When browsing through the IE browser, we can see that the page has a black background with a white dot. Of course, this is only a simple application. In the next section, we will continue to introduce the use of classes under System. Drawing.

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.