本文整理汇总了C#中UIKit.UIImage.GetPixelColour方法的典型用法代码示例。如果您正苦于以下问题:C# UIImage.GetPixelColour方法的具体用法?C# UIImage.GetPixelColour怎么用?C# UIImage.GetPixelColour使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIKit.UIImage
的用法示例。
在下文中一共展示了UIImage.GetPixelColour方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOilPaintingColours
private CGColor[,] GetOilPaintingColours(UIImage image)
{
var width = image.CGImage.Width;
var height = image.CGImage.Height;
var oilColours = new CGColor[width, height];
var radius = 2;
var intensity = 15;
var intensityCount = new long[256];
var sumR = new float[256];
var sumG = new float[256];
var sumB = new float[256];
for( int pixelY = 0; pixelY < height; pixelY++)
{
for( int pixelX = 0; pixelX < width; pixelX++)
{
// Find intensities of nearest nRadius pixels in four direction.
for( int borderPixelY = pixelY - radius; borderPixelY <= pixelY + radius; borderPixelY++ )
{
for( int borderPixelX = pixelX - radius; borderPixelX <= pixelX + radius; borderPixelX++ )
{
if(borderPixelX < 0 || borderPixelY < 0 || borderPixelX >= width || borderPixelY >= height)
{
continue;
}
var pixelColour = image.GetPixelColour(new CGPoint(borderPixelX, borderPixelY));
int currentPixelRed = (int)Math.Round(pixelColour.Components[0] * 255);
int currentPixelGreen = (int)Math.Round(pixelColour.Components[1] * 255);
int currentPixelBlue = (int)Math.Round(pixelColour.Components[2] * 255);
// Find intensity of RGB value and apply intensity level.
int currentIntensity = (int)( ( (float)( currentPixelRed + currentPixelGreen + currentPixelBlue ) / 3.0 ) * intensity ) / 255;
if( currentIntensity > 255 )
currentIntensity = 255;
int i = currentIntensity;
intensityCount[i]++;
sumR[i] = sumR[i] + currentPixelRed;
sumG[i] = sumG[i] + currentPixelGreen;
sumB[i] = sumB[i] + currentPixelBlue;
}
}
nfloat currentMax = 0;
int maxIndex = 0;
for( var index = 0; index < 256; index++ )
{
if( intensityCount[index] > currentMax )
{
currentMax = intensityCount[index];
maxIndex = index;
}
}
oilColours[pixelX, pixelY] = new CGColor((sumR[maxIndex] / currentMax) / 255f, (sumG[maxIndex] / currentMax) / 255f, (sumB[maxIndex] / currentMax) / 255f, 1);
Array.Clear(intensityCount, 0, intensityCount.Length);
Array.Clear(sumR, 0, sumR.Length);
Array.Clear(sumG, 0, sumG.Length);
Array.Clear(sumB, 0, sumB.Length);
}
}
return oilColours;
}