Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi. I would like to do some image processing in C# and need to align two images before applying a filter to them. I will attempt to do this by scanning the images at a fixed point in a small rectangular section, which I believe makes it necessary to use the Bitmap class. This section has a large amount of white pixels so I would like to take an average pixel value in this area to find the shift in the y-axis, as there is a large white horizontal bar going across the images. The x-axis will be the same in both images. I would like to setup a few test images with different shift values, from small to large, positive and negative, so I can search for the minimum value . This will require a scroll bar on the images to move them in small amounts. I am totally new to C#, and low level programmer. I have been trying to get the image in pictureBox1 with the following code.

C#
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing.Imaging; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms;

namespace imageAlign

{ public partial class Form1 : Form

{
    public Form1()

    {
        InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e)
    {
        Bitmap myImage = (Bitmap)pictureBox1.Image;
        OpenFileDialog ofd = new OpenFileDialog();

        if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) ;
        {
            pictureBox1.Image = Image.FromFile();


           // this.pictureBox1.Image = myImage;
        }
    }
}

}

I have left the Image.FromFile(); with nothing passed as I wish to choose the images when I click the button on the form. Currently, I only have one button and picture box.

Thanks
Posted

Hi,
Check the below code,
C#
private void button1_Click(object sender, EventArgs e)
        {
            Bitmap myImage = (Bitmap)pictureBox1.Image;
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                pictureBox1.Image = Image.FromFile(ofd.FileName);


                // this.pictureBox1.Image = myImage;
            }
        }

Best Regards
Muthuraja
 
Share this answer
 
Try:
C#
Bitmap myImage = (Bitmap)pictureBox1.Image;
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) ;
{
    pictureBox1.Image = Image.FromFile(ofd.FileName);
}
 
Share this answer
 
oh! I think I see. It worked.
So, I just wasn't passing anything into the pictureBox. I am now passing the ofd file.
Thanks a lot :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900