本文整理汇总了C#中System.Windows.Forms.TextBox.DrawToBitmap方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.DrawToBitmap方法的具体用法?C# TextBox.DrawToBitmap怎么用?C# TextBox.DrawToBitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.TextBox
的用法示例。
在下文中一共展示了TextBox.DrawToBitmap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: createLongTwitImage
public static Image createLongTwitImage(TextBox tbWeibo)
{
//获取图片长度
Graphics g = Graphics.FromHwnd(tbWeibo.Handle);
int tmptbHeight;
try
{
tmptbHeight = (int)g.MeasureString(tbWeibo.Text + "\r\n\r\n\t\t\tBy #SinaWeiboClient#", tbWeibo.Font, 440).Height;
}
catch
{
return null;
}
finally
{
g.Dispose();
}
//生成文本框
TextBox tmptb = new TextBox();
tmptb.Multiline = true;
tmptb.Width = 440;
tmptb.Height = tmptbHeight;
tmptb.Text = tbWeibo.Text + "\r\n\r\n\t\t\tBy #SinaWeiboClient#";
tmptb.BackColor = Color.White;
tmptb.BorderStyle = BorderStyle.None;
//转化为图片
Bitmap bmp = new Bitmap(tmptb.Width, tmptb.Height);
Rectangle rect = new Rectangle(new Point(0, 0), tmptb.Size);
tmptb.DrawToBitmap(bmp, rect);
tmptb.Dispose();
//MeasureString方法不甚精准,消除底部空白
int lines = 0, pixels = 0, white = Color.White.ToArgb();
for (int i = bmp.Height; i > 0; i--, pixels = 0)
{
for (int j = 0; j < bmp.Width; j++)
{
if (bmp.GetPixel(j, i).ToArgb() == white)
pixels++;
else
pixels = 0;
}
if (pixels == bmp.Width)
lines++;
else
break;
}
return lines > 0 ? bmp.Clone(new Rectangle(0, 0, bmp.Width, bmp.Height - lines), System.Drawing.Imaging.PixelFormat.Format24bppRgb) : bmp;
}
示例2: TAC_TurnTextBoxToPix
//返回转换的点阵数据
private static byte[][] TAC_TurnTextBoxToPix(TextBox tbFont)
{
int nWidth = tbFont.Width;
int nHeight = tbFont.Height;
Bitmap bmpTbFont = new Bitmap(nWidth, nHeight);
Rectangle rctTbFont = new Rectangle(0, 0, nWidth, nHeight);
tbFont.DrawToBitmap(bmpTbFont, rctTbFont);
byte[][] tempDesData = new byte[nHeight][];
Color coTemp = Color.Empty;
for (int i = 0; i < nHeight; i++)
{
tempDesData[i] = new byte[nWidth];
for (int j = 0; j < nWidth; j++)
{
Color coRealPixel = Color.FromArgb(bmpTbFont.GetPixel(j, i).ToArgb() ^ 0xffffff);
tempDesData[i][j] = TAC_IsBlack(coRealPixel, 1);
}
}
return tempDesData;
}