VB.Net/2D/Texture — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 16:40, 26 мая 2010
Содержание
Fill textureBitmap with yellow
Imports System
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.Drawing.Text
Public Class MainClass
Shared Sub Main()
Dim myform As Form = New FrmDrawShapes()
Application.Run(myform)
End Sub " Main
End Class
Public Class FrmDrawShapes
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.Container
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
"
"frmDrawShapes
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(520, 197)
Me.Name = "frmDrawShapes"
Me.Text = "Drawing Shapes"
End Sub
#End Region
" draw various shapes on form
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim graphicsObject As Graphics = e.Graphics
" bitmap texture
Dim textureBitmap As Bitmap = New Bitmap(10, 10)
Dim graphicsObject2 As Graphics = _
Graphics.FromImage(textureBitmap) " get bitmap graphics
" brush and pen used throughout program
Dim solidColorBrush As SolidBrush = _
New SolidBrush(Color.Red)
Dim coloredPen As Pen = New Pen(solidColorBrush)
" fill textureBitmap with yellow
solidColorBrush.Color = Color.Yellow
graphicsObject2.FillRectangle(solidColorBrush, 0, 0, 10, 10)
" draw small black rectangle in textureBitmap
coloredPen.Color = Color.Black
graphicsObject2.DrawRectangle(coloredPen, 1, 1, 6, 6)
" draw small blue rectangle in textureBitmap
solidColorBrush.Color = Color.Blue
graphicsObject2.FillRectangle(solidColorBrush, 1, 1, 3, 3)
" draw small red square in textureBitmap
solidColorBrush.Color = Color.Red
graphicsObject2.FillRectangle(solidColorBrush, 4, 4, 3, 3)
" create textured brush and display textured rectangle
Dim texturedBrush As TextureBrush = _
New TextureBrush(textureBitmap)
graphicsObject.FillRectangle(texturedBrush, 155, 30, 75, 100)
End Sub " OnPaint
End Class
Texture Brush Demo
Imports System.Drawing.Drawing2D
Imports System
Imports System.Drawing.Text
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Math
Public Class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1()
Application.Run(form1)
End Sub
End Class
Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim txt As String = "Path"
Dim graphics_path As New GraphicsPath
graphics_path.AddString(txt, _
New FontFamily("Times New Roman"), _
FontStyle.Bold, 150, _
New Point(0, 0), _
New StringFormat)
Dim smiley_brush As New TextureBrush(new Bitmap("figure2.bmp"))
e.Graphics.FillPath(smiley_brush, graphics_path)
e.Graphics.DrawPath(Pens.Black, graphics_path)
End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Public Class Form1
Inherits System.Windows.Forms.Form
"Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.SuspendLayout()
"
"Form1
"
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(800, 400)
Me.Name = "Form1"
Me.Text = "TransformArrow"
Me.ResumeLayout(False)
End Sub
End Class
Texture Brushes Form
Imports System
Imports System.Collections
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Resources
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class MainClass
Shared Sub Main()
Dim myform As Form = New TextureBrushesForm()
Application.Run(myform)
End Sub
End Class
Public Class TextureBrushesForm
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
components = New System.ruponentModel.Container()
Me.Text = "TextureBrushesForm"
End Sub
#End Region
Private Sub TextureBrushesForm_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint
Dim g As Graphics = e.Graphics
Dim x As Integer = 0
Dim y As Integer = 0
Dim width As Integer = Me.ClientRectangle.Width
Dim height As Integer = Me.ClientRectangle.Height / 6
Dim blackBrush As Brush = Brushes.Black
Dim blackPen As Pen = Pens.Black
Dim file As String = "BEANY.BMP"
Dim b As Brush = New TextureBrush(New Bitmap(file), Drawing.Drawing2D.WrapMode.Clamp)
g.FillRectangle(b, x, y, width, height)
g.DrawRectangle(blackPen, x, y, width, height)
g.DrawString(CType(b, TextureBrush).WrapMode.ToString(), Me.Font, blackBrush, x, y)
y = y + height
b = New TextureBrush(New Bitmap(file), Drawing.Drawing2D.WrapMode.Tile)
g.FillRectangle(b, x, y, width, height)
g.DrawRectangle(blackPen, x, y, width, height)
g.DrawString(CType(b, TextureBrush).WrapMode.ToString(), Me.Font, blackBrush, x, y)
y = y + height
b = New TextureBrush(New Bitmap(file), Drawing.Drawing2D.WrapMode.TileFlipX)
g.FillRectangle(b, x, y, width, height)
g.DrawRectangle(blackPen, x, y, width, height)
g.DrawString(CType(b, TextureBrush).WrapMode.ToString(), Me.Font, blackBrush, x, y)
y = y + height
b = New TextureBrush(New Bitmap(file), Drawing.Drawing2D.WrapMode.TileFlipY)
g.FillRectangle(b, x, y, width, height)
g.DrawRectangle(blackPen, x, y, width, height)
g.DrawString(CType(b, TextureBrush).WrapMode.ToString(), Me.Font, blackBrush, x, y)
y = y + height
b = New TextureBrush(New Bitmap(file), Drawing.Drawing2D.WrapMode.TileFlipXY)
g.FillRectangle(b, x, y, width, height * 2)
g.DrawRectangle(blackPen, x, y, width, height * 2)
g.DrawString(CType(b, TextureBrush).WrapMode.ToString(), Me.Font, blackBrush, x, y)
y = y + height
End Sub
End Class
Texture Brush with Rotate and Transformation
Imports System.Drawing.Drawing2D
Imports System
Imports System.Drawing.Text
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Math
Public Class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1()
Application.Run(form1)
End Sub
End Class
Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim texture_brush As New TextureBrush(new Bitmap("figure2.bmp"))
texture_brush.ScaleTransform(2, 1, MatrixOrder.Append)
texture_brush.RotateTransform(30, MatrixOrder.Append)
e.Graphics.FillEllipse(texture_brush, 100 , 100 , 100, 100)
End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Public Class Form1
Inherits System.Windows.Forms.Form
"Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.SuspendLayout()
"
"Form1
"
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(200, 200)
Me.Name = "Form1"
Me.Text = ""
Me.ResumeLayout(False)
End Sub
End Class