本文整理汇总了C#中System.Image.GetImagePixel方法的典型用法代码示例。如果您正苦于以下问题:C# Image.GetImagePixel方法的具体用法?C# Image.GetImagePixel怎么用?C# Image.GetImagePixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Image
的用法示例。
在下文中一共展示了Image.GetImagePixel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGetIntensity
public bool TryGetIntensity(Image image, double x, double y, out double intesity)
{
if (x > image.ImageWidth - 1 || y > image.ImageHeight - 1 || x < 0 || y < 0)
{
intesity = 0.0;
return false;
}
int x0 = (int)x;
int y0 = (int)y;
Pixel p01 = image.GetImagePixel(x0, y0 + 1);
Pixel p11 = image.GetImagePixel(x0 + 1, y0 + 1);
Pixel p10 = image.GetImagePixel(x0 + 1, y0);
Pixel p00 = image.GetImagePixel(x0, y0);
if (p00 == null || p01 == null || p10 == null || p11 == null)
{
intesity = LinearInterpolate(p00 ?? p01 ?? p10 ?? p11, p11 ?? p10 ?? p01 ?? p00, x, y);
return true;
}
var k1 = (x0 + 1 - x) * (y0 + 1 - y);
var k2 = (x - x0) * (y0 + 1 - y);
var k3 = (x0 + 1 - x) * (y - y0);
var k4 = (x - x0) * (y - y0);
var color = k1 * p00.Intensity + k2 * p10.Intensity + k3 * p01.Intensity + k4 * p11.Intensity;
//var color = ((x0 + 1 - x) * (y0 + 1 - y)) * p00.Intensity + ((x - x0) * (y0 + 1 - y)) * p10.Intensity + ((x0 + 1 - x) * (y - y0)) * p01.Intensity + ((x - x0) * (y - y0)) * p11.Intensity;
intesity = color;
return true;
}
示例2: TryGetIntensity
public bool TryGetIntensity(Image image, double x, double y, out double intesity)
{
if (x > image.ImageWidth - 1 || y > image.ImageHeight - 1 || x < 0 || y < 0)
{
intesity = 0.0;
return false;
}
intesity = image.GetImagePixel((int)Math.Round(x), (int)Math.Round(y)).Intensity;
return true;
}