Surface.GetGraphics() Method (Microsoft.DirectX.Direct3D)

Retrieves a device context.

Definition

Visual Basic Public Function GetGraphics() As GraphicsLeave Site
C# public GraphicsLeave Site GetGraphics();
C++ public:
GraphicsLeave SiteGetGraphics();
JScript public function GetGraphics() : GraphicsLeave Site;

Return Value

System.Drawing.Graphics
A GraphicsLeave Site object that represents the device context for the surface.

Remarks

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.

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 GraphicsLeave Site 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.

See Also