本文整理汇总了C#中System.Windows.Forms.Form.CreateGraphics方法的典型用法代码示例。如果您正苦于以下问题:C# System.Windows.Forms.Form.CreateGraphics方法的具体用法?C# System.Windows.Forms.Form.CreateGraphics怎么用?C# System.Windows.Forms.Form.CreateGraphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Form
的用法示例。
在下文中一共展示了System.Windows.Forms.Form.CreateGraphics方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDpi
public static uint GetDpi(this System.Windows.Forms.Screen screen)
{
if (!MonitorDpiSupported)
{
// fallback to slow method if we can't get the dpi from the system
using (var form = new System.Windows.Forms.Form { Bounds = screen.Bounds })
using (var graphics = form.CreateGraphics())
{
return (uint)graphics.DpiY;
}
}
var pnt = new System.Drawing.Point(screen.Bounds.Left + 1, screen.Bounds.Top + 1);
var mon = MonitorFromPoint(pnt, MONITOR.DEFAULTTONEAREST);
uint dpiX, dpiY;
GetDpiForMonitor(mon, MDT.EFFECTIVE_DPI, out dpiX, out dpiY);
return dpiX;
}
示例2: test
public void test(Image t)
{
MWNumericArray d = (MWNumericArray)t.image;
double[,] i_d = (double[,])d.ToArray(MWArrayComponent.Real);
Bitmap bmp = new Bitmap(t.Height, t.Width);
for (int i = 0; i < t.Height; i++)
{
for (int j = 0; j < t.Width; j++)
{
byte pixel = (byte)(i_d[j, i] * 255);
Color color = Color.FromArgb(255, pixel, pixel, pixel);
bmp.SetPixel(i, j, color);
}
}
System.Windows.Forms.Form TestForm = new System.Windows.Forms.Form();
TestForm.Size = new System.Drawing.Size(t.Width + 20, t.Height + 40);
Graphics g = TestForm.CreateGraphics();
g.DrawImage(bmp, 0, 0);
TestForm.ShowDialog();
}
示例3: DrawSlide2
private void DrawSlide2( DeckTraversalModel traversal, int index, System.Drawing.Rectangle displayBounds, System.Drawing.Graphics g )
{
float width_scale = g.DpiX / 100f;
float height_scale = g.DpiY / 100f;
Rectangle bounds = new Rectangle( 0, 0, (int)(displayBounds.Width * 3f), (int)(displayBounds.Height * 3f) );
// Create an image using temporary graphics and graphics buffer object
Bitmap imageForPrinting = new Bitmap( bounds.Width, bounds.Height );
using( Graphics graphicsImage = Graphics.FromImage( imageForPrinting ) ) {
using( DibGraphicsBuffer dib = new DibGraphicsBuffer() ) {
// Create temporary screen Graphics
System.Windows.Forms.Form tempForm = new System.Windows.Forms.Form();
Graphics screenGraphics = tempForm.CreateGraphics();
// Create temporary Graphics from the Device Independent Bitmap
using( Graphics graphicsTemp = dib.RequestBuffer( screenGraphics, imageForPrinting.Width, imageForPrinting.Height ) ) {
// Save the old state
System.Drawing.Drawing2D.GraphicsState oldState;
using( Synchronizer.Lock( traversal.SyncRoot ) ) {
using( Synchronizer.Lock( traversal.Deck.SyncRoot ) ) {
using( Synchronizer.Lock( traversal.Deck.TableOfContents.SyncRoot ) ) {
TableOfContentsModel.Entry entry = traversal.Deck.TableOfContents.Entries[index];
using( Synchronizer.Lock( entry.Slide.SyncRoot ) ) {
//Draw the background color
//First see if there is a Slide BG, if not, try the Deck. Otherwise, use transparent.
if( entry.Slide.BackgroundColor != Color.Empty ) {
graphicsTemp.Clear( entry.Slide.BackgroundColor );
} else if( traversal.Deck.DeckBackgroundColor != Color.Empty ) {
graphicsTemp.Clear( traversal.Deck.DeckBackgroundColor );
} else {
graphicsTemp.Clear( Color.Transparent );
}
//Get the Slide content and draw it
oldState = graphicsTemp.Save();
Model.Presentation.SlideModel.SheetCollection sheets = entry.Slide.ContentSheets;
for( int i = 0; i < sheets.Count; i++ ) {
SlideDisplayModel display = new SlideDisplayModel( graphicsTemp, null );
Rectangle rect = new Rectangle( 0, 0, bounds.Width, bounds.Height );
Rectangle slide = new Rectangle( rect.X, rect.Y, rect.Width, rect.Height );
float zoom = 1f;
if( entry.Slide != null ) {
slide = entry.Slide.Bounds;
zoom = entry.Slide.Zoom;
}
System.Drawing.Drawing2D.Matrix pixel, ink;
display.FitSlideToBounds( System.Windows.Forms.DockStyle.Fill, rect, zoom, ref slide, out pixel, out ink );
using( Synchronizer.Lock( display.SyncRoot ) ) {
display.Bounds = slide;
display.PixelTransform = pixel;
display.InkTransform = ink;
}
Viewer.Slides.SheetRenderer r = Viewer.Slides.SheetRenderer.ForStaticSheet( display, sheets[i] );
r.Paint( new System.Windows.Forms.PaintEventArgs( graphicsTemp, bounds ) );
r.Dispose();
}
}
}
}
}
//Restore the Old State
graphicsTemp.Restore( oldState );
// Use the buffer to paint onto the final image
dib.PaintBuffer( graphicsImage, 0, 0 );
// Draw this image onto the printer graphics,
// adjusting for printer margins
g.DrawImage( imageForPrinting, displayBounds );
//Cleanup
graphicsTemp.Dispose();
screenGraphics.Dispose();
tempForm.Dispose();
dib.Dispose();
graphicsImage.Dispose();
imageForPrinting.Dispose();
}
}
}
}