本文整理汇总了C#中Canvas.SetSymbol方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.SetSymbol方法的具体用法?C# Canvas.SetSymbol怎么用?C# Canvas.SetSymbol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Canvas
的用法示例。
在下文中一共展示了Canvas.SetSymbol方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Canvas_SetSymbolException3
public void Test_Canvas_SetSymbolException3()
{
Canvas canvas = new Canvas(4, 4);
canvas.SetSymbol('#', -1, 0, 4, Color.Black);
}
示例2: Decorate
public void Decorate(Canvas embroidery, Canvas pattern, Settings settings)
{
log.Source = "EmbroiderySource";
int squareWidth = embroidery.Width / settings.CellsCount;
if (embroidery.Height < pattern.Height * squareWidth)
throw new WrongResolutionException("Resolution.Height has to be higher");
try
{
settings.CreateColorSymbolRelation();
}
catch (WrongSymbolsRealisationException e)
{
throw new WrongSymbolsRealisationException(e.Message);
}
catch (NullReferenceException e)
{
throw new NullReferenceException(e.Message);
}
Color symbolColor;
if(settings.SymbolColor == Color.Empty) symbolColor = Color.Black;
else symbolColor = settings.SymbolColor;
Parallel.ForEach(Partitioner.Create(0, pattern.Height), rangeHeight =>
{
for (int patternY = rangeHeight.Item1; patternY < rangeHeight.Item2; patternY++)
{
Parallel.ForEach(Partitioner.Create(0, pattern.Width), rangeWidth =>
{
for (int patternX = rangeWidth.Item1; patternX < rangeWidth.Item2; patternX++)
{
int startX = patternX * squareWidth;
int startY = patternY * squareWidth;
char symbol = GetSymbol(pattern.GetColor(patternX, patternY), settings);
embroidery.SetSymbol(symbol, startX, startY, squareWidth, symbolColor);
}
});
}
});
#region Just Parallel.For
/*
Parallel.For(0, pattern.Height, patternY =>
{
Parallel.For(0, pattern.Width, patternX =>
{
int startX = patternX * squareWidth;
int startY = patternY * squareWidth;
char symbol = GetSymbol(pattern.GetColor(patternX, patternY), settings);
embroidery.SetSymbol(symbol, startX, startY, squareWidth, symbolColor);
});
});
*/
#endregion
#region Obsolete
/*for(int squareY = 0, patternY = 0; squareY <= embroidery.Height - squareWidth; squareY += squareWidth, patternY++)
for (int squareX = 0, patternX = 0; squareX <= embroidery.Width - squareWidth; squareX += squareWidth, patternX++)
{
char symbol = GetSymbol(pattern.GetColor(patternX, patternY), settings);
embroidery.SetSymbol(symbol, squareX, squareY, squareWidth, symbolColor);
}*/
#endregion
}
示例3: Test_Canvas_SetSymbol
public void Test_Canvas_SetSymbol()
{
Bitmap temp = new Bitmap(4, 4);
Graphics g = Graphics.FromImage(temp);
Font font = new Font("Arial", 4 - 1, GraphicsUnit.Pixel);
string sym = "#";
sym = sym.PadLeft(1, '#');
SolidBrush brush = new SolidBrush(Color.Black);
g.DrawString(sym, font, brush, new PointF(0f, 0f));
CanvasConverter converter = new CanvasConverter();
Canvas expectedCanvas = converter.ConvertBitmapToCanvas(temp);
Canvas canvas = new Canvas(4, 4);
canvas.SetSymbol('#', 0, 0, 4, Color.Black);
Assert.IsTrue(canvas.Width == expectedCanvas.Width && canvas.Height == expectedCanvas.Height);
for (int y = 0; y < canvas.Height; y++)
for (int x = 0; x < canvas.Width; x++)
{
Color actualColor = canvas.GetColor(x, y);
Color expectedColor = expectedCanvas.GetColor(x, y);
Assert.IsTrue(actualColor == expectedColor);
}
}