本文整理汇总了C#中System.Drawing.BufferedGraphicsContext.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# BufferedGraphicsContext.Dispose方法的具体用法?C# BufferedGraphicsContext.Dispose怎么用?C# BufferedGraphicsContext.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.BufferedGraphicsContext
的用法示例。
在下文中一共展示了BufferedGraphicsContext.Dispose方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
private void Draw()
{
var hours_in_window = (draw_interval.end - draw_interval.start).TotalHours;
if (hours_in_window < 1)
return;
hour_to_pixel_ratio = 1.0 * this.Width / hours_in_window;
BufferedGraphicsContext buffered_graphics_context = new BufferedGraphicsContext();
BufferedGraphics second_graphic_buffer = buffered_graphics_context.Allocate(this.CreateGraphics(), this.DisplayRectangle);
g = second_graphic_buffer.Graphics;
g.Clear(this.BackColor);
DrawTasks();
EnterStateAnimation();
DrawLinks();
second_graphic_buffer.Render();
second_graphic_buffer.Dispose();
buffered_graphics_context.Dispose();
}
示例2: OnPaint
/// <summary>
/// The override OnPaint- method to draw the content and more imporantly: the basic stuff around the panels.
/// Since it's always the same, it won't get overridden!
/// </summary>
/// <param name="e">The letter e - huehue</param>
protected override void OnPaint(PaintEventArgs e)
{
if ((DateTime.Now - DtSecond).Seconds >= 1)
{
//Debug.WriteLine("The OnPaint- loop was refreshed " + lTimesRefreshed + " times in a second!");
IterationsPerSeconds = _iTimesRefreshed;
_iTimesRefreshed = 0;
DtSecond = DateTime.Now;
}
_iTimesRefreshed++;
base.OnPaint(e);
//_swMainWatch.Reset();
//_swMainWatch.Start();
var context = new BufferedGraphicsContext();
context.MaximumBuffer = ClientSize;
using (var buffer = context.Allocate(e.Graphics, ClientRectangle))
{
buffer.Graphics.Clear(BackColor);
buffer.Graphics.CompositingMode = CompositingMode.SourceOver;
buffer.Graphics.CompositingQuality = CompositingQuality.HighSpeed;
buffer.Graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
buffer.Graphics.SmoothingMode = SmoothingMode.HighSpeed;
if (GInformation != null &&
GInformation.Gameinfo != null &&
GInformation.Gameinfo.IsIngame)
{
if (PSettings.PreferenceAll.Global.DrawOnlyInForeground && !BSurpressForeground)
{
if (PSc2Process == null)
_bDraw = false;
else
_bDraw = Interop.GetForegroundWindow().Equals(PSc2Process.MainWindowHandle);
}
else
{
_bDraw = true;
if (PSc2Process == null)
{
_bDraw = false;
PSc2Process = GInformation.CStarcraft2;
}
else if (Interop.GetForegroundWindow().Equals(PSc2Process.MainWindowHandle))
{
Interop.SetActiveWindow(Handle);
}
}
if (_bDraw)
{
Draw(buffer);
DrawResizeBorder(buffer);
}
}
buffer.Render();
}
context.Dispose();
//_swMainWatch.Stop();
//Debug.WriteLine("Time to execute DrawingMethods:" + 1000000 * _swMainWatch.ElapsedTicks / Stopwatch.Frequency + " µs");
}
示例3: accel_AccelerationChange
void accel_AccelerationChange(object sender, AccelerationChangeEventArgs e)
{
formGraphicsContext = new BufferedGraphicsContext();
formGraphicsBuffer = formGraphicsContext.Allocate(Graphics.FromImage(formDrawingSurface), rectBounds);
formGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
formGraphicsBuffer.Graphics.Clear(SystemColors.Control);
int i = 0;
//low pass filtering
switch (e.Index)
{
case 0:
xOut = 0;
xFilt[6] = e.Acceleration;
for (i = 0; i < 6; i++)
{
xFilt[i] = xFilt[i + 1];
xOut = xOut + xFilt[i];
}
xOut = xOut / 6;
label6.Text = e.Acceleration.ToString();
break;
case 1:
yOut = 0;
yFilt[6] = e.Acceleration;
for (i = 0; i < 6; i++)
{
yFilt[i] = yFilt[i + 1];
yOut = yOut + yFilt[i];
}
yOut = yOut / 6;
label7.Text = e.Acceleration.ToString();
break;
case 2:
zOut = 0;
zFilt[6] = e.Acceleration;
for (i = 0; i < 6; i++)
{
zFilt[i] = zFilt[i + 1];
zOut = zOut + zFilt[i];
}
zOut = zOut / 6;
label8.Text = e.Acceleration.ToString();
break;
}
x1Old = xCenter - (float)xOut * circleRadius;
y1Old = yCenter + (float)yOut * circleRadius;
formGraphicsBuffer.Graphics.DrawLine(xyAxisPen, xCenter, yCenter, x1Old, y1Old);
formGraphicsBuffer.Graphics.DrawEllipse(circlePen, circleRectangle);
if (accel.axes.Count == 3)
{
if (zOut > 0)
{
formGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Red, 2),
new Rectangle((int)xCenter - (int)(circleRadius * zOut), (int)yCenter - (int)(circleRadius * zOut),
(int)(circleDiameter * zOut), (int)(circleDiameter * zOut)));
}
else
{
formGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Green, 2),
new Rectangle((int)xCenter - (int)(circleRadius * -zOut), (int)yCenter - (int)(circleRadius * -zOut),
(int)(circleDiameter * -zOut), (int)(circleDiameter * -zOut)));
}
}
formGraphicsBuffer.Render(panel1.CreateGraphics());
formGraphicsBuffer.Dispose();
formGraphicsContext.Dispose();
}
示例4: AllocBufferInTempManager
private BufferedGraphics AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle) {
BufferedGraphicsContext tempContext = null;
BufferedGraphics tempBuffer = null;
try {
tempContext = new BufferedGraphicsContext();
if (tempContext != null) {
tempBuffer = tempContext.AllocBuffer(targetGraphics, targetDC, targetRectangle);
tempBuffer.DisposeContext = true;
}
}
finally {
if (tempContext != null && (tempBuffer == null || (tempBuffer != null && !tempBuffer.DisposeContext))) {
tempContext.Dispose();
}
}
return tempBuffer;
}
示例5: accel_AccelerationChange
//acceleration change event handler
void accel_AccelerationChange(object sender, AccelerationChangeEventArgs e)
{
//get our graphics buffer going so we can draw to our panel
accelGraphicsContext = new BufferedGraphicsContext();
accelGraphicsBuffer = accelGraphicsContext.Allocate(Graphics.FromImage(accelDrawingSurface), boundsRectangle);
accelGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
accelGraphicsBuffer.Graphics.Clear(SystemColors.Control);
Accelerometer attached = (Accelerometer)sender;
//in this switch statement we will do a bit of simple low pass filtering to smooth out the motion of the graphical representation of the
//acceleration data. We will also write the raw data to the textbox for the appropriate axis.
int i = 0;
try
{
switch (e.Index)
{
case 0:
xOut = 0;
xFilt[6] = e.Acceleration;
for (i = 0; i < 6; i++)
{
xFilt[i] = xFilt[i + 1];
xOut = xOut + xFilt[i];
}
xOut = xOut / 6;
axis1AccelTxt.Text = e.Acceleration.ToString();
break;
case 1:
yOut = 0;
yFilt[6] = e.Acceleration;
for (i = 0; i < 6; i++)
{
yFilt[i] = yFilt[i + 1];
yOut = yOut + yFilt[i];
}
yOut = yOut / 6;
axis2AccelTxt.Text = e.Acceleration.ToString();
break;
case 2:
zOut = 0;
zFilt[6] = e.Acceleration;
for (i = 0; i < 6; i++)
{
zFilt[i] = zFilt[i + 1];
zOut = zOut + zFilt[i];
}
zOut = zOut / 6;
axis3AccelTxt.Text = e.Acceleration.ToString();
break;
}
}
catch (PhidgetException ex)
{
MessageBox.Show(ex.Description);
}
xOld = xCenter - (float)xOut * circleRadius;
yOld = yCenter + (float)yOut * circleRadius;
accelGraphicsBuffer.Graphics.DrawLine(xyAxisPen, xCenter, yCenter, xOld, yOld);
accelGraphicsBuffer.Graphics.DrawEllipse(circlePen, circleRectangle);
if (attached.axes.Count == 3)
{
if (zOut > 0)
{
accelGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Red, 2),
new Rectangle((int)xCenter - (int)(circleRadius * zOut), (int)yCenter - (int)(circleRadius * zOut),
(int)(circleDiameter * zOut), (int)(circleDiameter * zOut)));
}
else
{
accelGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Green, 2),
new Rectangle((int)xCenter - (int)(circleRadius * -zOut), (int)yCenter - (int)(circleRadius * -zOut),
(int)(circleDiameter * -zOut), (int)(circleDiameter * -zOut)));
}
}
accelGraphicsBuffer.Render(panel1.CreateGraphics());
accelGraphicsBuffer.Dispose();
accelGraphicsContext.Dispose();
}
示例6: OnPaint
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
var context = new BufferedGraphicsContext();
context.MaximumBuffer = ClientSize;
using (BufferedGraphics buffer = context.Allocate(e.Graphics, ClientRectangle))
{
buffer.Graphics.Clear(BackColor);
buffer.Graphics.CompositingMode = CompositingMode.SourceOver;
buffer.Graphics.CompositingQuality = CompositingQuality.HighQuality;
buffer.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
buffer.Graphics.SmoothingMode = SmoothingMode.HighQuality;
if (GInfo != null && GInfo.IsIngame)
{
Drawing(buffer.Graphics);
}
#region Draw a Rectangle around the Panels (When changing position)
/* Draw a final bound around the panel */
if (_bChangingPosition)
{
/* Simple border */
buffer.Graphics.DrawRectangle(_pYellowGreen2,
1,
1,
Width - 2,
Height - 2);
/* Draw some filled frectangles to make the resizing easier */
buffer.Graphics.FillRectangle(Brushes.YellowGreen,
Width - SizeOfRectangle, 0, SizeOfRectangle,
SizeOfRectangle);
buffer.Graphics.FillRectangle(Brushes.YellowGreen,
0, Height - SizeOfRectangle, SizeOfRectangle,
SizeOfRectangle);
buffer.Graphics.FillRectangle(Brushes.YellowGreen,
Width - SizeOfRectangle, Height - SizeOfRectangle,
SizeOfRectangle, SizeOfRectangle);
buffer.Graphics.FillRectangle(Brushes.YellowGreen,
Width/2 - SizeOfRectangle, Height/2 - SizeOfRectangle,
SizeOfRectangle*2, SizeOfRectangle*2);
/* Draw current size */
buffer.Graphics.DrawString(
Width.ToString() + "x" +
Height.ToString() + " - [X=" +
Location.X.ToString() + "; Y=" + Location.Y.ToString() + "]",
new Font("Arial", 8, FontStyle.Regular), Brushes.YellowGreen, 2, 2);
}
else
Cursor = Cursors.Default;
#endregion
buffer.Render();
}
context.Dispose();
}
示例7: AllocBufferInTempManager
private BufferedGraphics AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
{
BufferedGraphicsContext context = null;
BufferedGraphics graphics = null;
try
{
context = new BufferedGraphicsContext();
if (context != null)
{
graphics = context.AllocBuffer(targetGraphics, targetDC, targetRectangle);
graphics.DisposeContext = true;
}
}
finally
{
if ((context != null) && ((graphics == null) || ((graphics != null) && !graphics.DisposeContext)))
{
context.Dispose();
}
}
return graphics;
}
示例8: drawMagFieldGraph
private void drawMagFieldGraph()
{
magFieldGraphicsContext = new BufferedGraphicsContext();
magFieldGraphicsBuffer = magFieldGraphicsContext.Allocate(Graphics.FromImage(magFieldDrawingSurface), magFieldBoundsRectangle);
magFieldGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
magFieldGraphicsBuffer.Graphics.Clear(SystemColors.Control);
float xCenter = (float)(magFieldBoundsRectangle.Width / 2.0);
float yCenter = (float)(magFieldBoundsRectangle.Height / 2.0);
float xOld = xCenter + (float)(spatial.compassAxes[0].MagneticField) * magFieldCircleRadius * (float)(1 / ambientMagneticField);
float yOld = yCenter + (float)(spatial.compassAxes[1].MagneticField) * magFieldCircleRadius * (float)(1 / ambientMagneticField);
magFieldGraphicsBuffer.Graphics.DrawLine(magFieldXYAxisPen, xCenter, yCenter, xOld, yOld);
magFieldGraphicsBuffer.Graphics.DrawEllipse(magFieldCirclePen, magFieldCircleRectangle);
if (spatial.compassAxes.Count == 3)
{
double zOut = (spatial.compassAxes[2].MagneticField) * (float)(1 / ambientMagneticField);
if (zOut > 0)
{
magFieldGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Red, 2),
new Rectangle((int)xCenter - (int)(magFieldCircleRadius * zOut), (int)yCenter - (int)(magFieldCircleRadius * zOut),
(int)(magFieldCircleDiameter * zOut), (int)(magFieldCircleDiameter * zOut)));
}
else
{
magFieldGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Green, 2),
new Rectangle((int)xCenter - (int)(magFieldCircleRadius * -zOut), (int)yCenter - (int)(magFieldCircleRadius * -zOut),
(int)(magFieldCircleDiameter * -zOut), (int)(magFieldCircleDiameter * -zOut)));
}
}
magFieldGraphicsBuffer.Render(magFieldView.CreateGraphics());
magFieldGraphicsBuffer.Dispose();
magFieldGraphicsContext.Dispose();
}
示例9: drawGyroGraph
private void drawGyroGraph()
{
//get our graphics buffer going so we can draw to our panel
gyroGraphicsContext = new BufferedGraphicsContext();
gyroGraphicsBuffer = gyroGraphicsContext.Allocate(Graphics.FromImage(gyroDrawingSurface), gyroboundsRectangle);
gyroGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
gyroGraphicsBuffer.Graphics.Clear(SystemColors.Control);
float xCenter = (float)(gyroboundsRectangle.Width / 2.0);
float yCenter = (float)(gyroboundsRectangle.Height / 2.0);
//heading circles
for (int i = 0; i < spatial.gyroAxes.Count; i++)
{
gyroGraphicsBuffer.Graphics.DrawEllipse(gyrocirclePen, gyrocircleRectangle[i]);
gyroGraphicsBuffer.Graphics.DrawEllipse(
gyroxyAxisPen[i],
(float)(gyrocircleRadius[i] * Math.Cos(gyroHeading[i] * (Math.PI / 180.0)) + xCenter) - 2,
(float)(-gyrocircleRadius[i] * Math.Sin(gyroHeading[i] * (Math.PI / 180.0)) + yCenter) - 2,
4,
4
);
}
gyroGraphicsBuffer.Render(gyroView.CreateGraphics());
gyroGraphicsBuffer.Dispose();
gyroGraphicsContext.Dispose();
}
示例10: drawCompassBearingGraph
private void drawCompassBearingGraph()
{
compassGraphicsContext = new BufferedGraphicsContext();
compassGraphicsBuffer = compassGraphicsContext.Allocate(Graphics.FromImage(compassDrawingSurface), compassboundsRectangle);
compassGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
compassGraphicsBuffer.Graphics.Clear(SystemColors.Control);
float xCenter = (float)(compassboundsRectangle.Width / 2.0);
float yCenter = (float)(compassboundsRectangle.Height / 2.0);
compassGraphicsBuffer.Graphics.DrawEllipse(compassCirclePen, compasscircleRectangle);
Point pt = new Point((int)(xCenter - spatialImage.Width / 2), (int)(yCenter - spatialImage.Height / 2));
compassGraphicsBuffer.Graphics.DrawImageUnscaled(rotateImage(spatialImage, (float)compassBearing), pt);
compassGraphicsBuffer.Graphics.DrawString("N", new Font("Arial", 16), new SolidBrush(Color.Black), xCenter-10, 0);
compassGraphicsBuffer.Graphics.DrawString("E", new Font("Arial", 16), new SolidBrush(Color.Black), xCenter*2-20, yCenter-12);
compassGraphicsBuffer.Graphics.DrawString("S", new Font("Arial", 16), new SolidBrush(Color.Black), xCenter-10, yCenter*2-20);
compassGraphicsBuffer.Graphics.DrawString("W", new Font("Arial", 16), new SolidBrush(Color.Black), 0, yCenter-12);
//Ticks around the compass circle
for (int i = 0; i < 360; i+=10)
{
Pen p = compassTickPen;
int tickSize = 4;
if (i == 0 || i == 90 || i == 180 || i == 270)
{
p = compassTickPenBig;
tickSize = 6;
}
compassGraphicsBuffer.Graphics.DrawLine(p,
(float)((compassCircleRadius + tickSize) * Math.Cos(i * (Math.PI / 180.0)) + xCenter),
(float)(-(compassCircleRadius + tickSize) * Math.Sin(i * (Math.PI / 180.0)) + yCenter),
(float)((compassCircleRadius - tickSize) * Math.Cos(i * (Math.PI / 180.0)) + xCenter),
(float)(-(compassCircleRadius - tickSize) * Math.Sin(i * (Math.PI / 180.0)) + yCenter));
}
//Marker on the compass circle
compassGraphicsBuffer.Graphics.DrawEllipse(
compassDotPen,
(float)(compassCircleRadius * Math.Cos((-compassBearing+90) * (Math.PI / 180.0)) + xCenter) - 2,
(float)(-compassCircleRadius * Math.Sin((-compassBearing+90) * (Math.PI / 180.0)) + yCenter) - 2,
4,
4
);
compassGraphicsBuffer.Render(compassView.CreateGraphics());
compassGraphicsBuffer.Dispose();
compassGraphicsContext.Dispose();
}
示例11: drawAccelGraph
private void drawAccelGraph()
{
accelGraphicsContext = new BufferedGraphicsContext();
accelGraphicsBuffer = accelGraphicsContext.Allocate(Graphics.FromImage(accelDrawingSurface), accelboundsRectangle);
accelGraphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
accelGraphicsBuffer.Graphics.Clear(SystemColors.Control);
float xCenter = (float)(accelboundsRectangle.Width / 2.0);
float yCenter = (float)(accelboundsRectangle.Height / 2.0);
float xOld = xCenter - (float)spatial.accelerometerAxes[0].Acceleration * accelcircleRadius * (float)(1 / ambientGravity);
float yOld = yCenter - (float)spatial.accelerometerAxes[1].Acceleration * accelcircleRadius * (float)(1 / ambientGravity);
accelGraphicsBuffer.Graphics.DrawLine(accelxyAxisPen, xCenter, yCenter, xOld, yOld);
accelGraphicsBuffer.Graphics.DrawEllipse(accelcirclePen, new Rectangle((int)(xCenter - accelcircleRadius), (int)(yCenter - accelcircleRadius),
(int)accelcircleDiameter, (int)accelcircleDiameter));
if (spatial.accelerometerAxes.Count == 3)
{
double zOut = spatial.accelerometerAxes[2].Acceleration * (float)(1 / ambientGravity);
if (zOut > 0)
{
accelGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Red, 2),
new Rectangle((int)xCenter - (int)(accelcircleRadius * zOut), (int)yCenter - (int)(accelcircleRadius * zOut),
(int)(accelcircleDiameter * zOut), (int)(accelcircleDiameter * zOut)));
}
else
{
accelGraphicsBuffer.Graphics.DrawEllipse(new Pen(Color.Green, 2),
new Rectangle((int)xCenter - (int)(accelcircleRadius * -zOut), (int)yCenter - (int)(accelcircleRadius * -zOut),
(int)(accelcircleDiameter * -zOut), (int)(accelcircleDiameter * -zOut)));
}
}
accelGraphicsBuffer.Render(panel1.CreateGraphics());
accelGraphicsBuffer.Dispose();
accelGraphicsContext.Dispose();
}