我将尺寸模式更改为正常,并观察到坐标相同但图像尺寸太大,因此部分显示。所以使用缩放尺寸模式属性。
说出尺寸为2825x3538的图像并将图片框尺寸模式保持为正常,图像部分显示在图片框中。所以我改变了图片框模式进行缩放(以适应系统屏幕分辨率)。与缩放模式下的普通模式比较时,坐标未匹配。
我如何实现相同的坐标。
private void openToolStripMenuItem_Click(object sender, EventArgs e) {OpenFD.FileName = ""; OpenFD.Title = "open image"; OpenFD.InitialDirectory = "C"; OpenFD.Filter = "JPEG|*.jpg|Bmp|*.bmp|All Files|*.*.*"; if (OpenFD.ShowDialog() == DialogResult.OK) { file = OpenFD.FileName; image = Image.FromFile(file); pictureBox1.Image = image; svc = Screen.PrimaryScreen; pictureBox1.Width = svc.Bounds.Width; pictureBox1.Height = svc.Bounds.Height-100; mybitmap1 = new Bitmap (pictureBox1.Image); mybitmap1.SetResolution(300, 300); pictureBox1.Image = mybitmap1; } }
private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { if (mybitmap == null) { mybitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height); mybitmap.SetResolution(300, 300); } }
private void pictureBox1_Paint(object sender, PaintEventArgs e) {
using (g = Graphics.FromImage(mybitmap)) { using (Pen pen = new Pen(Color.Green, m)) { e.Graphics.DrawRectangle(pen, r); e.Graphics.DrawString(lab[c].ToString(), new Font(lab[c].ToString(), 8F), new SolidBrush(label1.ForeColor), r); } } }
答案 0 :(得分:0)
您可以在实际图像和图片框之间使用两个比例因子,一个比例高度,另一个比例宽度。