VB.NET在不同位置的PictureBox上绘制多个图像

VB.NET在不同位置的PictureBox上绘制多个图像,.net,vb.net,graphics,gdi+,system.drawing,.net,Vb.net,Graphics,Gdi+,System.drawing,我在PictureBox中有一个图像,我还想在PictureBox的不同位置绘制一些其他图像 例如,我想在PictureBox中的一张图片上绘制几张图片,就像这两颗星(都是带有透明背景的单独图片(PNG)): 我想在不同的位置画多颗不同的星星,下面的图片是一个例子。(美国地图是图片盒中已经存在的图像 我试图编写一个函数,当提供/给定PictureBox的x和y值和图像的位置(例如My.Resources.RedCity或My.Resources.BlueCity)的Point变量时,该函数会

我在
PictureBox
中有一个图像,我还想在
PictureBox
的不同位置绘制一些其他图像

例如,我想在
PictureBox
中的一张图片上绘制几张图片,就像这两颗星(都是带有透明背景的单独图片(PNG)):

我想在不同的位置画多颗不同的星星,下面的图片是一个例子。(美国地图是
图片盒中已经存在的图像

我试图编写一个函数,当提供/给定
PictureBox
x
y
值和图像的位置(例如
My.Resources.RedCity
My.Resources.BlueCity
)的
Point
变量时,该函数会将多个图像绘制到
PictureBox

到目前为止,我已经完成了在
picturebox
上绘制一张图片的工作,但我无法同时在
picturebox
的不同位置绘制多张图片,因为当我使图片无效时,另一张图片会消失

我正在考虑编写一个类似这样的函数,在
PictureBox
paint
事件下添加一个图片/指向某个列表或某物,但我不确定它将如何工作

是否有任何现有的或可以编写的功能能够同时在不同位置将多个图像绘制到
PictureBox

谢谢

我在考虑写一个函数,类似这样的函数来添加 图片/指向某个列表或某物,并在下面显示某个内容 PictureBox的绘画活动,但我不确定它会如何工作

这正是正确的方法。简单示例:

Public Class Form1

    Private dataPoints As New List(Of Tuple(Of Point, Integer))

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        dataPoints.Add(Tuple.Create(New Point(nudX.Value, nudY.Value), If(cbBlue.Checked, 0, 1)))
        PictureBox1.Invalidate()
    End Sub

    Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
        Dim G As Graphics = e.Graphics
        For Each dataPoint In dataPoints
            Dim img As Image = If(dataPoint.Item2 = 0, My.Resources.BlueCity, My.Resources.RedCity)
            G.DrawImage(img, dataPoint.Item1)
        Next
    End Sub

End Class

我会将地图加载到图形环境中,然后在上面绘制

下面是一个如何绘制字符串(可以在地图上旋转)的示例,gr.DrawString结尾的两个零(、、、0、0)将字符串放置在左上角)。FromImage(bmp)是您可以加载美国地图的地方,只需使用地图的文件地址将bmp导入文件路径,或将其添加到资源中即可。我会添加Wingding字体中的彩色星星和圆圈,它们有不同的形状字符,您只需要更改它们的颜色。我提供了字体大小,所以你必须使用它

Dim bmp As New Bitmap(500, 15)
Dim gr As Graphics = Graphics.FromImage(bmp)
gr.SmoothingMode = SmoothingMode.HighQuality
gr.InterpolationMode = InterpolationMode.HighQualityBicubic
gr.PixelOffsetMode = PixelOffsetMode.HighQuality
gr.TextRenderingHint = TextRenderingHint.ClearTypeGridFit
gr.SmoothingMode = SmoothingMode.AntiAlias
Dim mybrush As New SolidBrush(Color.Yellow)
Dim fontbrush As New SolidBrush(Color.Black)
fontbrush.Color = SystemColors.ControlText
mybrush.Color = SystemColors.Control
Dim sfont As New Font("Microsoft Sans Serif", 9, FontStyle.Regular)
Dim strformat As StringFormat = New StringFormat(StringFormatFlags.DirectionVertical)
strformat.Alignment = StringAlignment.Far
Dim strToDraw As String
strToDraw = "Test string"
Dim stringSize As New SizeF()
stringSize = gr.MeasureString(strToDraw, sfont)
gr.FillRectangle(mybrush, CInt(0), CInt(0), stringSize.Width, stringSize.Height)
gr.DrawString(strToDraw, sgenefont, fontbrush, 0, 0)
gr.Dispose

是否有一种方法可以指定如何将特定图像与优先级重叠?例如,如果红星与蓝星在同一位置绘制,则蓝星将保持在顶部?确保可以在列表中进行两次遍历,首先绘制所有红星,然后绘制蓝星,使蓝色位于顶部。