本文整理汇总了C#中Microsoft.SPOT.Bitmap.GetPixel方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.GetPixel方法的具体用法?C# Bitmap.GetPixel怎么用?C# Bitmap.GetPixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.SPOT.Bitmap
的用法示例。
在下文中一共展示了Bitmap.GetPixel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChangeBitmapColor
public static void ChangeBitmapColor(Bitmap img, Color anyDifferentColor, Color changeTo)
{
for (int x = 0; x < img.Width; x++)
for (int y = 0; y < img.Height; y++)
if (img.GetPixel(x, y) != anyDifferentColor)
img.SetPixel(x, y, changeTo);
}
示例2: FillArea
/// <summary>
/// This method fills an area which surrounded by line(s). Not only polygon but also circle, pentagram, cloud shaped... any figure. Only you need to fill is set Bitmap, Color, certain X and Y to argument. Both X and Y should be exist inner line(s).
/// </summary>
/// <param name="screen"></param>
/// <param name="color"></param>
public void FillArea(Bitmap screen, Color color, Point point)
{
int currentY = 0;
int minY = 0;
int maxY = 0;
//screen.SetPixel(x, y, color);
currentY = point.Y - 1;
while (currentY >= 0 && screen.GetPixel(point.X, currentY) != color)
{
screen.SetPixel(point.X, currentY, color);
currentY--;
}
minY = currentY + 1;
currentY = point.Y;
while (currentY < screen.Height && screen.GetPixel(point.X, currentY) != color)
{
screen.SetPixel(point.X, currentY, color);
currentY++;
}
maxY = currentY - 1;
for (int i = minY; i < maxY; i++)
{
if (point.X > 0 && screen.GetPixel(point.X - 1, i) != color)
{
FillArea(screen, color, new Point(point.X - 1, i));
}
if (point.X < screen.Width - 1 && screen.GetPixel(point.X + 1, i) != color)
{
FillArea(screen, color, new Point(point.X + 1, i));
}
}
}
示例3: DrawPoly
/// <summary>
/// Draws polygon from list of points and fill it with specififed pattern.
/// </summary>
/// <param name="screen">Bitmap to draw on</param>
/// <param name="points">Array of points defining polygon</param>
/// <param name="borderColor">Color of poly border</param>
/// <param name="borderWidth">Poly border width</param>
/// <param name="fillColor">Color to use to fill poly</param>
/// <param name="polyFill">Fill patern. Empty will simply draw unfilled poly</param>
public void DrawPoly(Bitmap screen, Point[] points, Color borderColor, short borderWidth, Color fillColor, PolyFill polyFill)
{
if (points.Length < 3) return; // we need at least 3 point for poly
if (borderWidth < 1)
borderWidth = 1;
Color fgColor, bgColor;
if (fillColor == Color.Black)
{
fgColor = Color.Black;
bgColor = Color.White;
}
else
{
fgColor = Color.White;
bgColor = Color.Black;
}
if (polyFill == PolyFill.POLYFILL_EMPTY)
_DrawUnfilledPoly(screen, points, borderColor, borderWidth, new Point(0, 0));
else
{
Point br = new Point(0, 0), tl = new Point(screen.Width, screen.Height);
// find bounding box
for (int i = 0; i < points.Length; ++i)
{
tl.X = (tl.X > points[i].X) ? points[i].X : tl.X;
tl.Y = (tl.Y > points[i].Y) ? points[i].Y : tl.Y;
br.X = (br.X < points[i].X) ? points[i].X : br.X;
br.Y = (br.Y < points[i].Y) ? points[i].Y : br.X;
}
// adjust binding box to fit thick border. Foê some reason SPOT.Bitmap double the border width (at least on emulator)
if (borderWidth > 1)
{
tl.X = (short)((tl.X > borderWidth) ? tl.X - borderWidth * 2 : 0);
tl.Y = (short)((tl.Y > borderWidth) ? tl.Y - borderWidth * 2 : 0);
br.X = (short)((br.X + borderWidth < (screen.Width - 1)) ? br.X + borderWidth * 1.5 : 0);
br.Y = (short)((br.Y + borderWidth < (screen.Width - 1)) ? br.Y + borderWidth * 1.5 : 0);
}
// we need separate bitmap to draw poly as one specififed can have some drawing already and we won't be able to detect border properly
Bitmap buffer = new Bitmap((br.X - tl.X + 1), (br.Y - tl.Y + 1));
// fill bitmap with color opposite to border color
if (borderColor == Color.Black)
buffer.DrawRectangle(Color.White, 0, 0, 0, buffer.Width, buffer.Height, 0, 0, Color.White, 0, 0, Color.White, buffer.Width, buffer.Height, 0xFF);
else
buffer.DrawRectangle(Color.Black, 0, 0, 0, buffer.Width, buffer.Height, 0, 0, Color.Black, 0, 0, Color.Black, buffer.Width, buffer.Height, 0xFF);
_DrawUnfilledPoly(buffer, points, borderColor, borderWidth, tl);
// scan created bitmap
bool isInside = false, onBorder = false;
int startX = -1, borderStart = -1;
for (int y = 0; y < buffer.Height; ++y)
{
isInside = false;
onBorder = false;
startX = -1;
borderStart = -1;
for (int x = 0; x < buffer.Width; ++x)
{
if (buffer.GetPixel(x, y) == borderColor)
{
if (onBorder)
{
// still on border
screen.SetPixel(x + tl.X, y + tl.Y, borderColor);
}
else
{
// we have reached border from inside/outside
if (isInside)
{
//isInside = false;
if (startX >= 0)
{
// draw pattern line
for (int k = startX; k < x; ++k)
{
if (polyFill == PolyFill.POLYFILL_SOLID) screen.SetPixel(k + tl.X, y + tl.Y, fgColor);
else if (polyFill == PolyFill.POLYFILL_HORIZONTAL)
screen.SetPixel(k + tl.X, y + tl.Y, (polyfill_horizontal[k % 3 + 3 * (y % 3)] == 0xFF) ? fgColor : bgColor);
else if (polyFill == PolyFill.POLYFILL_HORIZONTAL)
screen.SetPixel(k + tl.X, y + tl.Y, (polyfill_horizontal[k % 3 + 3 * (y % 3)] == 0xFF) ? fgColor : bgColor);
else if (polyFill == PolyFill.POLYFILL_VERTICAL)
screen.SetPixel(k + tl.X, y + tl.Y, (polyfill_vertical[k % 3 + 3 * (y % 3)] == 0xFF) ? fgColor : bgColor);
//.........这里部分代码省略.........
示例4: ImageBrushTest
private MFTestResults ImageBrushTest(Bitmap bmp)
{
MFTestResults tResult = MFTestResults.Pass;
int x, y, w = bmp.Width, h = bmp.Height;
Log.Comment("Drawing Rectangle with Bitmap's w = " + w.ToString() + " and h = " + h.ToString());
Log.Comment("filling the Rectangle with ImageBrush ");
Master_Media._panel.Dispatcher.Invoke(new TimeSpan(0, 0, 5),
new DispatcherOperationCallback(DrawRectangle), new Point(bmp.Width, bmp.Height));
autoEvent.WaitOne();
Log.Comment("Getting a random pixel colors on the image and verifying");
Random random = new Random();
for (int i = 0; i < 10; i++)
{
x = random.Next(w - 2) + 1;
y = random.Next(h - 2) + 1;
Color c = bmp.GetPixel(x, y);
int x1 = x, y1 = y;
_rectangle.PointToScreen(ref x1, ref y1);
if (VerifyingPixelColor(new Point[] { new Point(x1, y1) }, c) != MFTestResults.Pass)
{
tResult = MFTestResults.Fail;
break;
}
}
return tResult;
}
示例5: FillColor
ArrayList FillColor(Bitmap bitmap)
{
int i, j;
ArrayList temp = new ArrayList();
int posX = 0, posY = 0;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
var pixel = bitmap.GetPixel(posX, posY);
Color color = ColorUtility.ColorFromRGB(ColorUtility.GetRValue(pixel),
ColorUtility.GetGValue(pixel), ColorUtility.GetBValue(pixel));
temp.Add(color);
posX += 159;
}
posY = +119;
posX = 0;
}
return temp;
}