1

我正在尝试将图片上传到 winform,然后显示缩略图。我尝试将功能添加到我的 btnUpload_click 方法,但它不允许我将 PaintEventArgs 设置为事件处理程序。所以为了解决这个问题,我创建了另一个方法,但现在需要知道如何调用它。

private void btnUpload_Click(object sender, EventArgs e)
{}

public void getImage(PaintEventArgs ex)
{
    Image.GetThumbnailImageAbort myCallback =
    new Image.GetThumbnailImageAbort(ThumbnailCallback);

    OpenFileDialog open = new OpenFileDialog();
    // image filters
    open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
    if (open.ShowDialog() == DialogResult.OK)
    {
        // display image in picture box
        upload = new Bitmap(open.FileName);

        pictureBox1.Image.GetThumbnailImage(114, 108, myCallback, IntPtr.Zero);
        ex.Graphics.DrawImage(upload, 150, 75);
    }
}

谢谢您的帮助

4

1 回答 1

1

您不需要实例PaintEventArgsGraphics只需更改代码以在按钮单击内工作:

Image.GetThumbnailImageAbort myCallback =
    new Image.GetThumbnailImageAbort(ThumbnailCallback);

OpenFileDialog open = new OpenFileDialog();

// image filters
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
    // display image in picture box
    upload = new Bitmap(open.FileName);

    pictureBox1.Image.GetThumbnailImage(114, 108, myCallback, IntPtr.Zero);
    this.CreateGraphics().DrawImage(upload, 150, 75);
}
于 2013-09-06T17:35:28.223 回答