Asp. NET to generate a simple picture _ basic Application

Source: Internet
Author: User
In this section we create a simple picture as an introductory training for asp.net graphics processing.
First Use VisualStudio.NET 2003 to create a new Web application, named Gditec, create a new Web Form named Gdi_sample1.aspx, and we write logical 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 the code generated by the 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

' The user code to place the initialization page here

' Declare Bitmap object

' Bitmap object is a canvas, and we can make graphics on it with a canvas.

Dim Objbitmap as Bitmap

Dim I as Integer

' declares a random seed that is used 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 i = 1 to 5000

Objbitmap.setpixel (Objrandom.next), Objrandom.next (MB), Color.White)

Next

' Saves the Objgraphics object to the specified stream object in the specified graphic format (here is GIF).

' and output to the client. The Save method has 5 overloads that you can save to your hard disk, and you can choose a different picture format

Objbitmap.save (Response.outputstream, Drawing.Imaging.ImageFormat.Gif)

End Sub

End Class

'---------Code End-----

After you save the compilation, the gdi_sample1.aspx run the results as shown in Figure 11.1.

Figure 11.1 Gdi_sample1.aspx Run Results

When browsing through IE browser, we can see that there is a black background with white dots on the page. Of course this is just a simple application, and in the next section we will continue to introduce the use of classes under System.Drawing.

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.