Reputation: 53
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
Upvotes: 1
Views: 83
Reputation: 67898
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);
}
Upvotes: 1