我目前有一个位图
图像。我需要将此图像放置在 PictureBox
内的某个坐标处。具体来说,我希望将其放置在距顶部 5 像素和距左侧 5 像素的位置。位图的长度不同,因此我希望起点始终在该特定点开始绘制位图。
作为示例,这里有两个“位图”,它们都从坐标 5,5 开始,长度不同。想象灰色是 PictureBox
:
private void setQuantity(PictureBox pb, int quantity) {
Graphics g = pb.CreateGraphics();
g.DrawImage(iqc.createQuantityImage(quantity), 0, 0);
g.Dispose();
}
iqc.createQuantityImage() 返回位图
但这似乎并没有画出任何东西。我还更改了 x 和 y,但没有任何变化。
如果可能的话,我希望能够指定 PictureBox
内的确切坐标或点。
感谢您的帮助!
最佳答案
通过向 Paint 方法添加事件处理程序,您可以在 PictureBox 中的任何位置绘制图像,如下所示;
private void PictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(_myBitmap, new Point(5, 5)); //Here new Point(x,y) determines location in pictureBox where you want to draw the bitmap.
}
关于C# 在 PictureBox 中的某个点上绘制位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40168361/