Hallo, wollte gerne per VB6.0 eine jpg Datei drehen können
habe den Quelltest dazu auf der Microsoft-Seite gefunden:
'Bild in beliebigem Winkel drehen
Public Sub BildDrehen(ByVal picSource As PictureBox, ByVal picDest As _
PictureBox, Optional ByVal DrehWinkel As Long = 0)
Const pi = 3.14159265359
' cp0 - cp3 = Farbe eines einzelnen Pixels
Dim cp0 As Long, cp1 As Long
Dim cp2 As Long, cp3 As Long
' Bild-Dimensionen
Dim w1 As Long, h1 As Long
Dim w2 As Long, h2 As Long
Dim p1x As Double, p1y As Double
Dim p2x As Double, p2y As Double
Dim n As Double, r As Double, a As Double
picSource.AutoSize = True
picSource.Visible = False
' AutoRedraw einschalten
picSource.AutoRedraw = True
picDest.AutoRedraw = True
' ScaleMode auf Pixel setzen
picSource.ScaleMode = vbPixels
picDest.ScaleMode = vbPixels
' Zielbild zunächst löschen
Set picDest.Picture = Nothing
picDest.Cls
w1 = picSource.ScaleWidth \ 2
h1 = picSource.ScaleHeight \ 2
w2 = picDest.ScaleWidth \ 2
h2 = picDest.ScaleHeight \ 2
' DrehWinkel = pi * (DrehWinkel / 180)
If w2 < h2 Then n = h2 Else n = w2
n = n - 1
For p2x = 0 To n
For p2y = 0 To n
' Position berechnen
If p2x = 0 Then a = pi / 2 Else a = Atn(p2y / p2x)
r = Sqr(p2x * p2x + p2y * p2y)
p1x = r * Cos(a + (pi * DrehWinkel / 180))
p1y = r * Sin(a + (pi * DrehWinkel / 180))
' Bildpunkte ermitteln
cp0 = picSource.Point(w1 + p1x, h1 + p1y)
cp1 = picSource.Point(w1 - p1x, h1 - p1y)
cp2 = picSource.Point(w1 + p1y, h1 - p1x)
cp3 = picSource.Point(w1 - p1y, h1 + p1x)
' neue Bildpunkte setzen
If cp0 <> -1 Then picDest.PSet (w2 + p2x, h2 + p2y), cp0
If cp1 <> -1 Then picDest.PSet (w2 - p2x, h2 - p2y), cp1
If cp2 <> -1 Then picDest.PSet (w2 + p2y, h2 - p2x), cp2
If cp3 <> -1 Then picDest.PSet (w2 - p2y, h2 + p2x), cp3
Next p2y
Next p2x
Set picDest.Picture = picDest.Image
End Sub Der Aufruf dazu: Call BildDrehen(picOriginalBild, Picture1, 90)
picOriginalBild => 1.PictureBox
Picture1 => 2.PictureBox
90 => Gradzahl um die das Bild gedreht wird
Mein Problem ist nun, dass ich das Bilde gerne mit folgendem Quelltest noch Skalieren würde:
'Foto vorschau Hochkant in PicBox
Picture1.Height = 5295
Picture1.Width = 3350
Picture1.Left = 3000
'Set Pic = LoadPicture(File1.Path & "\" & File1.List(File1.ListIndex))
picOriginalBild.Picture = LoadPicture(File1.Path & "\" & File1.List( _
File1.ListIndex))
h = (picOriginalBild.Height / 254) * 144
w = (picOriginalBild.Width / 254) * 144
Call BildDrehen(picOriginalBild, Picture1, 90)
'Picture1.PaintPicture Pic, 0, 0, Picture1.Width, Picture1.Height, 0,
' 0, w, h Das Bild wird im Aufruf dann übergeben aber ich kann irgend wie nicht drauf zu greifen!
Am allerliebsten wäre mir, dass das Bild als Stdpicture/Picture ausgeben wird. Zum Beispiel an die Variabele "pic" (Stdpicture), leider bekomme ich es immer an die Picturebox weitergegeben.
Ich habe auch die unterschiede bzw. zusammen hänge von STDPICTURE / IMAGE / PICTURE nicht verstanden.
Wäre echt klasse wenn da jemand mal drüber schauen könnte...
Schon mal Vielen Dank Cay1 |