本文整理汇总了C#中System.Windows.Forms.Control.DrawToBitmap方法的典型用法代码示例。如果您正苦于以下问题:C# Control.DrawToBitmap方法的具体用法?C# Control.DrawToBitmap怎么用?C# Control.DrawToBitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Control
的用法示例。
在下文中一共展示了Control.DrawToBitmap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetTransparentControl
/// <summary>
/// Поставить прозрачность + картинка
/// </summary>
/// <param name="parent"></param>
/// <param name="usedControl"></param>
/// <param name="img"></param>
public static void SetTransparentControl(Control parent, Panel usedControl, Image img)
{
//try
//{
//Получить координаты контрола
var point = new Point(usedControl.Left, usedControl.Top);
var width = usedControl.Width;
var height = usedControl.Height;
var destRect = new Rectangle(0, 0, width, height);//куда вставляем
var srcRect = new Rectangle(point.X, point.Y, width, height);//Что вырезаем
var buff = new Bitmap(parent.Width, parent.Height, PixelFormat.Format32bppArgb);
var dest = new Bitmap(width, height, PixelFormat.Format32bppArgb);
using (var gr = Graphics.FromImage(dest))
{
parent.DrawToBitmap(buff, new Rectangle(0, 0, parent.Width, parent.Height));
gr.DrawImage(buff, destRect, srcRect, GraphicsUnit.Pixel);
if (img != null)
gr.DrawImage(img, 0, 0, width, height);
}
usedControl.BackgroundImage = dest;
//}
//catch (Exception ex)
//{
// Logger.ExceptionSaveAndThrow(ex);
//}
}
示例2: PictureButton
public PictureButton(Control parent)
{
_parent = parent;
var point = new Point(Left, Top);
var width = Width;
var height = Height;
var destRect = new Rectangle(0, 0, width, height);//куда вставляем
var srcRect = new Rectangle(point.X, point.Y, width, height);//Что вырезаем
var buff = new Bitmap(Width, Height, PixelFormat.Format32bppArgb);
var dest = new Bitmap(width, height, PixelFormat.Format32bppArgb);
using (var gr = Graphics.FromImage(dest))
{
_parent.DrawToBitmap(buff, new Rectangle(0, 0, Width, Height));
gr.DrawImage(buff, destRect, srcRect, GraphicsUnit.Pixel);
if(Image!=null)
gr.DrawImage(Image, 0, 0, width, height);
}
Image = dest;
}
示例3: GenerateImage
/// <summary>
///
/// </summary>
/// <param name="panel"></param>
public static void GenerateImage(Control panel)
{
//Save control images for documentation purposes
var image = new Bitmap(panel.ClientRectangle.Width, panel.ClientRectangle.Height);
panel.DrawToBitmap(image, panel.ClientRectangle);
image.Save(panel.Name + ".png");
}
示例4: TakeSnapshotFromControl
public static Bitmap TakeSnapshotFromControl(Control control)
{
if (control == null) throw new ArgumentNullException("control");
var bitmap = new Bitmap(control.Width, control.Height);
control.DrawToBitmap(bitmap, new Rectangle(0, 0, bitmap.Size.Width, bitmap.Size.Height));
return bitmap;
}
示例5: SavePng
public static void SavePng(string received, Control control)
{
using (var b = new Bitmap(control.Width, control.Height, PixelFormat.Format32bppArgb))
{
control.DrawToBitmap(b, new Rectangle(0, 0, control.Width, control.Height));
b.Save(received, ImageFormat.Png);
}
}
示例6: createBitmapPreview
/// <summary>
/// Creates the bitmap preview. Will distort BMP
/// </summary>
/// <param name="src">The shape to scale bitmap to.</param>
/// <param name="width">The width to scale down to.</param>
/// <param name="height">The height to scale down to.</param>
/// <returns></returns>
public static Bitmap createBitmapPreview(Control src, int width, int height)
{
using (var bmp = new Bitmap(src.Width, src.Height))
{
src.DrawToBitmap(bmp, new Rectangle(0, 0, src.Width, src.Height));
return ResizeImage(bmp, new Size(width, height));
}
}
示例7: SetDragImage
/// <summary>
/// Sets the drag image as the rendering of a control.
/// </summary>
/// <param name="dataObject">The DataObject to set the drag image on.</param>
/// <param name="control">The Control to render as the drag image.</param>
/// <param name="cursorOffset">The location of the cursor relative to the control.</param>
public static void SetDragImage(this System.Windows.Forms.IDataObject dataObject, Control control, Point cursorOffset) {
int width = control.Width;
int height = control.Height;
var bmp = new Bitmap(width, height);
control.DrawToBitmap(bmp, new Rectangle(0, 0, width, height));
SetDragImage(dataObject, bmp, cursorOffset);
}
示例8: GetForeground
protected virtual Bitmap GetForeground(Control ctrl)
{
Bitmap bitmap = new Bitmap(base.Width, base.Height);
if (!ctrl.IsDisposed)
{
this.isSnapshotNow = true;
ctrl.DrawToBitmap(bitmap, new Rectangle(this.Padding.Left, this.Padding.Top, ctrl.Width, ctrl.Height));
this.isSnapshotNow = false;
}
return bitmap;
}
示例9: FormToBitmap
public static Image FormToBitmap(Control form, Size size)
{
Size formSize = form.Size;
Rectangle rect = new Rectangle(new Point(0, 0), formSize);
Bitmap bitmap = new Bitmap(formSize.Width, formSize.Height);
form.DrawToBitmap(bitmap, rect);
Bitmap result = new Bitmap(size.Width, size.Height);
Graphics g = Graphics.FromImage(result);
rect.Size = size;
g.DrawImage(bitmap, rect);
return result;
}
示例10: DrawBackControl
private void DrawBackControl(Control c, System.Windows.Forms.PaintEventArgs pevent)
{
using (Bitmap bmp = new Bitmap(c.Width, c.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
c.DrawToBitmap(bmp, new Rectangle(0, 0, c.Width, c.Height));
int offsetX = (c.Left - this.Left) -
(int)Math.Floor((double)(this.Bounds.Width - this.ClientRectangle.Width) / 2.0);
int offsetY = (c.Top - this.Top) - (int)Math.Floor
((double)(this.Bounds.Height -
this.ClientRectangle.Height) / 2.0);
pevent.Graphics.DrawImage(bmp, offsetX, offsetY, c.Width, c.Height);
}
}
示例11: DoFade
public void DoFade(Control panel1, Control panel2)
{
_startimage = new Bitmap(panel1.Width, panel1.Height);
_endimage = new Bitmap(panel2.Width, panel2.Height);
panel1.DrawToBitmap(_startimage, panel1.ClientRectangle);
panel2.DrawToBitmap(_endimage, panel2.ClientRectangle);
Location = panel1.Location;
Size = panel1.Size;
_fade = 1;
_tmr.Interval = 1;
_tmr.Enabled = true;
}
示例12: GetScreenBackground
/*
private Bitmap GetScreenBackground(Control ctrl, bool includeForeground, bool clip)
{
var size = GetBounds().Size;
Graphics temp = FakeControl.CreateGraphics();//???
var bmp = new Bitmap(size.Width, size.Height, temp);
Graphics gr = Graphics.FromImage(bmp);
var p = ctrl.Parent == null? ctrl.Location : ctrl.Parent.PointToScreen(ctrl.Location);
gr.CopyFromScreen(p.X - animation.Padding.Left, p.Y - animation.Padding.Top, 0, 0, size);
return bmp;
}*/
protected virtual Bitmap GetForeground(Control ctrl)
{
Bitmap bmp = null;
if (!ctrl.IsDisposed)
{
if (ctrl.Parent == null)
{
bmp = new Bitmap(ctrl.Width + animation.Padding.Horizontal, ctrl.Height + animation.Padding.Vertical);
ctrl.DrawToBitmap(bmp, new Rectangle(animation.Padding.Left, animation.Padding.Top, ctrl.Width, ctrl.Height));
}
else
{
bmp = new Bitmap(DoubleBitmap.Width, DoubleBitmap.Height);
ctrl.DrawToBitmap(bmp, new Rectangle(ctrl.Left - DoubleBitmap.Left, ctrl.Top - DoubleBitmap.Top, ctrl.Width, ctrl.Height));
#if debug
using (var gr = Graphics.FromImage(bmp))
gr.DrawLine(Pens.Red, 0, 0, DoubleBitmap.Width, DoubleBitmap.Height);
#endif
}
}
return bmp;
}
示例13: GetForeground
protected virtual Bitmap GetForeground(Control ctrl)
{
Bitmap bmp = new Bitmap(this.Width, this.Height);
if (!ctrl.IsDisposed)
{
isSnapshotNow = true;
ctrl.DrawToBitmap(bmp, new Rectangle(Padding.Left, Padding.Top, ctrl.Width, ctrl.Height));
isSnapshotNow = false;
}
return bmp;
}
示例14: Draw
/// <summary>
/// Draws the control to a bitmap.
/// </summary>
/// <param name="control">The control to draw.</param>
/// <returns>An image with the control drawn onto it.</returns>
/// <remarks>Internally uses WM_PRINT to draw the control to an HDC</remarks>
public static Bitmap Draw(Control control)
{
Bitmap dest = new Bitmap(control.Width, control.Height);
control.DrawToBitmap(dest, new Rectangle(0, 0, control.Width, control.Height));
return dest;
}
示例15: Show
//-------------------------------------------------------------------------------------
/// <summary>
/// Отображает контрол в указанном родителе.
/// </summary>
/// <param name="parent">Родительский контрол.</param>
/// <param name="useBack">Определяет, будет ли использоваться эмуляция прозрачности фона.</param>
public static void Show(Control parent, bool useBack = true)
{
SimProgress box = new SimProgress();
foreach(Control c in parent.Controls)
if(c is SimProgress)
{
((SimProgress)c).Start();
return;
}
Rectangle r = new Rectangle(Point.Empty, parent.Size);
try
{
if(useBack)
{
r.X = -1*(parent.Width - parent.ClientSize.Width)/2;
r.Y = -1*(parent.Height - parent.ClientSize.Height)/2;
Bitmap bmp = new Bitmap(r.Width, r.Height);
parent.DrawToBitmap(bmp, new Rectangle(Point.Empty, parent.Size)); //parent.Location
BitmapEffects.GaussianBlur(bmp, 4);
BitmapEffects.Ligth(bmp, 50);
if(box.BackgroundImageLayout != ImageLayout.Center)
box.BackgroundImageLayout = ImageLayout.Center;
box.BackgroundImage = bmp;
}
else
box.BackColor = Color.Transparent;
}
catch
{
}
box.Bounds = r;
parent.Controls.Add(box);
box.BringToFront();
box.timer.Start();
parent.SizeChanged += new EventHandler(parent_SizeChanged);
}