本文整理汇总了C#中System.Windows.Forms.Form.DrawToBitmap方法的典型用法代码示例。如果您正苦于以下问题:C# Form.DrawToBitmap方法的具体用法?C# Form.DrawToBitmap怎么用?C# Form.DrawToBitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Form
的用法示例。
在下文中一共展示了Form.DrawToBitmap方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ScreenCapture
public static void ScreenCapture(string received, Form form)
{
EnsureControlDisplaysCorrectlyByAddingItToAHiddenForm(form);
var b = new Bitmap(form.Width, form.Height, PixelFormat.Format32bppArgb);
form.DrawToBitmap(b, new Rectangle(0, 0, form.Width, form.Height));
b.Save(received, ImageFormat.Png);
}
示例2: Draw
/// <summary>
/// Draws the form to a bitmap.
/// </summary>
/// <param name="form">The form to draw.</param>
/// <param name="clientArea">If only the client area (non-chrome area) should be drawn.</param>
/// <returns>An image with the form drawn onto it.</returns>
/// <remarks>Internally uses WM_PRINT to draw the form to an HDC.</remarks>
public static Bitmap Draw(Form form, bool clientArea)
{
Bitmap bmp = new Bitmap(form.Width, form.Height);
form.DrawToBitmap(bmp, new Rectangle(0, 0, form.Width, form.Height));
if (clientArea)
{
Bitmap crop = new Bitmap(form.ClientRectangle.Width, form.ClientRectangle.Height);
using (Graphics g = Graphics.FromImage(crop))
{
Rectangle screenRectangle = form.RectangleToScreen(form.ClientRectangle);
int titleHeight = screenRectangle.Top - form.Top;
g.DrawImage(bmp, new Point((form.ClientRectangle.Width - form.Width) / 2, -titleHeight));
}
bmp.Dispose();
bmp = crop;
}
return bmp;
}
示例3: DisplayComparisonPlot
private void DisplayComparisonPlot(MSSpectra spectrumX, MSSpectra spectrumY, double mzTolerance,
string path = "comparison.png", string newTitle = "MS/MS Spectra")
{
var model = CreatePlot(spectrumX.Peaks, spectrumY.Peaks, mzTolerance);
model.Title = newTitle;
var plot = new PlotView();
plot.Model = model;
var form = new Form();
form.Size = Screen.PrimaryScreen.WorkingArea.Size;
plot.Dock = DockStyle.Fill;
form.Controls.Add(plot);
form.Show();
IO.Utilities.SleepNow(3);
using (var bitmap = new Bitmap(form.Width, form.Height))
{
form.DrawToBitmap(bitmap, form.DisplayRectangle);
bitmap.Save(path);
}
}
示例4: PaintMap
public Bitmap PaintMap(Form f1, Graphics grap)
{
try
{
mapimage = new Bitmap(f1.Width, f1.Height);
Rectangle frame = new Rectangle(new System.Drawing.Point(f1.Width, f1.Height), f1.Size);
f1.DrawToBitmap(mapimage, frame);
grap = Graphics.FromImage(mapimage);
string[] lines = System.IO.File.ReadAllLines(_mapname.ToString());
int Index_x;
int Limit = _wide - 1;
int Index_y;
int Limit_Y = _height - 1;
for (Index_x = 0; Index_x < Limit; Index_x++)
{
for (Index_y = 0; Index_y < Limit_Y; Index_y++)
{
//paint(grap, new Point(Index_x, Index_y), 0);
}
}
}
catch (Exception p)
{
Console.Write(p.Message);
}
return mapimage;
}
示例5: TAC_TurnAreaToPixData
//当前窗口上指定相对坐标,指定范围,转为点阵数据。
public static byte[][] TAC_TurnAreaToPixData(Form fmImaNoScreen, int nPositionX, int nPositionY, int nAreaWidth, int nAreaHeight)
{
byte[][] tempDesData = new byte[nAreaHeight][];
for (int i = 0; i < nAreaHeight; i++)
tempDesData[i] = new byte[nAreaWidth];
try
{
Bitmap bmpForm = new Bitmap(fmImaNoScreen.Width, fmImaNoScreen.Height);
fmImaNoScreen.DrawToBitmap(bmpForm, new Rectangle(0, 0, bmpForm.Width, bmpForm.Height));
Bitmap bmpDes = new Bitmap(nAreaWidth, nAreaHeight);
Graphics grpForm = Graphics.FromImage(bmpDes);
int Border = (fmImaNoScreen.Width - fmImaNoScreen.ClientSize.Width) / 2;
Rectangle destRect = new Rectangle(nPositionX + Border,
nPositionY + fmImaNoScreen.Height - fmImaNoScreen.ClientSize.Height - Border,
nAreaWidth, nAreaHeight);
Rectangle srcRect = new Rectangle(0, 0, nAreaWidth, nAreaHeight);
grpForm.DrawImage(bmpForm, srcRect, destRect, GraphicsUnit.Pixel);
System.Drawing.Imaging.BitmapData tempBitmapData = bmpDes.LockBits(srcRect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
fmImaNoScreen.Enabled = false;
unsafe
{
byte* tempPixelData = (byte*)tempBitmapData.Scan0.ToPointer();
int jump = tempBitmapData.Stride - nAreaWidth * 3;
for (int i = 0; i < nAreaHeight; i++)
{
for (int j = 0; j < nAreaWidth; j++)
{
tempDesData[i][j] = TAC_IsBlack(*tempPixelData ^ 0xff, *(tempPixelData + 1) ^ 0xff, *(tempPixelData + 2) ^ 0xff, 1);
tempPixelData += 3;
}
tempPixelData += jump;
}
}
fmImaNoScreen.Enabled = true;
}
catch (Exception Mistake)
{
MessageBox.Show(Mistake.ToString());
return null;
}
return tempDesData;
}