I am trying to upload a picture to a winform and then show a thumbnail. I tried adding the functionality to my btnUpload_click method but it would not allow me to set PaintEventArgs as an eventhandler. So to remedy this, I created another method but now need to know how to call it.
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);
}
}
Thank you for your assistance
You don't need PaintEventArgs
for a Graphics
instance. Just change the code to work inside the button click:
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.