async Task SaveToFile(SharpDX.WIC.Bitmap bitmap) // debugging helper method, remove when no longer needed. { var width = bitmap.Size.Width; var height = bitmap.Size.Height; var pixels = new SharpDX.ColorBGRA[bitmap.Size.Width * bitmap.Size.Height]; bitmap.CopyPixels(pixels); var bytes = new byte[width * height * 4]; for (var i = 0; i < pixels.Length; ++i) { bytes[i * 4 + 0] = (byte)pixels[i].B; bytes[i * 4 + 1] = (byte)pixels[i].G; bytes[i * 4 + 2] = (byte)pixels[i].R; bytes[i * 4 + 3] = (byte)pixels[i].A; } var folder = ApplicationData.Current.LocalFolder; var file = await folder.CreateFileAsync("test.png", CreationCollisionOption.ReplaceExisting); using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite)) { var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream); encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)bitmap.Size.Width, (uint)bitmap.Size.Height, 96, 96, bytes); await encoder.FlushAsync(); } }
/// <summary> /// Draws a line strip in screen space with a specified input transformation matrix. /// </summary> /// <param name="vertices"><para>Array of vertices that make up the line. See <see cref="SharpDX.Vector3"/>.</para></param> /// <param name="transform"><para>A scale, rotate, and translate (SRT) matrix for transforming the points. See <see cref="SharpDX.Matrix"/>. If this matrix is a projection matrix, any stippled lines will be drawn with a perspective-correct stippling pattern. Or, you can transform the vertices and use <see cref="SharpDX.Direct3D9.Line.Draw"/> to draw the line with a nonperspective-correct stipple pattern.</para></param> /// <param name="color"><para>Color of the line. See <see cref="SharpDX.Color4"/>.</para></param> /// <returns>If the method succeeds, the return value is <see cref="SharpDX.Direct3D9.ResultCode.Success"/>. If the method fails, the return value can be one of the following: <see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/>, D3DXERR_INVALIDDATA.</returns> /// <unmanaged>HRESULT ID3DXLine::DrawTransform([In] const void* pVertexList,[In] unsigned int dwVertexListCount,[In] const D3DXMATRIX* pTransform,[In] D3DCOLOR Color)</unmanaged> public void DrawTransform(Vector3[] vertices, SharpDX.Matrix transform, SharpDX.ColorBGRA color) { unsafe { fixed(void *pVertexListRef = vertices) DrawTransform((IntPtr)pVertexListRef, vertices.Length, ref transform, color); } }
/// <summary> /// Draws a line strip in screen space. Input is in the form of an array that defines points (of <see cref="SharpDX.Vector2"/>) on the line strip. /// </summary> /// <param name="vertices">No documentation.</param> /// <param name="color">No documentation.</param> /// <unmanaged>HRESULT ID3DXLine::Draw([In] const void* pVertexList,[In] unsigned int dwVertexListCount,[In] D3DCOLOR Color)</unmanaged> public void Draw(SharpDX.Vector2[] vertices, SharpDX.ColorBGRA color) { unsafe { fixed(void *pVertexListRef = vertices) Draw((IntPtr)pVertexListRef, vertices.Length, color); } }
/// <summary> /// Draws a line strip in screen space with a specified input transformation matrix. /// </summary> /// <param name="vertices"><para>Array of vertices that make up the line. See <see cref="SharpDX.Vector3"/>.</para></param> /// <param name="transform"><para>A scale, rotate, and translate (SRT) matrix for transforming the points. See <see cref="SharpDX.Matrix"/>. If this matrix is a projection matrix, any stippled lines will be drawn with a perspective-correct stippling pattern. Or, you can transform the vertices and use <see cref="SharpDX.Direct3D9.Line.Draw"/> to draw the line with a nonperspective-correct stipple pattern.</para></param> /// <param name="color"><para>Color of the line. See <see cref="SharpDX.Color4"/>.</para></param> /// <returns>If the method succeeds, the return value is <see cref="SharpDX.Direct3D9.ResultCode.Success"/>. If the method fails, the return value can be one of the following: <see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/>, D3DXERR_INVALIDDATA.</returns> /// <unmanaged>HRESULT ID3DXLine::DrawTransform([In] const void* pVertexList,[In] unsigned int dwVertexListCount,[In] const D3DXMATRIX* pTransform,[In] D3DCOLOR Color)</unmanaged> public void DrawTransform <T>(T[] vertices, SharpDX.Matrix transform, SharpDX.ColorBGRA color) where T : struct { unsafe { if (Utilities.SizeOf <T>() != sizeof(Vector3)) { throw new ArgumentException("Invalid size for T. Must be 3 floats (12 bytes)"); } DrawTransform((IntPtr)Interop.Fixed(vertices), vertices.Length, ref transform, color); } }
/// <summary> /// <p>Adds a sprite to the list of batched sprites.</p> /// </summary> /// <param name="textureRef"><dd> <p>Pointer to an <strong><see cref="SharpDX.Direct3D9.Texture"/></strong> interface that represents the sprite texture.</p> </dd></param> /// <param name="srcRectRef"><dd> <p>Pointer to a <strong><see cref="SharpDX.Rectangle"/></strong> structure that indicates the portion of the source texture to use for the sprite. If this parameter is <strong><c>null</c></strong>, then the entire source image is used for the sprite.</p> </dd></param> /// <param name="centerRef"><dd> <p>Pointer to a <strong><see cref="SharpDX.Vector3"/></strong> vector that identifies the center of the sprite. If this argument is <strong><c>null</c></strong>, the point (0,0,0) is used, which is the upper-left corner.</p> </dd></param> /// <param name="positionRef"><dd> <p>Pointer to a <strong><see cref="SharpDX.Vector3"/></strong> vector that identifies the position of the sprite. If this argument is <strong><c>null</c></strong>, the point (0,0,0) is used, which is the upper-left corner.</p> </dd></param> /// <param name="color"><dd> <p> <strong><see cref="SharpDX.Color4"/></strong> type. The color and alpha channels are modulated by this value. A value of 0xFFFFFFFF maintains the original source color and alpha data. Use the <strong>D3DCOLOR_RGBA</strong> macro to help generate this color.</p> </dd></param> /// <returns><p>If the method succeeds, the return value is <see cref="SharpDX.Result.Ok"/>. If the method fails, the return value can be one of the following: <see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/>, D3DXERR_INVALIDDATA.</p></returns> /// <remarks> /// <p>To scale, rotate, or translate a sprite, call <strong><see cref="SharpDX.Direct3D9.Sprite.SetTransform"/></strong> with a matrix that contains the scale, rotate, and translate (SRT) values, before calling <see cref="SharpDX.Direct3D9.Sprite.Draw"/>. For information about setting SRT values in a matrix, see Matrix Transforms.</p> /// </remarks> /// <msdn-id>bb174251</msdn-id> /// <unmanaged>HRESULT ID3DXSprite::Draw([In] IDirect3DTexture9* pTexture,[In] const RECT* pSrcRect,[In] const D3DXVECTOR3* pCenter,[In] const D3DXVECTOR3* pPosition,[In] D3DCOLOR Color)</unmanaged> /// <unmanaged-short>ID3DXSprite::Draw</unmanaged-short> public unsafe void Draw(SharpDX.Direct3D9.Texture textureRef, SharpDX.ColorBGRA color, SharpDX.Rectangle?srcRectRef = null, SharpDX.Vector3?centerRef = null, SharpDX.Vector3?positionRef = null) { SharpDX.Rectangle localRect = default(Rectangle); SharpDX.Vector3 localCenter; SharpDX.Vector3 localPosition; if (srcRectRef.HasValue) { localRect = srcRectRef.Value; } if (centerRef.HasValue) { localCenter = centerRef.Value; } if (positionRef.HasValue) { localPosition = positionRef.Value; } Draw(textureRef, srcRectRef.HasValue ? (IntPtr)(void *)&localRect : IntPtr.Zero, centerRef.HasValue ? (IntPtr)(void *)&localCenter : IntPtr.Zero, positionRef.HasValue ? (IntPtr)(void *)&localPosition : IntPtr.Zero, color); }
public void Render() { // Note: there ought to be a more efficient way to do this, as this is // critical. However, after much searching, the only way I found to // convert a Wic bitmap to a BitmapImage was by serializing to/from // a memory stream. if (!isRendering && GraphicsHandler != null && GraphicsHandler.Control != null) { isRendering = true; GraphicsHandler.BeginDrawing(); Callback.OnPaint(Widget, new PaintEventArgs(graphics, Widget.Bounds)); // renders into the bitmap GraphicsHandler.EndDrawing(); var bitmap = GraphicsHandler.Image; if (bitmap != null) { var bitmapHandler = bitmap.Handler as BitmapHandler; var bitmapObject = bitmapHandler.Control; var size = bitmapObject.Size; var writeableBitmap = new WriteableBitmap(size.Width, size.Height); // Get a pointer to the bitmap pixels unsafe { byte *ptr = null; ((IBufferByteAccess)writeableBitmap.PixelBuffer).Buffer(out ptr); var len = size.Width * size.Height; var pixels = new SharpDX.ColorBGRA[len]; fixed(SharpDX.ColorBGRA *pixelsPtr = &pixels[0]) { bitmapObject.CopyPixels(pixels); CopyMemory((IntPtr)ptr, (IntPtr)pixelsPtr, (uint)len * 4); } } Control.Source = writeableBitmap; } isRendering = false; } }
private static void TextObj(string str, Obj_AI_Base target, SharpDX.ColorBGRA color) { Drawing.DrawText(str, target.Position.WorldToScreen() + new SharpDX.Vector2(0, -50), color); }
public static void DrawTextBold(Font vFont, String vText, float vPosX, float vPosY, SharpDX.ColorBGRA vColor) { vFont.DrawText(null, vText, (int)vPosX, (int)vPosY, vColor); }
/// <summary> /// <p>Adds a sprite to the list of batched sprites.</p> /// </summary> /// <param name="textureRef"><dd> <p>Pointer to an <strong><see cref="SharpDX.Direct3D9.Texture"/></strong> interface that represents the sprite texture.</p> </dd></param> /// <param name="color"><dd> <p> <strong><see cref="SharpDX.Color4"/></strong> type. The color and alpha channels are modulated by this value. A value of 0xFFFFFFFF maintains the original source color and alpha data. Use the <strong>D3DCOLOR_RGBA</strong> macro to help generate this color.</p> </dd></param> /// <returns><p>If the method succeeds, the return value is <see cref="SharpDX.Result.Ok"/>. If the method fails, the return value can be one of the following: <see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/>, D3DXERR_INVALIDDATA.</p></returns> /// <remarks> /// <p>To scale, rotate, or translate a sprite, call <strong><see cref="SharpDX.Direct3D9.Sprite.SetTransform"/></strong> with a matrix that contains the scale, rotate, and translate (SRT) values, before calling <see cref="SharpDX.Direct3D9.Sprite.Draw"/>. For information about setting SRT values in a matrix, see Matrix Transforms.</p> /// </remarks> /// <msdn-id>bb174251</msdn-id> /// <unmanaged>HRESULT ID3DXSprite::Draw([In] IDirect3DTexture9* pTexture,[In] const RECT* pSrcRect,[In] const D3DXVECTOR3* pCenter,[In] const D3DXVECTOR3* pPosition,[In] D3DCOLOR Color)</unmanaged> /// <unmanaged-short>ID3DXSprite::Draw</unmanaged-short> public void Draw(SharpDX.Direct3D9.Texture textureRef, SharpDX.ColorBGRA color) { Draw(textureRef, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, color); }
public static void DrawText(Font fuente, String text, float posx, float posy, SharpDX.ColorBGRA color) { fuente.DrawText(null, text, (int)posx, (int)posy, color); }
public void display(VideoFrame videoFrame, Color backColor, RenderMode mode) { lock (renderLock) { if (device == null) { return; } SharpDX.Result deviceStatus = device.TestCooperativeLevel(); if (deviceStatus.Success == true) { try { SharpDX.ColorBGRA backColorDX = new SharpDX.ColorBGRA(backColor.R, backColor.G, backColor.B, backColor.A); device.Clear(D3D.ClearFlags.Target, backColorDX, 1.0f, 0); if (mode == RenderMode.CLEAR_SCREEN) { device.Present(); return; } device.BeginScene(); SharpDX.Rectangle videoSourceRect = new SharpDX.Rectangle(); if (mode == RenderMode.NORMAL) { videoSourceRect = new SharpDX.Rectangle(0, 0, videoFrame.Width, videoFrame.Height); SharpDX.DataRectangle stream = offscreen.LockRectangle(LockFlags.None); videoFrame.copyFrameDataToSurface(stream.DataPointer, stream.Pitch); offscreen.UnlockRectangle(); } else if (mode == RenderMode.PAUSED) { videoSourceRect = new SharpDX.Rectangle(0, 0, offscreen.Description.Width, offscreen.Description.Height); } videoDestRect = getVideoDestRect(backBuffer); device.StretchRectangle(offscreen, videoSourceRect, backBuffer, videoDestRect, D3D.TextureFilter.Linear); drawText(); device.EndScene(); device.Present(); RenderMode = mode; } catch (SharpDX.SharpDXException) { //log.Info("lost direct3d device", e); deviceStatus = device.TestCooperativeLevel(); } } if (deviceStatus.Code == D3D.ResultCode.DeviceLost.Result) { //Can't Reset yet, wait for a bit } else if (deviceStatus.Code == D3D.ResultCode.DeviceNotReset.Result) { resetDevice(); } } }
public void display(VideoFrame videoFrame, Color backColor, RenderMode mode) { lock (renderLock) { if (device == null) return; SharpDX.Result deviceStatus = device.TestCooperativeLevel(); if (deviceStatus.Success == true) { try { SharpDX.ColorBGRA backColorDX = new SharpDX.ColorBGRA(backColor.R, backColor.G, backColor.B, backColor.A); device.Clear(D3D.ClearFlags.Target, backColorDX, 1.0f, 0); if (mode == RenderMode.CLEAR_SCREEN) { device.Present(); return; } device.BeginScene(); SharpDX.Rectangle videoSourceRect = new SharpDX.Rectangle(); if (mode == RenderMode.NORMAL) { videoSourceRect = new SharpDX.Rectangle(0, 0, videoFrame.Width, videoFrame.Height); SharpDX.DataRectangle stream = offscreen.LockRectangle(LockFlags.None); videoFrame.copyFrameDataToSurface(stream.DataPointer, stream.Pitch); offscreen.UnlockRectangle(); } else if (mode == RenderMode.PAUSED) { videoSourceRect = new SharpDX.Rectangle(0, 0, offscreen.Description.Width, offscreen.Description.Height); } videoDestRect = getVideoDestRect(backBuffer); device.StretchRectangle(offscreen, videoSourceRect, backBuffer, videoDestRect, D3D.TextureFilter.Linear); drawText(); device.EndScene(); device.Present(); RenderMode = mode; } catch (SharpDX.SharpDXException) { //log.Info("lost direct3d device", e); deviceStatus = device.TestCooperativeLevel(); } } if (deviceStatus.Code == D3D.ResultCode.DeviceLost.Result) { //Can't Reset yet, wait for a bit } else if (deviceStatus.Code == D3D.ResultCode.DeviceNotReset.Result) { resetDevice(); } } }