![]() |
![]() |
![]() |
Surface.GetGraphics Method |
Language: |
Retrieves a device context.
Visual Basic .NET Public Function GetGraphics() As Graphics C# public Graphics GetGraphics(); Managed C++ public: Graphics* GetGraphics(); JScript .NET public function GetGraphics() : Graphics;
System.Drawing.Graphics . A Graphics
object that represents the device context for the surface.
The following restrictions apply.
- The GetGraphics method is valid only on the following formats: Format.R5G6B5, Format.X1R5G5B5, Format.R8G8B8, and Format.X8R8G8B8. Formats that contain alpha are not supported because the Microsoft® Windows® Graphics Device Interface (GDI) implementations do not have a well-defined behavior on the alpha channel. For more information about formats, see Format.
- Only one device context per surface can be returned at a time.
- This method fails if the surface is already locked. It also fails if the surface is a member of a mipmap or cube map, and any other mipmap or cube map member is locked.
- This method fails on render targets unless they were created as lockable (or, in the case of back buffers, with PresentFlag.LockableBackBuffer).
- It fails on surfaces created with Pool.Default, unless they are Usage.Dynamic or are lockable render targets.
- It fails on surfaces created with Pool.Scratch.
When a device context is outstanding on a surface, the application cannot call the following methods.
- CubeTexture.LockRectangle
- Device.ColorFill
- Device.StretchRectangle
- Device.UpdateSurface
- Device.UpdateTexture
- Surface.LockRectangle
- SwapChain.Present (on a swap chain that contains the surface)
- Texture.LockRectangle
The GetGraphics method causes an implicit lock; do not retain the device context for later use. Call Surface.ReleaseGraphics to release it.
It is valid to call Surface.GetGraphics and Surface.ReleaseGraphics on levels of a mipmap or cube map; however, these calls are slow to all mip levels except the topmost level, and GDI operations to these mip levels are not accelerated.
The Graphics
object provides access to Microsoft Win32® and GDI functionality.
Exceptions
InvalidCallException The method call is invalid. For example, a method's parameter might contain an invalid value.
Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center