Public Function Bild_in_Polygon_OK(ByVal bm_out As Bitmap, ByVal bm_pg As Bitmap, ByVal bm_pgs As Bitmap, ByVal pg() As Point, ByVal opt_bgw As Boolean) As Boolean 'bm_out Zielbitmap, in die eingefügt wird 'bm_pg Bitmap, die eingefügt wird 'bm_pgs Bitmap zur Maskierung von Bereichen, optional 'pg Polygon-Punkte, Eckpunkte des gezerrten Bereichs 'opt_bgw Flag zur Steuerung des Lockbit-Datenbereichs Bild_in_Polygon_OK = True 'Sicherstellen, dass p(1) immer oben links ist Dim p() As Point = Punkte_ordnen(pg) 'Die Punkte pm(2) als umschließendes Rechteck Dim pm() As Point = Min_Max_Punkte(p) Dim x_von As Integer Dim x_bis As Integer Dim y_von As Integer Dim y_bis As Integer Try x_von = pm(1).X x_bis = pm(2).X y_von = pm(1).Y y_bis = pm(2).Y If x_von < 0 Then x_von = 0 If y_von < 0 Then y_von = 0 If x_bis >= bm_out.Width Then x_bis = bm_out.Width - 1 If y_bis >= bm_out.Height Then y_bis = bm_out.Height - 1 Catch ex As Exception 'MsgBox(ex.ToString) Return False Exit Function End Try Dim x0A As Single Dim x0B As Single Dim y0A As Single Dim y0B As Single Dim xr As Long = 0 Dim yr As Long = 0 Dim c2 As stcRGB c2.Rot = 255 c2.Grün = 0 c2.Blau = 0 Dim selektion As Boolean = False If Not bm_pgs Is Nothing Then selektion = True End If '-------------------------------------------------------------------------- If Bitmap_L1_Lock_OK(bm_pg, "Bild_in_Polygon_bm_pg", opt_bgw) = False Then Return False Exit Function End If If Bitmap_S1_Lock_OK(bm_out, "Bild_in_Polygon_bm_out", opt_bgw) = False Then Bitmap_L1_Unlock(bm_pg, opt_bgw) Return False Exit Function End If If selektion Then If Bitmap_L2_Lock_OK(bm_pgs, "Bild_in_Polygon_bm_pgs", opt_bgw) = False Then Bitmap_L1_Unlock(bm_pg, opt_bgw) Bitmap_S1_Unlock(bm_out, opt_bgw) Return False Exit Function End If End If '-------------------------------------------------------------------------- For y = y_von To y_bis If p(1).Y = p(4).Y Then x0A = Math.Abs(p(4).X - p(1).X) / 2 Else x0A = (y - p(1).Y) * (p(4).X - p(1).X) / (p(4).Y - p(1).Y) + p(1).X End If If p(2).Y = p(3).Y Then x0B = Math.Abs(p(2).X - p(3).X) / 2 Else x0B = (y - p(3).Y) * (p(2).X - p(3).X) / (p(2).Y - p(3).Y) + p(3).X End If For x = x_von To x_bis If p(1).X = p(2).X Then y0A = Math.Abs(p(2).Y - p(1).Y) / 2 Else y0A = (x - p(1).X) * (p(2).Y - p(1).Y) / (p(2).X - p(1).X) + p(1).Y End If If p(4).X = p(3).X Then y0B = Math.Abs(p(3).Y - p(4).Y) / 2 Else y0B = (x - p(4).X) * (p(3).Y - p(4).Y) / (p(3).X - p(4).X) + p(4).Y End If '--------------------------------------------------------- If Math.Abs(y0A - y0B) > 0 Then yr = CLng(bm_pg.Height * (y - y0A) / (y0B - y0A)) Else 'BMD_S1_setRGB(x, y, c2, opt_bgw) Continue For End If If Math.Abs(x0A - x0B) > 0 Then xr = CLng(bm_pg.Width * (x - x0A) / (x0B - x0A)) Else 'BMD_S1_setRGB(x, y, c2, opt_bgw) Continue For End If If xr < 0 Or xr >= bm_pg.Width _ Or yr < 0 Or yr >= bm_pg.Height Then 'BMD_S1_setRGB(x, y, c1, opt_bgw) Continue For End If '--------------------------------------------------------- If selektion Then If BMD_L2_getRGB(xr, yr, opt_bgw).Blau > 127 Then Continue For End If End If 'Pixel(xr, yr) in bm_pg lesen und in bm_out(x,y) schreiben '=========================================================== BMD_S1_setRGB(x, y, BMD_L1_getRGB(xr, yr, opt_bgw), opt_bgw) '=========================================================== Next Next Bitmap_L1_Unlock(bm_pg, opt_bgw) Bitmap_S1_Unlock(bm_out, opt_bgw) If selektion Then Bitmap_L2_Unlock(bm_pgs, opt_bgw) End If End Function