本文整理汇总了C#中Nikse.SubtitleEdit.Logic.NikseBitmap.Fill方法的典型用法代码示例。如果您正苦于以下问题:C# NikseBitmap.Fill方法的具体用法?C# NikseBitmap.Fill怎么用?C# NikseBitmap.Fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nikse.SubtitleEdit.Logic.NikseBitmap
的用法示例。
在下文中一共展示了NikseBitmap.Fill方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: listBoxFileNames_SelectedIndexChanged
private void listBoxFileNames_SelectedIndexChanged(object sender, EventArgs e)
{
labelNOcrCharInfo.Text = string.Empty;
if (listBoxFileNames.SelectedIndex < 0)
return;
_nocrChar = listBoxFileNames.Items[listBoxFileNames.SelectedIndex] as NOcrChar;
if (_nocrChar == null)
{
pictureBoxCharacter.Invalidate();
groupBoxCurrentCompareImage.Enabled = false;
listBoxLinesForeground.Items.Clear();
listBoxlinesBackground.Items.Clear();
}
else
{
textBoxText.Text = _nocrChar.Text;
checkBoxItalic.Checked = _nocrChar.Italic;
pictureBoxCharacter.Invalidate();
groupBoxCurrentCompareImage.Enabled = true;
labelNOcrCharInfo.Text = string.Format("Size: {0}x{1}, margin top: {2} ", _nocrChar.Width, _nocrChar.Height, _nocrChar.MarginTop);
if (pictureBoxCharacter.Image != null)
{
if (IsMatch())
{
groupBoxCurrentCompareImage.BackColor = Color.LightGreen;
}
else
{
groupBoxCurrentCompareImage.BackColor = Control.DefaultBackColor;
}
}
_drawLineOn = false;
_history = new List<NOcrChar>();
_historyIndex = -1;
if (_bitmap == null)
{
var bitmap = new Bitmap(_nocrChar.Width, _nocrChar.Height);
var nbmp = new NikseBitmap(bitmap);
nbmp.Fill(Color.White);
pictureBoxCharacter.Image = nbmp.GetBitmap();
SizePictureBox();
ShowOcrPoints();
bitmap.Dispose();
}
}
}
示例2: GenerateImageFromTextWithStyleInner
private static Bitmap GenerateImageFromTextWithStyleInner(MakeBitmapParameter parameter)
{
string text = parameter.P.Text;
text = RemoveSubStationAlphaFormatting(text);
text = text.Replace("<I>", "<i>");
text = text.Replace("</I>", "</i>");
text = Utilities.FixInvalidItalicTags(text);
text = text.Replace("<B>", "<b>");
text = text.Replace("</B>", "</b>");
// no support for underline
text = text.Replace("<u>", string.Empty);
text = text.Replace("</u>", string.Empty);
text = text.Replace("<U>", string.Empty);
text = text.Replace("</U>", string.Empty);
var bmp = new Bitmap(1, 1);
var g = Graphics.FromImage(bmp);
var fontSize = g.DpiY * parameter.SubtitleFontSize / 72;
Font font = SetFont(parameter, parameter.SubtitleFontSize);
var lineHeight = parameter.LineHeight; // (textSize.Height * 0.64f);
var textSize = g.MeasureString(Utilities.RemoveHtmlTags(text), font);
g.Dispose();
bmp.Dispose();
int sizeX = (int)(textSize.Width * 1.8) + 150;
int sizeY = (int)(textSize.Height * 0.9) + 50;
if (sizeX < 1)
sizeX = 1;
if (sizeY < 1)
sizeY = 1;
bmp = new Bitmap(sizeX, sizeY);
if (parameter.BackgroundColor != Color.Transparent)
{
NikseBitmap nbmpTemp = new NikseBitmap(bmp);
nbmpTemp.Fill(parameter.BackgroundColor);
var temp = nbmpTemp.GetBitmap();
bmp.Dispose();
bmp = temp;
// g.FillRectangle(new SolidBrush(parameter.BackgroundColor), 0, 0, bmp.Width, bmp.Height);
}
g = Graphics.FromImage(bmp);
// align lines with gjpqy, a bit lower
var lines = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
int baseLinePadding = 13;
if (parameter.SubtitleFontSize < 30)
baseLinePadding = 12;
if (parameter.SubtitleFontSize < 25)
baseLinePadding = 9;
if (lines.Length > 0)
{
if (lines[lines.Length - 1].Contains("g") || lines[lines.Length - 1].Contains("j") || lines[lines.Length - 1].Contains("p") || lines[lines.Length - 1].Contains("q") || lines[lines.Length - 1].Contains("y") || lines[lines.Length - 1].Contains(","))
{
string textNoBelow = lines[lines.Length - 1].Replace("g", "a").Replace("j", "a").Replace("p", "a").Replace("q", "a").Replace("y", "a").Replace(",", "a");
baseLinePadding -= (int)Math.Round((TextDraw.MeasureTextHeight(font, lines[lines.Length - 1], parameter.SubtitleFontBold) - TextDraw.MeasureTextHeight(font, textNoBelow, parameter.SubtitleFontBold)));
}
else
{
baseLinePadding += 1;
}
if (baseLinePadding < 0)
baseLinePadding = 0;
}
//TODO: Better baseline - test http://bobpowell.net/formattingtext.aspx
//float baselineOffset=font.SizeInPoints/font.FontFamily.GetEmHeight(font.Style)*font.FontFamily.GetCellAscent(font.Style);
//float baselineOffsetPixels = g.DpiY/72f*baselineOffset;
//baseLinePadding = (int)Math.Round(baselineOffsetPixels);
var lefts = new List<float>();
if (text.ToLower().Contains("<font") || text.ToLower().Contains("<i>"))
{
foreach (string line in text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
string lineNoHtml = Utilities.RemoveHtmlFontTag(line.Replace("<i>", string.Empty).Replace("</i>", string.Empty));
if (parameter.AlignLeft)
lefts.Add(5);
else if (parameter.AlignRight)
lefts.Add(bmp.Width - CalcWidthViaDraw(lineNoHtml, parameter) - 15); // calculate via drawing+crop
else
lefts.Add((bmp.Width - CalcWidthViaDraw(lineNoHtml, parameter) + 5) / 2); // calculate via drawing+crop
}
}
else
{
foreach (string line in Utilities.RemoveHtmlFontTag(text.Replace("<i>", string.Empty).Replace("</i>", string.Empty)).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
if (parameter.AlignLeft)
lefts.Add(5);
else if (parameter.AlignRight)
lefts.Add(bmp.Width - (TextDraw.MeasureTextWidth(font, line, parameter.SubtitleFontBold) + 15));
else
lefts.Add((bmp.Width - TextDraw.MeasureTextWidth(font, line, parameter.SubtitleFontBold) + 15) / 2);
}
//.........这里部分代码省略.........