VB.Net by API/System.Drawing.Drawing2D/Matrix — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 12:51, 26 мая 2010
Содержание
Matrix.Elements
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class Test
public Shared Sub Main
Dim X As New Matrix(2, 1, 3, 1, 0, 4)
Dim i As Integer
For i = 0 To X.Elements.Length - 1
Console.WriteLine(X.Elements(i))
Next i
Console.WriteLine("Inverted values: ")
X.Invert()
Dim pts As Single() = X.Elements
Dim i1 As Integer
For i = 0 To pts.Length - 1
Console.WriteLine(pts(i))
Next i
End Sub
End class
Matrix.Invert
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class MatrixReflection
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
public class Form1
Inherits System.Windows.Forms.Form
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim g As Graphics = Me.CreateGraphics()
g.Clear(Me.BackColor)
Dim curBitmap As New Bitmap("yourfile.jpg") "
Dim X As New Matrix
X.Invert()
g.Transform = X
g.DrawImage(curBitmap, New Rectangle(0, 0, 200, 200), 0, 0, curBitmap.Width, curBitmap.Height, GraphicsUnit.Pixel)
" Dispose
curBitmap.Dispose()
g.Dispose()
End Sub
Public Sub New()
MyBase.New()
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
End Sub
End Class
Matrix.Multiply
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class Test
public Shared Sub Main
Dim X As New Matrix(2.0F, 1.0F, 3.0F, 1.0F, 0.0F, 4.0F)
Dim Y As New Matrix(0.0F, 1.0F, -1.0F, 0.0F, 0.0F, 0.0F)
X.Multiply(Y, MatrixOrder.Append)
" Read the result Matrix
Dim i As Integer
For i = 0 To X.Elements.Length - 1
Console.WriteLine(X.Elements(i).ToString())
Next i
End Sub
End class
Matrix.Rotate
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Drawing.Imaging
Public Class MainClass
Shared Sub Main()
Dim m As Matrix = New Matrix()
m.Rotate(90, MatrixOrder.Append)
m.Translate(7, 12, MatrixOrder.Append)
Dim p() As Point = {New Point(20, 45)}
Console.WriteLine(p.GetValue(0).ToString())
m.TransformPoints(p)
Console.WriteLine(p.GetValue(0).ToString())
End Sub
End Class
Matrix.RotateAt
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class MatrixRotateAt
public Shared Sub Main
Application.Run(New RotateForm)
End Sub
End class
Public Class RotateForm
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(280, 214)
Me.Name = "RotateForm"
Me.Text = "RotateForm"
End Sub
Sub RotateForm_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint
Dim g As Graphics = e.Graphics
Dim x As Integer = 400
Dim y As Integer = 400
Dim width As Integer = 250
Dim height As Integer = 250
Dim textWidth As Single = g.MeasureString("00", Me.Font).Width
Dim length As Single = 250
Dim textRect As RectangleF = New RectangleF(x + length, y - Me.Font.GetHeight(g) / 2, length, textWidth)
Dim format As StringFormat = New StringFormat()
format.Alignment = StringAlignment.Near
format.LineAlignment = StringAlignment.Center
Dim i As Integer
For i = 0 To 360 Step 5
Dim matrix As Matrix = New Matrix()
matrix.RotateAt(i, New PointF(x, y))
g.Transform = matrix
g.DrawLine(Pens.Black, x, y, x + length, y)
g.DrawString(i.ToString(), Me.Font, Brushes.Black, textRect, format)
Next
End Sub
End Class
Matrix.Shear
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class TransformPathGradientBrush
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
public class Form1
Inherits System.Windows.Forms.Form
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim g As Graphics = Me.CreateGraphics()
g.Clear(Me.BackColor)
Dim path As New GraphicsPath
Dim rect As New Rectangle(20, 20, 200, 200)
path.AddRectangle(rect)
Dim pgBrush As New PathGradientBrush(path.PathPoints)
pgBrush.CenterColor = Color.Green
pgBrush.SurroundColors = New Color() {Color.Blue}
Dim M As New Matrix
M.Translate(20.0F, 10.0F, MatrixOrder.Prepend)
M.Rotate(10.0F, MatrixOrder.Prepend)
M.Scale(2, 1, MatrixOrder.Prepend)
M.Shear(0.05F, 0.03F, MatrixOrder.Prepend)
pgBrush.MultiplyTransform(M)
g.FillRectangle(pgBrush, 20, 100, 400, 400)
pgBrush.Dispose()
g.Dispose()
End Sub
Public Sub New()
MyBase.New()
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
End Sub
End Class
Matrix.TransformPoints
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Drawing.Imaging
Public Class MainClass
Shared Sub Main()
Dim m As Matrix = New Matrix()
m.Rotate(90, MatrixOrder.Append)
m.Translate(7, 12, MatrixOrder.Append)
Dim p() As Point = {New Point(20, 45)}
Console.WriteLine(p.GetValue(0).ToString())
m.TransformPoints(p)
Console.WriteLine(p.GetValue(0).ToString())
End Sub
End Class
Matrix.Translate(Int x, Int y)
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class MatrixTranslationDemo
public Shared Sub Main
Application.Run(New TranslationForm)
End Sub
End class
Public Class TranslationForm
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
End Sub
Sub TranlationForm_Pain(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint
Dim g As Graphics = e.Graphics
Dim rect As RectangleF = New RectangleF(0, 0, 125, 125)
g.FillRectangle(Brushes.White, rect)
g.DrawRectangle(Pens.Black, rect.X, rect.Y, rect.Width, rect.Height)
Dim matrix As Matrix = New Matrix()
matrix.Translate(150, 150)
g.Transform = matrix
g.FillRectangle(Brushes.White, rect)
g.DrawRectangle(Pens.Black, rect.X, rect.Y, rect.Width, rect.Height)
End Sub
End Class