⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 paintimage.aspx

📁 asp.net技术内幕的书配源码
💻 ASPX
字号:
<%@ Page ContentType="image/gif" %>
<%@ Import namespace="System.Drawing" %>
<%@ Import namespace="System.Drawing.Imaging" %>

<Script Runat="Server">

Sub Page_Load
  Dim objBitmap As Bitmap
  Dim objGraphics As Graphics
  Dim objPen As Pen
  Dim strAction As String
  Dim strColor As String
  Dim objColor As Color
  Dim intOldX, intOldY As Integer 
  Dim intNewX, intNewY As Integer

  ' Create or Retrieve Bitmap
  objBitmap = Session( "Canvas" )
  If objBitmap Is Nothing Then
    objBitmap = New Bitmap( 600, 400, PixelFormat.Format32bppARGB )
  End If
  objGraphics  = Graphics.FromImage( objBitmap )

  ' Get Action, Color, and Coordinates
  strAction = Request.QueryString( "a" )
  strColor = Request.QueryString( "color" )
  intNewX = Request.QueryString( "x" )
  intNewY = Request.QueryString( "y" )
  intOldX = Session( "OldX" )
  intOldY = Session( "OldY" )

  ' Create Pen
  If strColor <> Nothing Then
    objColor = Color.FromName( strColor )
    objPen = New Pen( objColor )
  Else
    objColor = Color.White
    objPen = New Pen( objColor )
  End If

  ' Perform Action
  Select Case strAction
    Case "SetPixel"
      objBitMap.SetPixel( intNewX, intNewY, objColor )
    Case "DrawLine"
      If intOldX <> Nothing Then
        objGraphics.DrawLine( objPen, intOldX, intOldY, intNewX, intNewY )
      End If
    Case "DrawLine"
      If intOldX <> Nothing Then
        objGraphics.DrawLine( objPen, intOldX, intOldY, intNewX, intNewY )
      End If
    Case "DrawRectangle"
      If intOldX <> Nothing Then
        objGraphics.DrawRectangle( objPen, intOldX, intOldY, intNewX - intOldX, intNewY - intOldY )
      End If
    Case "FillRectangle"
      If intOldX <> Nothing Then
        objGraphics.FillRectangle( New SolidBrush( objColor ), intOldX, intOldY, intNewX - intOldX, intNewY - intOldY )
      End If
  End Select

  ' Display the Bitmap
  objBitmap.Save( Response.OutputStream, ImageFormat.GIF)

  ' Save the Bitmap
  Session( "Canvas" ) = objBitMap

  If Session( "OldX" ) <> Nothing Then
    Session( "OldX" ) = Nothing
    Session( "OldY" ) = Nothing
  Else
    Session( "OldX" ) = intNewX
    Session( "OldY" ) = intNewY
  End If
End Sub

</Script>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -