Programm(e) mit Effekten programmieren.

  • Allgemein

Es gibt 12 Antworten in diesem Thema. Der letzte Beitrag () ist von thefiloe.

    Programm(e) mit Effekten programmieren.

    Hallo

    Ich würde gerne Wissen, ob es möglich ist, in Visual Basic einen Webbrowser zu entwickeln der im Vollbild ist wie ein Spiel und Effekte hat.

    Mit Effekten meines ich sowas, was man z.B. in AfterEffects bei Videos einfügen kann, z.B. Staub der über den Webbrowser (im Fenster) fliegt sobald man einen Button drückt, so meine ich das. (Schwer zu erklären)

    Wie kann man sowas bewerkstelligen? :)
    (Edit: Wird sowas wie DirectX benötigt?)
    "Denken ist die schwerste Arbeit, die es gibt. Das ist wahrscheinlich auch der Grund, warum sich so wenig Leute damit beschäftigen." - Henry Ford
    Danke schon mal für die schnelle Antwort.

    Hmmm... Schade, Ich hätte da wirklich einige tolle Ideen gehabt, wie man ein komplett neuen Webbrowser entwickelt der einfach nur Bombe aussieht und viele neue Funktionen bietet.
    "Denken ist die schwerste Arbeit, die es gibt. Das ist wahrscheinlich auch der Grund, warum sich so wenig Leute damit beschäftigen." - Henry Ford
    Ich habe dieses Thema mal ausgegraben, weil ich nochmal eine Frage dazu habe.


    Gibt es Effekte die im Visual Studio bereits erhalten sind, oder die man sich runterladen kann?
    Ich meine jetzt so Effekte wie das die Anwendung unscharf wird, wenn man z.B. einen Ladevorgang hat, sowas würde ich nämlich gerne in mein Programm einbauen, um es Optisch etwas besser aussehen zu lassen. :)

    (Oder benötigen solche Effekte auch DirectX? Und wenn ja, was gäbe es denn zum Optischen auf hübschen der eigenen Anwendung?)
    "Denken ist die schwerste Arbeit, die es gibt. Das ist wahrscheinlich auch der Grund, warum sich so wenig Leute damit beschäftigen." - Henry Ford

    Vultrax schrieb:

    Ich meine jetzt so Effekte wie das die Anwendung unscharf wird

    Schnell zusammengehackt:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Public Class Form1
    2. Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    3. Using bmp As New Bitmap(Me.Width, Me.Height)
    4. Using g As Graphics = Graphics.FromImage(bmp)
    5. g.CopyFromScreen(Me.PointToScreen(Me.ClientRectangle.Location), New Point(0, 0), Me.ClientRectangle.Size)
    6. End Using
    7. Me.BackgroundImage = generateBlur(CType(bmp.Clone, Bitmap))
    8. End Using
    9. For Each c As Control In Me.Controls
    10. c.Visible = False
    11. Next
    12. End Sub
    13. Private Function generateBlur(img As Bitmap) As Bitmap
    14. Dim conv As New convolutionFilters
    15. Dim grid As convolutionFilters.ConvMatrix
    16. ' get a grid:
    17. grid = conv.GetGrid
    18. ' set the grid as in the web site:
    19. grid.SetAll(1)
    20. grid(1) = 3
    21. grid(3) = 3
    22. grid(4) = 0
    23. grid(5) = 3
    24. grid(7) = 3
    25. grid.Factor = 16
    26. ' process:
    27. conv.conv3x3(img, grid)
    28. Return img
    29. End Function
    30. End Class

    Die convolutionFilters.vb musst du dir selbst anlegen. Der Inhalt ist das hier, einmal durch den C#->VB Converter gejagt: codeproject.com/Articles/2008/…ies-with-C-and-GDI-Part-2

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.Drawing.Imaging
    2. Imports System.Runtime.InteropServices
    3. Imports System.Drawing
    4. Public Class convolutionFilters
    5. ' the matrix class
    6. Public Class ConvMatrix
    7. Public Factor As Integer = 1
    8. Public Offset As Integer = 0
    9. 'instead of all those integers, we'll use an array:
    10. Public grid(8) As Integer
    11. ' then we can get it in a for... next loop
    12. Sub New()
    13. ' fill up with defaults
    14. For i As Integer = 0 To 8
    15. grid(i) = 0
    16. Next
    17. grid(4) = 1
    18. End Sub
    19. Public Sub SetAll(ByVal value As Integer)
    20. 'allows us to set all the items in grid to the same value
    21. For i As Integer = 0 To 8
    22. grid(i) = value
    23. Next
    24. End Sub
    25. Default Property item(ByVal index As Integer) As Integer
    26. ' default property means we dont have to use the keyword "item"
    27. ' lets us set the values at grid(value)
    28. Get
    29. Return grid(index)
    30. End Get
    31. Set(ByVal Value As Integer)
    32. grid(index) = Value
    33. End Set
    34. End Property
    35. End Class
    36. Private _grid As ConvMatrix ' for the property:
    37. ' Allow us to get a grid
    38. Public ReadOnly Property GetGrid() As ConvMatrix
    39. Get
    40. Return _grid
    41. End Get
    42. End Property
    43. Sub New()
    44. _grid = New ConvMatrix
    45. End Sub
    46. Public Function conv3x3(ByVal b As Bitmap, ByVal m As ConvMatrix) As Boolean
    47. ' this will always be fairly slow as for each pixel we are reading 9 other pixels to get
    48. ' the final color value. The perpixel filters just read from one pixel.
    49. 'avoid / by 0
    50. If m.Factor = 0 Then Return True
    51. ' We are moving through the bitmap, and changing pixels based on their surrounding
    52. ' pixels. This means that we need a copy of the source bitmap, so that we don't
    53. ' end up using pixels that we have changed (and so filter based on changed pixels)
    54. ' So here is a copy of the input bitmap:
    55. Dim bSrc As Bitmap = CType(b.Clone, Bitmap)
    56. ' So we want Two lockbits now. We lock the source bits
    57. Dim bmSrc As BitmapData = _
    58. bSrc.LockBits(New Rectangle(0, 0, bSrc.Width, bSrc.Height), _
    59. ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb)
    60. ' And we lock the target bits
    61. Dim bmData As BitmapData = _
    62. b.LockBits(New Rectangle(0, 0, b.Width, b.Height), _
    63. ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb)
    64. ' We need the pointers to the start of both images data:
    65. Dim Scan0 As IntPtr = bmData.Scan0
    66. Dim SrcScan0 As IntPtr = bmSrc.Scan0
    67. ' We are storing all the pixels as int32s in arrays:
    68. Dim pixels(b.Width * b.Height - 1) As Integer
    69. Dim pixelsSrc(b.Width * b.Height - 1) As Integer
    70. ' Marshal copy grabs the pixels
    71. Marshal.Copy(Scan0, pixels, 0, pixels.Length)
    72. Marshal.Copy(SrcScan0, pixelsSrc, 0, pixelsSrc.Length)
    73. ' keep a running total (more later)...
    74. Dim total(3) As Single ' store sum of the pixels read from the source
    75. Dim index As Integer
    76. Dim gridValueDivmFactor As Single
    77. Dim ninthOfOffset As Single = CSng(m.Offset / 9)
    78. ' We are manipulating a pixel based on all its surrounding pixels
    79. ' the pixels on the edges don't have all the surrounding pixels
    80. ' so we skip them by staring these loops at 1 and ending at blah -2
    81. For y As Integer = 1 To b.Height - 2
    82. For x As Integer = 1 To b.Width - 2
    83. ' We have defined a 3x3 grid and we apply it to the pixels
    84. ' around the current one: (E is current pixel)
    85. '
    86. ' pixels grid
    87. ' A B C 0 1 2
    88. ' D E F with 3 4 5
    89. ' G H I 6 7 8
    90. '
    91. ' (this is not matrix multiplication)
    92. '
    93. ' We get: (A*1) + (B*2) + (C*3) + (D*4) + (E*5) + (F*6) + (G*7) + (H*8) + (I*9)
    94. ' we then divide this by m.factor and add m.offset...
    95. '
    96. ' e.g. with the starting grid:
    97. ' 000
    98. ' 010
    99. ' 000 we get the result E = the value of the central pixel so no change to the image
    100. '
    101. ' Our For ... Next loop puts the current pixel at (x,y)
    102. ' This means we need to get the pixels in the following positions:
    103. ' (x-1,y-1) ( x ,y-1) (x+1,y-1)
    104. ' (x-1, y ) ( x , y ) (x+1, y )
    105. ' (x-1,y+1) ( x ,y+1) (x+1,y+1)
    106. '
    107. ' Another loop
    108. ' This one loops through a 3x3 grid:
    109. For yy As Integer = -1 To +1
    110. For xx As Integer = -1 To +1
    111. ' the central pixel(x,y) is in the array at this index:
    112. ' (y * b.Width) pixels in the rows above + x pixels in the current row
    113. ' (y * b.width) + x
    114. ' the yyxx for next loop gives us: (-1,-1) (0,-1) (1,-1)
    115. ' (-1,0) (0,0) (1,0)
    116. ' (-1,1) (0,1) (1,1)
    117. '
    118. 'so... the locaion of the pixels in the loop is (x+xx,y+yy)
    119. 'and the position in the array is:
    120. '
    121. index = ((y + yy) * b.Width) + x + xx
    122. 'we want to total the argb of the current pixel * the grid value for its position
    123. 'we'll do the factor here too, and add on 1/9 of offset
    124. 'trying to keep the number of calculations in the loops to a minimum
    125. gridValueDivmFactor = CSng(m.grid(((yy + 1) * 3) + (xx + 1)) / m.Factor)
    126. 'ignore alpha, it messes up with some filters. will just set it to 255
    127. 'total(0) += (((pixelsSrc(index) >> 24) And &HFF) * gridValueDivmFactor) + ninthOfOffset
    128. total(1) += (((pixelsSrc(index) >> 16) And &HFF) * gridValueDivmFactor) + ninthOfOffset
    129. total(2) += (((pixelsSrc(index) >> 8) And &HFF) * gridValueDivmFactor) + ninthOfOffset
    130. total(3) += ((pixelsSrc(index) And &HFF) * gridValueDivmFactor) + ninthOfOffset
    131. Next
    132. Next
    133. For i As Integer = 0 To 3
    134. If total(i) > 255 Then total(i) = 255
    135. If total(i) < 0 Then total(i) = 0
    136. Next
    137. 'finally we set the pixel in the destination bitmap
    138. pixels(y * b.Width + x) = (255 << 24) _
    139. Or (Convert.ToInt32(total(1)) << 16) _
    140. Or (Convert.ToInt32(total(2)) << 8) _
    141. Or Convert.ToInt32(total(3))
    142. 'reset total for next pixel
    143. Array.Clear(total, 0, 4)
    144. Next
    145. Next
    146. Marshal.Copy(pixels, 0, Scan0, pixels.Length)
    147. 'unlock both bitmaps
    148. b.UnlockBits(bmData)
    149. bSrc.UnlockBits(bmSrc)
    150. Return True
    151. End Function
    152. End Class
    Bilder
    • unbenannt.png

      52,54 kB, 684×320, 262 mal angesehen

    Skybird schrieb:

    Das sind ja Ubisoftmethoden hier !

    Das sieht ja schon mal nicht schlecht aus @vb-checker. Vergleicht man es aber mit WPF hast du hier fast 100 VB-Codezeilen und in WPF eine XAML-Codezeile + vielfache Performance.


    Opensource Audio-Bibliothek auf github: KLICK, im Showroom oder auf NuGet.