Многие, наверно, знают что такое Wrap Transform из Фотошопа. Это очень интересный (и, надо думать, сложный) эффект деформирования изображения:
(было)

(стало)

Собственно, вопрос: каким образом можно сделать такое (или аналогичное) искажение?
Function mt_rand(ByVal min As Long, ByVal max As Long) As Long
Dim ret As Single = Math.Round(Rnd() * max)
While ret < min Or ret > max
ret = Math.Round(Rnd() * max)
End While
Return CLng(ret)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim bs As Bitmap = p1.Image.Clone
Dim bd As New Bitmap(bs.Width, bs.Height)
'// случайные параметры (можно поэкспериментировать с коэффициентами):
'// частоты
Dim rand1 As Double = mt_rand(700000, 1000000) / 15000000
Dim rand2 As Double = mt_rand(700000, 1000000) / 15000000
Dim rand3 As Double = mt_rand(700000, 1000000) / 15000000
Dim rand4 As Double = mt_rand(700000, 1000000) / 15000000
'// фазы
Dim rand5 As Double = mt_rand(0, 3141592) / 1000000
Dim rand6 As Double = mt_rand(0, 3141592) / 1000000
Dim rand7 As Double = mt_rand(0, 3141592) / 1000000
Dim rand8 As Double = mt_rand(0, 3141592) / 1000000
'// амплитуды
Dim rand9 As Double = mt_rand(400, 600) / 100
Dim rand10 As Double = mt_rand(400, 600) / 100
For x As Long = 0 To bs.Width - 1
For y As Long = 0 To bs.Height - 1
Dim sx As Double = x + (Math.Sin(x * rand1 + rand5) + Math.Sin(y * rand3 + rand6)) * rand9
Dim sy As Double = y + (Math.Sin(x * rand2 + rand7) + Math.Sin(y * rand4 + rand8)) * rand10
Dim color As Long = 255
Dim color_x As Long = 255
Dim color_y As Long = 255
Dim color_xy As Long = 255
If Not (Math.Ceiling(sx) < 0 Or Math.Ceiling(sy) < 0 Or Math.Ceiling(sx) >= bs.Width - 2 Or Math.Ceiling(sy) >= bs.Height - 2) Then
color = (bs.GetPixel(Math.Ceiling(sx), Math.Ceiling(sy)).ToArgb >> 32) And &HFF
color_x = (bs.GetPixel(Math.Ceiling(sx) + 1, Math.Ceiling(sy)).ToArgb >> 32) And &HFF
color_y = (bs.GetPixel(Math.Ceiling(sx), Math.Ceiling(sy) + 1).ToArgb >> 32) And &HFF
color_xy = (bs.GetPixel(Math.Ceiling(sx) + 1, Math.Ceiling(sy) + 1).ToArgb >> 32) And &HFF
End If
Dim NewColor As Integer = color
If Not (color = color_x And color = color_y And color = color_xy) Then
Dim frsx As Double = sx - Math.Floor(sx)
Dim frsy As Double = sy - Math.Floor(sy)
Dim frsx1 As Double = 1 - frsx
Dim frsy1 As Double = 1 - frsy
NewColor = Math.Floor(color * frsx1 * frsy1 + color_x * frsx * frsy1 + color_y * frsx1 * frsy + color_xy * frsx * frsy)
End If
If NewColor > 255 Or NewColor < 0 Then Stop
bd.SetPixel(x, y, System.Drawing.Color.FromArgb(NewColor, NewColor, NewColor))
Next
Next
p2.Image = bd
End Sub
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 8