![]() |
Tipp 0154
|
Grafik in beliebigem Winkel drehen
|
 |
|
Autor/Einsender: Datum: |
|
Gerald Kimmersdorfer 29.12.2006 |
|
Entwicklungsumgebung: |
|
VB.Net 2005 |
Framework: |
|
2.0 |
|
|
Grafiken können wie in Tipp Bilder drehen und spiegeln mit der RotateFlipType-Enumeration in fest vorgegebenen
Winkeln gedreht werden, oder aber auch mit den Grafikmethoden TranslateTransForm und RotateTransform um den Mittelpunkt
im angegebenen, frei wählbaren Winkel. Darüber hinaus kann über die Eigenschaft Graphics.InterpolationMode der Interpolationsmodus
festgelegt werden.
|
In diesem Tipp wird eine Demo-Routine mit einem Timer zur Veranschaulichung der Schnelligkeit der Drehaktionen eingesetzt.
|
|
|
Imports System.Drawing.Imaging
Public Class Form1
Dim Buffer As Bitmap
Dim graph As Graphics
Dim Xtmr As Integer
Private Sub Winkelscroll_Scroll(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.ScrollEventArgs) Handles _
Winkelscroll.Scroll
Winkelanz.Text = Winkelscroll.Value / 10 & "°"
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Buffer = New Bitmap(PictureBox1.Width, PictureBox1.Height, _
PixelFormat.Format32bppPArgb)
graph = Graphics.FromImage(Buffer)
Call DreheBild()
End Sub
Private Sub DreheBild()
graph.Clear(Color.Transparent)
graph.ResetTransform()
graph.TranslateTransform(PictureBox1.Width / 2, _
PictureBox1.Height / 2, Drawing2D.MatrixOrder.Append)
graph.RotateTransform(Winkelscroll.Value / 10)
graph.DrawImage(PictureBox1.Image, _
New Rectangle(-PictureBox1.Width / 2, _
-PictureBox1.Height / 2, PictureBox1.Width, _
PictureBox1.Height))
Vorschau.Image = Buffer
End Sub
Private Sub Go_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Go.Click
Call DreheBild()
End Sub
Private Sub einst1_SelectedIndexChanged(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles _
einst1.SelectedIndexChanged
On Error Resume Next
Select Case einst1.Text
Case "HighQualityBicubic"
graph.InterpolationMode = _
Drawing2D.InterpolationMode.HighQualityBicubic
Case "Bicubic"
graph.InterpolationMode = _
Drawing2D.InterpolationMode.Bicubic
Case "Bilinear"
graph.InterpolationMode = _
Drawing2D.InterpolationMode.Bilinear
Case "High"
graph.InterpolationMode = Drawing2D.InterpolationMode.High
Case "HighQualityBilinear"
graph.InterpolationMode = _
Drawing2D.InterpolationMode.HighQualityBilinear
Case "Low"
graph.InterpolationMode = Drawing2D.InterpolationMode.Low
Case "NearestNeighbor"
graph.InterpolationMode = _
Drawing2D.InterpolationMode.NearestNeighbor
End Select
Call DreheBild()
End Sub
Private Sub DemoTMR_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles DemoTMR.Tick
Winkelscroll.Value = Winkelscroll.Value + Xtmr
Winkelanz.Text = Winkelscroll.Value / 10 & "°"
If Winkelscroll.Value >= 3600 Then
Xtmr = -10
End If
If Winkelscroll.Value <= -3600 Then
Xtmr = 10
End If
Call DreheBild()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "Demo starten" Then
Button1.Text = "Demo beenden"
DemoTMR.Enabled = True
Xtmr = 10
Winkelscroll.Value = CInt(Winkelscroll.Value / 10) * 10
Else
Button1.Text = "Demo starten"
DemoTMR.Enabled = False
End If
End Sub
End Class
|
|
|
|
|
Windows-Version |
98/SE |
 |
|
ME |
 |
|
NT |
 |
|
2000 |
 |
|
XP |
 |
|
Vista |
 |
|
Win
7 |
 |
|
|
|
Download (49,6 kB)
|
Downloads bisher: [ 905 ]
|
|
|