gpt4 book ai didi

c# - 在 PictureBox() 中绘制矩形或箭头

转载 作者:太空宇宙 更新时间:2023-11-03 12:54:08 25 4
gpt4 key购买 nike

这项工作正确。如果我从我的系统拍照。

        pictures[idObjekt] = new Bitmap(@"C:\rectangle.png");
picBox[idObjekt] = new PictureBox();
picBox[idObjekt].Location = new System.Drawing.Point(25, 7);
picBox[idObjekt].SizeMode = PictureBoxSizeMode.StretchImage;
picBox[idObjekt].ClientSize = new Size(53, 40);
picBox[idObjekt].Image = pictures[idObjekt];
picBox[idObjekt].MouseDown += pictureBox1_MouseDown;
picBox[idObjekt].MouseMove += pictureBox1_MouseMove;
picBox[idObjekt].PreviewKeyDown += Form1_PreviewKeyDown;
picBox[idObjekt].Tag = idObjekt;
this.Controls.Add(this.picBox[idObjekt]);

但是当我尝试在 PictureBox() 中绘制一些东西时,我只看到空的 PictureBox() 我不知道为什么这不能正常工作。

        pictures[idObjekt] = new Bitmap(1000, 1000, PixelFormat.Format24bppRgb);
picBox[idObjekt] = new PictureBox();
picBox[idObjekt].Location = new System.Drawing.Point(25, 7);
picBox[idObjekt].SizeMode = PictureBoxSizeMode.StretchImage;
picBox[idObjekt].ClientSize = new Size(500, 500);
picBox[idObjekt].MouseDown += pictureBox1_MouseDown;
picBox[idObjekt].MouseMove += pictureBox1_MouseMove;
picBox[idObjekt].PreviewKeyDown += Form1_PreviewKeyDown;
picBox[idObjekt].Tag = idObjekt;
picBox[idObjekt].BackColor = Color.White;
this.Controls.Add(this.picBox[idObjekt]);
Graphics g = Graphics.FromImage(pictures[idObjekt]);

// Rectangle
int heightRec = 100;
int widthRec = 250;
int pozitionX = 10;
int pozitionY = 10;

g.DrawRectangle(Pens.White, pozitionX + 1, pozitionY + 1, widthRec - 3, heightRec - 3);
g.DrawRectangle(Pens.Gray, pozitionX + 2, pozitionY + 2, widthRec - 3, heightRec - 3);
g.DrawRectangle(Pens.Black, pozitionX, pozitionY, widthRec, heightRec);
g.DrawString("The Code Project", new Font("Arial", 12, FontStyle.Italic),
SystemBrushes.WindowText, new PointF(10, 50));

// Arrow
Pen p = new Pen(Color.Red, 7);
p.EndCap = LineCap.ArrowAnchor;

// Arrow
Point point1 = new Point(100, 100);
Point point2 = new Point(100, 100);
g.DrawLine(p, point1, point2);
g.Dispose();
pictures[idObjekt].Dispose();

最佳答案

第二次,您从未将位图分配给 PictureBox。

picBox[idObjekt].Image = pictures[idObjekt];

在你画完之后,为什么调用pictures[idObjekt].Dispose()?如果您需要保留 PictureBox 中的图像,则不应释放该图像。

关于c# - 在 PictureBox() 中绘制矩形或箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34544766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com