openFileDialogue位图C# [英] openFileDialogue Bitmaps C#

查看:83
本文介绍了openFileDialogue位图C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我想在C#中进行一些图像处理,并且在对它们应用滤镜之前需要对齐两个图像。我将通过在一个小矩形截面中的固定点扫描图像来尝试这样做,我相信这需要使用Bitmap类。此部分有大量的白色像素,因此我想在此区域中取一个平均像素值来查找y轴的偏移,因为图像上有一个大的白色水平条。两个图像中的x轴相同。我想设置一些具有不同移位值的测试图像,从小到大,正面和负面,所以我可以搜索最小值。这将需要图像上的滚动条以少量移动它们。我是C#的新手,也是低级程序员。我一直试图使用以下代码获取pictureBox1中的图像。



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;
        }
    }
}

}



我离开了Image.FromFile();当我单击表单上的按钮时,我希望选择图像时没有传递任何内容。目前,我只有一个按钮和图片框。



谢谢


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

推荐答案


检查以下代码,

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;
            }
        }



最好的问候

Muthuraja


Best Regards
Muthuraja


尝试:

Try:
Bitmap myImage = (Bitmap)pictureBox1.Image;
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) ;
{
    pictureBox1.Image = Image.FromFile(ofd.FileName);
}


哦!我想我明白了。有效。

所以,我只是没有把任何东西传递到pictureBox。我现在正在传递ofd文件。

非常感谢:)
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 :)


这篇关于openFileDialogue位图C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆