コード例 #1
0
 private void OpenButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (ResultImage.Image == null)
         {
             openFile.Filter = "Image Files(*.PNG)|*.PNG";
             if (openFile.ShowDialog() == DialogResult.OK)
             {
                 sFileName     = openFile.FileName;
                 FileName.Text = sFileName;
                 image         = new Bitmap(openFile.FileName);
                 if (image.Size.Height == 256 && image.Size.Width == 256)
                 {
                     SourceImage.Image = image;
                     SourceImage.Invalidate();
                     FileInfo imageInfo = new FileInfo(sFileName);
                     sourceSizeInKBytes = Convert.ToInt32(imageInfo.Length / 1024);
                 }
                 else
                 {
                     DialogResult rezult = MessageBox.Show("Incorrect image size! Try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
         }
         else
         {
             DialogResult rezult = MessageBox.Show("You can't open image now.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
     catch (Exception exception)
     {
         DialogResult rezult = MessageBox.Show("Error opening image!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }