如何在位图图像中显示像素值 [英] How Can I Show Pixel Value In A Bitmap Image
本文介绍了如何在位图图像中显示像素值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好..我是C#的初学者,我只是想问一下在位图图片中显示每个像素的像素值
我是使用下面的代码打开位图图片:
Hello .. i'm beginner in C# and i just want to ask about to show the pixel value for each pixel in a bitmap picture
I've used the code below to open a bitmap picture:
private void pictureBox1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Open Image";
dlg.Filter = "bmp files (*.bmp)|*.bmp";
if (dlg.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = Image.FromFile(dlg.FileName);
}
dlg.Dispose();
}
我如何修改它以显示标签中的像素值?
How can i modify it to show the pixel value in a label ?
推荐答案
通过显示像素值不确定你的意思,但要获得给定坐标的像素值,你可以使用 Bitmap.GetPixel [ ^ ]
Not sure what you mean by showing the pixel value, but to get the pixel value for a given coordinate you can use Bitmap.GetPixel[^]
假设:
0.你有WinForm,'FrmViewColors
1.你在表格上有一个PictureBox '图片属性设置',pbxViewColors
2.你在表格上有一个标签,'lblColor
3.为PictureBox的MouseMove事件创建一个EventHandler
Assume:
0. you have WinForm, 'FrmViewColors
1. you have a PictureBox on a Form with its 'Image property set, 'pbxViewColors
2. you have a Label on the Form, 'lblColor
3. you create an EventHandler for the MouseMove Event of the PictureBox
private Bitmap bmp;
private void FrmViewColors_Load(object sender, EventArgs e)
{
// get the Bitmap from the PictureBox Image
bmp = // left for you to figure out
}
// EventHandler
private void pbxViewColors_MouseMove(object sender, MouseEventArgs e)
{
Color clr = bmp.GetPixel(e.X, e.Y);
lblColor.Text = // left for you to figure out
}
这篇关于如何在位图图像中显示像素值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文