Click here to Skip to main content
12,946,816 members (52,499 online)
Rate this:
 
Please Sign up or sign in to vote.
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.

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 2-Feb-13 21:48pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi,
Check the below code,
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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try:
Bitmap myImage = (Bitmap)pictureBox1.Image;
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) ;
{
    pictureBox1.Image = Image.FromFile(ofd.FileName);
}
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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 :)
  Permalink  

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,919
CHill60 3,235
Maciej Los 2,508
Jochen Arndt 1,935
ppolymorphe 1,795


Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 3 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100