本文整理汇总了C#中FastBitmap.GetColor方法的典型用法代码示例。如果您正苦于以下问题:C# FastBitmap.GetColor方法的具体用法?C# FastBitmap.GetColor怎么用?C# FastBitmap.GetColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FastBitmap
的用法示例。
在下文中一共展示了FastBitmap.GetColor方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Colorize
/// <summary>Implements a b&w + hue-based transformation for an image.</summary>
/// <param name="original">The original image.</param>
/// <param name="selectedPixels">The location in the original image of the selected pixels for hue
/// comparison.</param>
/// <param name="epsilon">Allowed hue variation from selected pixels.</param>
/// <param name="paths">GraphicPath instances demarcating regions containing possible pixels to be
/// left in color.</param>
/// <param name="parallel">Whether to run in parallel.</param>
/// <returns>The new Bitmap.</returns>
public Bitmap Colorize(Bitmap original, List<Point> selectedPixels, int epsilon, List<GraphicsPath> paths, bool parallel)
{
// Create a new bitmap with the same size as the original
int width = original.Width, height = original.Height;
Bitmap colorizedImage = new Bitmap(width, height);
// Optimization: For every GraphicsPath, get a bounding rectangle. This allows for quickly
// ruling out pixels that are definitely not containing within the selected region.
Rectangle [] pathsBounds = null;
if (paths != null && paths.Count > 0)
{
pathsBounds = new Rectangle[paths.Count];
for(int i=0; i<pathsBounds.Length; i++)
{
pathsBounds[i] = Rectangle.Ceiling(paths[i].GetBounds());
}
}
// Optimization: Hit-testing against GraphicPaths is relatively slow. Hit testing
// against rectangles is very fast. As such, appromixate the area of the GraphicsPath
// with rectangles which can be hit tested against instead of the paths. Not quite
// as accurate, but much faster.
List<RectangleF[]> compositions = null;
if (paths != null && paths.Count > 0)
{
compositions = new List<RectangleF[]>(paths.Count);
using (Matrix m = new Matrix())
{
for(int i=0; i<paths.Count; i++)
{
using (Region r = new Region(paths[i])) compositions.Add(r.GetRegionScans(m));
}
}
}
// Use FastBitmap instances to provide unsafe/faster access to the pixels
// in the original and in the new images
using (FastBitmap fastColorizedImage = new FastBitmap(colorizedImage))
using (FastBitmap fastOriginalImage = new FastBitmap(original))
{
// Extract the selected hues from the selected pixels
List<float> selectedHues = new List<float>(selectedPixels.Count);
foreach (Point p in selectedPixels)
{
selectedHues.Add(fastOriginalImage.GetColor(p.X, p.Y).GetHue());
}
// For progress update purposes, figure out how many pixels there
// are in total, and how many constitute 1% so that we can raise
// events after every additional 1% has been completed.
long totalPixels = height * width;
long pixelsPerProgressUpdate = totalPixels / 100;
if (pixelsPerProgressUpdate == 0) pixelsPerProgressUpdate = 1;
long pixelsProcessed = 0;
// Pixels close to the selected hue but not close enough may be
// left partially desaturated. The saturation window determines
// what pixels fall into that range.
const int maxSaturationWindow = 10;
int saturationWindow = Math.Min(maxSaturationWindow, epsilon);
// Separated out the body of the loop just to make it easier
// to switch between sequential and parallel for demo purposes
Action<int> processRow = y =>
{
for (int x = 0; x < width; x++)
{
// Get the color/hue of th epixel
Color c = fastOriginalImage.GetColor(x, y);
float pixelHue = c.GetHue();
// Use hit-testing to determine if the pixel is in the selected region.
bool pixelInSelectedRegion = false;
// First, if there are no paths, by definition it is in the selected
// region, since the whole image is then selected
if (paths == null || paths.Count == 0) pixelInSelectedRegion = true;
else
{
// For each path, first see if the pixel is within the bounding
// rectangle; if it's not, it's not in the selected region.
Point p = new Point(x, y);
for (int i = 0; i < pathsBounds.Length && !pixelInSelectedRegion; i++)
{
if (pathsBounds[i].Contains(p))
{
// The pixel is within a bounding rectangle, so now
// see if it's within the composition rectangles
// approximating the region.
foreach (RectangleF bound in compositions[i])
{
//.........这里部分代码省略.........
示例2: MeasureError
double MeasureError(Rectangle blockRect, FastBitmap block)
{
double error = 0;
for (int y = 0; y < blockRect.Height; y++)
{
for (int x = 0; x < blockRect.Width; x++)
{
Color m = _main.GetColor(blockRect.X + x, blockRect.Y + y);
Color b = block.GetColor(x, y);
double dist = Math.Sqrt(
(m.R - b.R) * (m.R - b.R) +
(m.G - b.G) * (m.G - b.G) +
(m.B - b.B) * (m.B - b.B));
error += dist;
}
}
return error;
}
示例3: IsIn
/// <summary>
/// Matches until difference is more than total tolerance.
/// </summary>
/// <param name="fast_bitmap"></param>
/// <param name="sub_rect"></param>
/// <returns></returns>
public bool IsIn(FastBitmap fast_bitmap, Point basepoint, int tolerance)
{
int total = 0;
for (int y = 0; y < this.Height; y++)
{
for (int x = 0; x < this.Width; x++)
{
total += BitmapAnalyzer.AbsoluteDiff(this.GetColor(x, y), fast_bitmap.GetColor(basepoint.X + x, basepoint.Y + y));
if (total > tolerance)
return false;
}
}
return true;
}
示例4: IsMatch
public bool IsMatch(FastBitmap bitmap, int tolerance)
{
Color c1 = bitmap.GetColor(X, Y);
Color c2 = this.ToColor();
if (Math.Abs(c1.R - c2.R) > tolerance || Math.Abs(c1.G - c2.G) > tolerance || Math.Abs(c1.B - c2.B) > tolerance)
return false;
return true;
}
示例5: IsMatch
public static bool IsMatch(FastBitmap fast_bitmap1, FastBitmap fast_bitmap2, int total_tolerance)
{
if (fast_bitmap1.Width != fast_bitmap2.Width || fast_bitmap1.Height != fast_bitmap2.Height)
return false;
int total = 0;
for (int y = 0; y < fast_bitmap1.Height; y++)
{
for (int x = 0; x < fast_bitmap1.Width; x++)
{
total += BitmapAnalyzer.AbsoluteDiff(fast_bitmap1.GetColor(x, y), fast_bitmap2.GetColor(x, y));
if (total > total_tolerance)
return false;
}
}
return true;
}