Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Professional ASP.NET 1.0 Special Edition- P6:Those of us who are Microsoft developers can't help but notice that .NET has received a fair amount of visibility over the last year or so. This is quite surprising considering that for most of this period, .NET has been in its early infancy and beta versions. I can't remember any unreleased product that has caused this much interest among developers. And that's really an important point, because ignoring all the hype and press, .NET really is a product for developers, providing a great foundation for building all types of applications | @ Import Namespace System.Drawing @ Import Namespace System.Drawing.Imaging @ Import Namespace System.Drawing.Drawing2D Response.Clear Dim height As integer 100 Dim width As integer 200 Dim r As New Random Dim x As integer r.Next 75 Dim x1 As integer 0 Dim a As integer r.Next 155 Dim x2 As integer r.Next 100 Dim bmp As new Bitmap width height PixelFormat.Format24bppRgb Dim g As Graphics Graphics.Fromlmage bmp g.SmoothingMode SmoothingMode.AntiAlias g.Clear Color.LightGray g.DrawRectangle Pens.White 1 1 width-3 height-3 g.DrawRectangle Pens.Gray 2 2 width-3 height-3 g.DrawRectangle Pens.Black 0 0 width height g.DrawString Response.OutputStream Test New Font Arial 10 FontStyle.Bold SystemBrushes.WindowText New PointF 10 50 g.FillRectangle New SolidBrush Color.FromArgb a 255 128 255 x 20 100 50 g.FillRectangle New LinearGradientBrush New Point x2 0 New Point x2 75 50 30 Color.FromArgb 128 0 0 128 Color.FromArgb 255 255 255 240 x2 50 75 30 bmp.Save Response.OutputStream ImageFormat.Jpeg g.Dispose bmp.Dispose Response.End o There are four key lines that we need to look at- we will not be looking at all of the drawing functions since they are probably worthy of an entire book to themselves First we need to tell the browser requesting this page that we are sending back a set of bytes that represent an image- not a set of text in HTML format. @ Page Language VB ContentType image jpeg Next just to be safe we want to make sure that no header information has been sent back to the browser. To do this we need to clear the buffer. Remember that when the output to the browser is buffered as is the default then we can clear out that buffer at any time before it is sent back. Response.Clear The next part of the page is going to dynamically create a Bitmap object in memory and then draw to that object. Once we have completed drawing the bitmap we will want to send it to the browser. The Save method of the Bitmap object looks like this Public Sub Save _ ByVal stream As Stream _ .