本文整理汇总了C#中System.Windows.Forms.Panel.DrawToBitmap方法的典型用法代码示例。如果您正苦于以下问题:C# Panel.DrawToBitmap方法的具体用法?C# Panel.DrawToBitmap怎么用?C# Panel.DrawToBitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Panel
的用法示例。
在下文中一共展示了Panel.DrawToBitmap方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPrintArea
public void GetPrintArea(Panel pnl)
{
int pnlWidth = pnl.Width;
int pnlHeight = pnl.Height;
MemoryImage = new Bitmap(pnlWidth, pnlHeight);
Rectangle rect = new Rectangle(0, 0, pnlWidth, pnlHeight);
pnl.DrawToBitmap(MemoryImage, new Rectangle(0, 0, pnlWidth, pnlHeight));
}
示例2: GetCapturedImage
public Bitmap GetCapturedImage(Panel panel, string filePath, Boolean firstTime)
{
Rectangle rectangle;
Bitmap bitmap = null;
ArrayList controls = null;
try
{
rectangle = panel.RectangleToScreen(panel.Bounds);
bitmap = new Bitmap(rectangle.Width, rectangle.Height, PixelFormat.Format32bppArgb);
if (firstTime)
{
panel.DrawToBitmap(bitmap, panel.Bounds); // 再帰的にコンテナ及びコントロールをキャプチャ
controls = GetAllControls(panel);
controls.Reverse(); // 背面から
foreach (Control c in controls)
{
Rectangle rectangle2 = c.Bounds;
Control control = c;
while (control.Bounds.Location != panel.Bounds.Location)
{
rectangle2.X += control.Parent.Bounds.Location.X;
rectangle2.Y += control.Parent.Bounds.Location.Y;
control = control.Parent;
}
c.DrawToBitmap(bitmap, rectangle2);
}
}
else
{
CaptureControls(panel, ref bitmap);
}
bitmap.Save(filePath, ImageFormat.Bmp); // 保存する場合
}
catch (SystemException ex)
{
Console.WriteLine(ex.Message);
}
return bitmap;
}
示例3: ProcessPrintRequest
//.........这里部分代码省略.........
break;
case "STRETCH":
bufferGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
bufferGraphics.DrawImage(img, 0, 0, printPanel.Size.Width, printPanel.Size.Height);
bufferGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default;
break;
case "CENTER":
int centerX = (printPanel.Size.Width / 2) - (img.Size.Width / 2);
int centerY = (printPanel.Size.Height / 2) - (img.Size.Height / 2);
bufferGraphics.DrawImage(img, centerX, centerY);
break;
default:
bufferGraphics.DrawImage(img, 0, 0);
break;
}
}
foreach (Control control in pageControls)
{
if (control is DragableGroupBox)
{
Pen pen = new Pen(Color.Black);
Point ul = control.Location;
Point ur = new Point(control.Location.X + control.Width, control.Location.Y);
Point ll = new Point(control.Location.X, control.Location.Y + control.Height);
Point lr = new Point(control.Location.X + control.Width, control.Location.Y + control.Height);
bufferGraphics.DrawLine(pen, ul, ur);
bufferGraphics.DrawLine(pen, ur, lr);
bufferGraphics.DrawLine(pen, lr, ll);
bufferGraphics.DrawLine(pen, ll, ul);
}
}
bufferGraphics.DrawImage(b, 0, 0);
bufferBitmap = b;
printPanel.BackgroundImage = b;
}
catch
{
bufferBitmap.Dispose();
graphics.Dispose();
printPanel.Dispose();
pageImageList = null;
return false;
}
}
}
foreach (Control control in pageControls)
{
if (control is DragableGroupBox)
{
Label label = new Label();
label.Width = control.Width;
label.Text = control.Text;
Size textSize = TextRenderer.MeasureText(graphics, label.Text, label.Font);
label.Left = control.Left + 12;
label.Top = control.Top - textSize.Height / 2;
label.Width = textSize.Width + 12;
label.Font = control.Font;
label.AutoSize = true;
printPanel.Controls.Add(label);
}
}
if (bufferBitmap != null)
{
graphics.DrawImage(bufferBitmap, 0, 0);
}
try
{
memoryImage = new Bitmap(printPanel.Width, printPanel.Height, graphics);
printPanel.DrawToBitmap(memoryImage, new Rectangle(0, 0, printPanel.Width, printPanel.Height));
printPanel.Dispose();
pageImageList.Add(memoryImage.Clone());
}
catch
{
bufferBitmap.Dispose();
graphics.Dispose();
printPanel.Dispose();
pageImageList = null;
memoryImage.Dispose();
return false;
}
}
}
catch
{
memoryImage.Dispose();
pageImageList = null;
return false;
};
return true;
}
示例4: makeImage
private Bitmap makeImage(Template template)
{
Bitmap bmp;
Panel panel = new Panel();
Panel panel0 = new Panel();
Panel panel1 = new Panel();
Label label0 = new Label();
Label label1 = new Label();
panel.Size = new Size(OBJ_WIDTH, OBJ_HEIGHT);
panel.BorderStyle = BorderStyle.None;
panel.BackColor = Color.Black;
panel.Margin = new Padding(0, 0, 0, 0);
panel.Location = new Point(0, 0);
panel0.Size = new Size(OBJ_WIDTH, OBJ_HEIGHT);
panel0.BorderStyle = BorderStyle.None;
panel0.BackColor = Color.White;
panel0.Margin = new Padding(0, 0, 0, 0);
panel0.Location = new Point(0, 0);
panel1.Size = new Size(OBJ_WIDTH, OBJ_HEIGHT);
panel1.BorderStyle = BorderStyle.None;
panel1.BackColor = Color.White;
panel1.Margin = new Padding(0, 0, 0, 0);
panel1.Location = new Point(0, 0);
label0.Margin = new Padding(0, 0, 0, 0);
label0.Padding = new Padding(0, 0, 0, 0);
label0.Location = new Point(1, 1);
label0.Size = new Size(10, 10);
label0.BackColor = Color.White;
label0.Font = new Font(FontFamily.GenericSansSerif, 6);
label0.Text = "1";
label1.Margin = new Padding(0, 0, 0, 0);
label1.Padding = new Padding(0, 0, 0, 0);
label1.Location = new Point(1, 1);
label1.Size = new Size(10, 10);
label1.BackColor = Color.White;
label1.Font = new Font(FontFamily.GenericSansSerif, 6);
label1.Text = "2";
Panel curBmpObj;
bool hasSide2 = false;
foreach (TemplateObject curObj in template.objects)
{
curBmpObj = new Panel();
if (curObj.quizType == Constant.answerPrefix)
{
curBmpObj.BackColor = Color.Green;
}
else if (curObj.quizType == Constant.questionPrefix)
{
curBmpObj.BackColor = Color.Red;
}
else
{
curBmpObj.BackColor = Color.Gray;
}
curBmpObj.BorderStyle = BorderStyle.FixedSingle;
curBmpObj.Location = new Point(Convert.ToInt32(curObj.x1 / 100.0 * OBJ_WIDTH), Convert.ToInt32(curObj.y1 / 100.0 * OBJ_HEIGHT));
curBmpObj.Size = new Size(Convert.ToInt32((curObj.x2 - curObj.x1) / 100.0 * OBJ_WIDTH), Convert.ToInt32((curObj.y2 - curObj.y1) / 100.0 * OBJ_HEIGHT));
if (curObj.side == 0)
{
panel0.Controls.Add(curBmpObj);
}
else if (curObj.side == 1)
{
panel1.Controls.Add(curBmpObj);
hasSide2 = true;
}
}
panel0.Controls.Add(label0);
panel1.Controls.Add(label1);
if (hasSide2)
{
panel.Height = (OBJ_HEIGHT * 2) + 1;
panel1.Location = new Point(0, OBJ_HEIGHT + 1);
panel.Controls.Add(panel1);
}
panel.Controls.Add(panel0);
bmp = new Bitmap(panel.Width, panel.Height);
panel.DrawToBitmap(bmp, new Rectangle(0, 0, panel.Width, panel.Height));
return bmp;
}