0

嘿,我正在尝试将 4 个框添加到 1280 x 720 的图像中。

我想将这些框添加到图像的顶部,但将它们均匀地分布在 1280 宽度上。

Dim g As Graphics = Graphics.FromImage(image)

g.FillRectangle(New SolidBrush(Color.FromArgb(90, 255, 255, 255)), New Rectangle(3, 7, 270, 25)) 'The transparent square for Date
g.DrawString(Format(DateTime.Now, "MM/dd/yyyy HH:mm:ss tt"), New Font("Arial", 18), Brushes.Black, New PointF(3, 5)) 'The date

g.FillRectangle(New SolidBrush(Color.FromArgb(90, 255, 255, 255)), New Rectangle(350, 7, 170, 25)) 'The transparent square for Latitude
g.DrawString("Lat: " & "30.976154", New Font("Arial", 18), Brushes.Black, New PointF(352, 5))

g.FillRectangle(New SolidBrush(Color.FromArgb(90, 255, 255, 255)), New Rectangle(670, 7, 180, 25)) 'The transparent square for longitude
g.DrawString("Lng: " & "33.351328", New Font("Arial", 18), Brushes.Black, New PointF(672, 5))

g.FillRectangle(New SolidBrush(Color.FromArgb(90, 255, 255, 255)), New Rectangle(970, 7, 120, 25)) 'The transparent square for MPH
g.DrawString("MPH: " & "000", New Font("Arial", 18), Brushes.Black, New PointF(972, 5))

g.Dispose()

但是,由于每个矩形/文本的宽度与其周围的宽度不同,我还没有找到一种可靠的方法来使它们均匀地穿过屏幕。

任何想法,想法都会很棒!

4

1 回答 1

0

只需将宽度除以标签数量即可。这是一些伪代码:

const int NUM_LABELS = 4; 
int divWidth = width / NUM_LABELS;
int i;
for i = 0 to (NUM_LABELS - 1)
    FillRect(i * divWidth, LABEL_HEIGHT, (i + 1) * divWidth, 0); // or whatever you want to do
    MoveTo (i * divWidth, LABEL_HEIGHT);
    DrawString("some string");
于 2013-08-17T18:19:48.733 回答