error when click on the thumbnail

Posted by Chaithragm under C# on 8/2/2013 | Points: 10 | Views : 692 | Status : [Member] | Replies : 0
Hi ,im developing a windows application where in which when a thumbnail is click the image has to be opened in the picturebox but im getting error when click on thumbnail
how to resolve this

this is the code to open the images
this.openFileDialog1.Multiselect = true;
this.openFileDialog1.Title = "Select Photos";

DialogResult dr = this.openFileDialog1.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
foreach (String file in openFileDialog1.FileNames)
{
try
{
imageControl = new PictureBox();
imageControl.Click += new EventHandler(Thumbnail_Click);
imageControl.Height = 100;
imageControl.Width = 100;

Image.GetThumbnailImageAbort myCallback =
new Image.GetThumbnailImageAbort(ThumbnailCallback);
Bitmap myBitmap = new Bitmap(file);
Image myThumbnail = myBitmap.GetThumbnailImage(96, 96,
myCallback, IntPtr.Zero);
//imageControl.Image = myThumbnail;
imageControl.Image = myBitmap;
imageControl.SizeMode=PictureBoxSizeMode.StretchImage;
PhotoGallary.Controls.Add(imageControl);
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
//thumbnail click event
private void Thumbnail_Click(object sender, EventArgs e)
{
int height, width;
angle = 0;
tool_type = "open";


PictureBox test = new PictureBox();

PictureBox oPictureBox = (PictureBox)sender;
try
{

test = oPictureBox;

if (test != null)
{

if (test_image != null)
{
test_image.Dispose();

}
test_image = (Bitmap)test.Image;
orginal_height = test_image.Height; // im getting error here as invalid parameter when a thumbnail ic clicked
orginal_width = test_image.Width;
height = test_image.Height;
width = test_image.Width;
pictureBox1.Image = test_image;
pictureBox1.Height = height;
pictureBox1.Width = width;
OriginalImageSize = new Size(test_image.Width, test_image.Height);
pictureBox1.Image = test_image;
}
}
catch (Exception ec)
{
if (test != null)
{
test.Dispose();
}
if (test_image != null)
{
test_image.Dispose();

}
test_image = (Bitmap)test.Image;
orginal_height = test_image.Height;
orginal_width = test_image.Width;
height = test_image.Height;
width = test_image.Width;
pictureBox1.Image = test_image;
pictureBox1.Height = height;
pictureBox1.Width = width;
OriginalImageSize = new Size(test_image.Width, test_image.Height);
pictureBox1.Image = test_image;
}

}




Responses

(No response found.)

Login to post response