计算图像中的总像素 [英] calculate total pixels in an image
本文介绍了计算图像中的总像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我如何使用c#
can somebody tell me how to calculate total number of pixels in an image using c#
推荐答案
位图中的像素总数是和 PixelWidth
属性.有关详细信息,请参见位图和像素位 [
The total amount of pixels in a bitmap is the product ofPixelHeight
andPixelWidth
properties. More about this is explained at Bitmaps And Pixel Bits[^].
尝试一下
仅与.Net FW 4兼容.确保您拥有
Try this
Only compatible with .Net FW 4 . Insure that you have that
Bitmap image1;
private void Button1_Click(System.Object sender, System.EventArgs e)
{
try
{
// Retrieve the image.
image1 = new Bitmap(@"C:\Documents and Settings\All Users\"
+ @"Documents\My Music\music.bmp", true);
int x, y;
// Loop through the images pixels to reset color.
for(x=0; x<image1.width;> {
for(y=0; y<image1.height;> {
Color pixelColor = image1.GetPixel(x, y);
Color newColor = Color.FromArgb(pixelColor.R, 0, 0);
image1.SetPixel(x, y, newColor);
}
}
// Set the PictureBox to display the image.
PictureBox1.Image = image1;
// Display the pixel format in Label1.
Label1.Text = "Pixel format: "+image1.PixelFormat.ToString();
}
catch(ArgumentException)
{
MessageBox.Show("There was an error." +
"Check the path to the image file.");
}
}
亲爱的朋友,
请点击以下链接:-
c-sharp-如何从特定颜色的图像中找到像素数 [ ^ ]
希望对您有所帮助.
谢谢
Dear Friend,
Please follow this link:-
c-sharp-how-to-find-number-of-pixels-from-specific-color-in-a-image[^]
I hope this will help you out.
Thanks
这篇关于计算图像中的总像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文