public DrawBitmap ( Bitmap bitmap, float opacity, BitmapInterpolationMode interpolationMode ) : void | ||
bitmap | Bitmap | The bitmap to render. |
opacity | float | A value between 0.0f and 1.0f, inclusive, that specifies an opacity value to apply to the bitmap; this value is multiplied against the alpha values of the bitmap's contents. The default value is 1.0f. |
interpolationMode | BitmapInterpolationMode | The interpolation mode to use if the bitmap is scaled or rotated by the drawing operation. The default value is |
return | void |
public override void Render(RenderTarget pRender, float pPercent) { pRender.Transform = Matrix3x2.Identity; pRender.DrawText("dx:" + dx + " dy:" + dy + " da:" + da, Constants.SmallFont, new RectangleF(0, 0, 200, 50), new SolidColorBrush(pRender, Color4.Black)); pRender.Transform = Matrix3x2.Rotation(MathUtil.DegreesToRadians(-a + 180)) * Matrix3x2.Translation(x, y); pRender.DrawBitmap(ShipBitmap, new RectangleF(-17, -17, 34, 34), 1.0f, BitmapInterpolationMode.Linear); }
/// <summary> /// Draws the given bitmap. /// </summary> /// <param name="bitmap">The bitmap.</param> /// <param name="destinationRectangle">The target rectangle where to draw the bitmap.</param> /// <param name="opacity">The opacity.</param> /// <param name="interpolationMode">The interpolation mode.</param> /// <param name="frameIndex">The frame of the bitmap to be rendered.</param> public void DrawBitmap( BitmapResource bitmap, RectangleF destinationRectangle, float opacity = 1f, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.NearestNeighbor, int frameIndex = 0) { if (m_renderTarget == null) { return; } bitmap.EnsureNotNull(nameof(bitmap)); destinationRectangle.EnsureNotEmpty(nameof(destinationRectangle)); opacity.EnsureInRange(0f, 1f, nameof(opacity)); int bitmapFrameCount = bitmap.TotalFrameCount; frameIndex.EnsureInRange(0, bitmapFrameCount - 1, nameof(frameIndex)); // Render the bitmap if (bitmapFrameCount > 1) { // Get the native bitmap object first // (if not, we may not have loaded it already and therefore // missing size information) D2D.Bitmap nativeBitmap = bitmap.GetBitmap(m_device); // Calculate source rectangle int framesX = bitmap.FrameCountX; int xFrameIndex = frameIndex % framesX; int yFrameIndex = (frameIndex - xFrameIndex) / framesX; int singleFrameWidth = bitmap.SingleFramePixelWidth; int singleFrameHeight = bitmap.SingleFramePixelHeight; RectangleF sourceRectangle = new RectangleF( xFrameIndex * singleFrameWidth, yFrameIndex * singleFrameHeight, singleFrameWidth, singleFrameHeight); // Render tiled bitmap m_renderTarget.DrawBitmap( nativeBitmap, destinationRectangle.ToDXRectangle(), opacity, (D2D.BitmapInterpolationMode)interpolationMode, sourceRectangle.ToDXRectangle()); } else { // Render non-tiled bitmap m_renderTarget.DrawBitmap( bitmap.GetBitmap(m_device), destinationRectangle.ToDXRectangle(), opacity, (D2D.BitmapInterpolationMode)interpolationMode); } }
/// <summary> /// Draw a bitmap on the Render Target (Game Launcher Window). /// </summary> /// <param name="target">Destination render target which is ready to be drawn.</param> /// <param name="bitmapData">Bitmap data.</param> /// <param name="windowSize">Destination window size.</param> /// <param name="rect">Which rectangle range on the render target(window) should be drawn by the bitmap?</param> /// <param name="opacity">What opacity we should use to draw the bitmap? (Range: [0,1])</param> /// <param name="isFlushInstantly">Should we flush render target instantly after drawing the bitmap?</param> public static void DrawBitmap(D2D.RenderTarget target, byte[] bitmapData, Size2F windowSize, RawRectangleF rect, float opacity = 1.0f, bool isFlushInstantly = true) { var stream = new MemoryStream(bitmapData); stream.Seek(0, SeekOrigin.Begin); var bitmapWrapper = (Bitmap)Image2.FromStream(stream); if (bitmapWrapper.Width > windowSize.Width) { bitmapWrapper = bitmapWrapper.ScaleBitmap((double)windowSize.Width / bitmapWrapper.Width); } else if (bitmapWrapper.Height > windowSize.Height) { bitmapWrapper = bitmapWrapper.ScaleBitmap((double)windowSize.Height / bitmapWrapper.Height); } var bitmap = target.LoadD2DBitmapFromBitmap(bitmapWrapper); if (bitmap != null) { target.DrawBitmap(bitmap, opacity, D2D.BitmapInterpolationMode.Linear, rect); if (isFlushInstantly) { target.Flush(); } } }
public static void DrawBitmap(this SharpDX.Direct2D1.RenderTarget target, D2DBitmap bitmap, float destX, float destY, float destWidth, float destHeight, float srcX, float srcY, float srcWidth, float srcHeight, float opacity) { var destRect = new RawRectangleF(destX, destY, destX + destWidth, destY + destHeight); var srcRect = new RawRectangleF(srcX, srcY, srcX + srcWidth, srcY + srcHeight); target.DrawBitmap(bitmap.NativeBitmap, destRect, opacity, BitmapInterpolationMode.Linear, srcRect); }
private void OnRender() { lock (_renderContextLock) { if (_renderTarget?.IsDisposed ?? true) { return; } _renderTarget.BeginDraw(); _renderTarget.Clear(_backgroundColor); if (_paradigmStarted) // Draw blocks { foreach (var block in _blocks) { if (block.BorderWidth > 0) { _solidColorBrush.Color = _blockBorderColor; _renderTarget.FillRectangle(block.BorderRect, _solidColorBrush); } if (_bitmap != null) { _solidColorBrush.Color = _blockNormalColor; _renderTarget.FillRectangle(block.ContentRect, _solidColorBrush); if (block.Actived) { _renderTarget.DrawBitmap(_bitmap, block.ContentRect, 1, D2D1.BitmapInterpolationMode.Linear); } } else { _solidColorBrush.Color = block.Actived ? _blockActivedColor : _blockNormalColor; _renderTarget.FillRectangle(block.ContentRect, _solidColorBrush); } if (block.Target) { _solidColorBrush.Color = _blockBorderColor; _renderTarget.FillEllipse(block.CenterPointEllipse, _solidColorBrush); } } } else if (!(_displayText?.IsBlank() ?? true)) // Draw text { _solidColorBrush.Color = _fontColor; _renderTarget.DrawText(_displayText, _textFormat, new RawRectangleF(0, 0, Width, Height), _solidColorBrush, D2D1.DrawTextOptions.None); } _renderTarget.EndDraw(); _swapChain.Present(1, DXGI.PresentFlags.None, _presentParameters); } }
internal void Render(RenderTarget d2dRenderTarget) { InitializeResources(d2dRenderTarget); d2dRenderTarget.Transform = Matrix.Translation(Position); d2dRenderTarget.DrawBitmap(texture,1, BitmapInterpolationMode.Linear); //d2dRenderTarget.FillRectangle(new RectangleF(-20, -20, 20, 20), Fill); //d2dRenderTarget.DrawRectangle(new RectangleF(-20, -20, 20, 20), Stroke); }
public void drawImage(System.Drawing.Image _bmp, int x, int y, int w, int h, float alpha) { AddDrawRequest((target) => { System.Drawing.Bitmap bmp = null; bool needDispose = false; if (_bmp is System.Drawing.Bitmap) { bmp = _bmp as System.Drawing.Bitmap; } else { bmp = new System.Drawing.Bitmap(_bmp); needDispose = true; } if (bmp.PixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppPArgb && bmp.PixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb) { needDispose = true; System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(_bmp.Width, _bmp.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBmp)) { g.DrawImage(_bmp, 0, 0, newBmp.Width, newBmp.Height); g.Flush(); } bmp = newBmp; } var mem = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bmp.PixelFormat); var bitmapProperties = new BitmapProperties(new PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Ignore)); using (Bitmap gameBitmap = new Bitmap(d2dRenderTarget, new Size2(bmp.Width, bmp.Height), bitmapProperties)) { gameBitmap.CopyFromMemory(mem.Scan0, mem.Stride); d2dRenderTarget.DrawBitmap(gameBitmap, new RawRectangleF(x, y, x + w, y + h), alpha, BitmapInterpolationMode.NearestNeighbor); } bmp.UnlockBits(mem); if (needDispose) { bmp.Dispose(); } }); }
/// <summary> /// Draws a bitmap image. /// </summary> /// <param name="source">The bitmap image.</param> /// <param name="opacity">The opacity to draw with.</param> /// <param name="sourceRect">The rect in the image to draw.</param> /// <param name="destRect">The rect in the output to draw to.</param> public void DrawImage(IBitmapImpl source, double opacity, Rect sourceRect, Rect destRect) { using (var d2d = ((BitmapImpl)source).GetDirect2DBitmap(_renderTarget)) { _renderTarget.DrawBitmap( d2d.Value, destRect.ToSharpDX(), (float)opacity, BitmapInterpolationMode.Linear, sourceRect.ToSharpDX()); } }
/// <summary> /// Draws a bitmap image. /// </summary> /// <param name="source">The bitmap image.</param> /// <param name="opacity">The opacity to draw with.</param> /// <param name="sourceRect">The rect in the image to draw.</param> /// <param name="destRect">The rect in the output to draw to.</param> public void DrawImage(IBitmap source, double opacity, Rect sourceRect, Rect destRect) { BitmapImpl impl = (BitmapImpl)source.PlatformImpl; Bitmap d2d = impl.GetDirect2DBitmap(_renderTarget); _renderTarget.DrawBitmap( d2d, destRect.ToSharpDX(), (float)opacity, BitmapInterpolationMode.Linear, sourceRect.ToSharpDX()); }
public void OnRender(RenderTarget target) { target.FillRectangle(new RectangleF(0, 0, mSize.X, mSize.Y), Brushes.Solid[0xFF333333]); if (mLoadingImage == null || mLoadingImage.IsLoaded == false) return; target.DrawBitmap(mLoadingImage, mTargetRectangle, 1.0f, BitmapInterpolationMode.Linear); if (mLoadingBarBackground == null || !mLoadingBarBackground.IsLoaded) return; var startPosY = mTargetRectangle.Y + mTargetRectangle.Height * 0.8f + 13; var startPosX = mTargetRectangle.X + (mTargetRectangle.Width - mLoadingBarBackground.Width * 1.2f + 80) / 2.0f; target.DrawBitmap(mLoadingBarFill, new RectangleF(startPosX, startPosY, (mLoadingBarBackground.Width * 1.2f - 80.0f) * mProgress, 40), 1.0f, BitmapInterpolationMode.Linear); startPosY = mTargetRectangle.Y + mTargetRectangle.Height * 0.8f; startPosX = mTargetRectangle.X + (mTargetRectangle.Width - mLoadingBarBackground.Width * 1.2f) / 2.0f; target.DrawBitmap(mLoadingBarBackground, new RectangleF(startPosX, startPosY, mLoadingBarBackground.Width * 1.2f, mLoadingBarBackground.Height), 1.0f, BitmapInterpolationMode.Linear); }
/// <summary> /// Draws a bitmap image. /// </summary> /// <param name="source">The bitmap image.</param> /// <param name="opacity">The opacity to draw with.</param> /// <param name="sourceRect">The rect in the image to draw.</param> /// <param name="destRect">The rect in the output to draw to.</param> /// <param name="bitmapInterpolationMode">The bitmap interpolation mode.</param> public void DrawImage(IRef <IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode) { using (var d2d = ((BitmapImpl)source.Item).GetDirect2DBitmap(_renderTarget)) { var interpolationMode = GetInterpolationMode(bitmapInterpolationMode); _renderTarget.DrawBitmap( d2d.Value, destRect.ToSharpDX(), (float)opacity, interpolationMode, sourceRect.ToSharpDX()); } }
protected override void Draw(D2D1.RenderTarget renderTarget) { renderTarget.Clear(Color.Black); lock (this) if (_bitmap != null) { var scale = Math.Min(ClientSize.Width / _bitmap.Size.Width, ClientSize.Height / _bitmap.Size.Height); var scaledWidth = _bitmap.Size.Width * scale; var scaledHeight = _bitmap.Size.Height * scale; var left = (ClientSize.Width - scaledWidth) / 2; var top = (ClientSize.Height - scaledHeight) / 2; var destRect = new RawRectangleF(left, top, left + scaledWidth, top + scaledHeight); renderTarget.DrawBitmap(_bitmap, destRect, 1, D2D1.BitmapInterpolationMode.NearestNeighbor); } }
public void EndDraw() { if (!IsFinished) { Target.Transform = Matrix3x2.Translation(-_x.RealTime - _originOffsetX, -_y.RealTime - _originOffsetY) * Matrix3x2.Scaling(_vx.RealTime, _vy.RealTime) * Matrix3x2.Rotation(_r.RealTime) * Matrix3x2.Translation(_x.RealTime + _originOffsetX, _y.RealTime + _originOffsetY); if (_f.RealTime > 0) { Target.DrawBitmap(Bitmap, Rect.RealTime, _f.RealTime, D2D.BitmapInterpolationMode.Linear /*, RtInRect*/); //todo: bug #if DEBUG Target.DrawRectangle(Rect.RealTime, _redBrush, 1); #endif } Target.Transform = new Matrix3x2(1, 0, 0, 1, 0, 0); } else { Target.Transform = Matrix3x2.Translation(-_x.RealTime - _originOffsetX, -_y.RealTime - _originOffsetY) * Matrix3x2.Scaling(_vx.RealTime, _vy.RealTime) * Matrix3x2.Rotation(_r.RealTime) * Matrix3x2.Translation(_x.RealTime + _originOffsetX, _y.RealTime + _originOffsetY); //if (EnableLog) LogUtil.LogInfo(string.Format("[{0},{1},{2},{3}]", InRect.RealTime.Left, // InRect.RealTime.Top, InRect.RealTime.Right, InRect.RealTime.Bottom)); //Target.FillOpacityMask(Bitmap, _brush, D2D.OpacityMaskContent.TextGdiCompatible, Rect.Target, null); if (_f.Target > 0) { Target.DrawBitmap(Bitmap, Rect.Target, _f.Target, D2D.BitmapInterpolationMode.Linear /*, TarInRect*/); //todo: bug #if DEBUG Target.DrawRectangle(Rect.Target, _redBrush, 1); #endif } Target.Transform = new Matrix3x2(1, 0, 0, 1, 0, 0); } }
/// <summary> /// Present the device. /// </summary> public void Present() { if (renderTarget != null) { renderTarget.BeginDraw(); for (int i = 0; i < layers.Count; i++) { if (i == 5) { renderTarget.Transform = SharpDX.Matrix.Translation(padding.Left, padding.Top, 0); } renderTarget.DrawBitmap(layers[i].Bitmap, 1, BitmapInterpolationMode.Linear); renderTarget.Transform = SharpDX.Matrix.Identity; } renderTarget.EndDraw(); } }
public void OnRender(RenderTarget target) { if (gBorder == null) InitBrushes(); if(mIsHovered || mIsClicked) { if (mIsClicked) target.FillRectangle(mTargetRect, gClick); else if (mIsHovered) target.FillRectangle(mTargetRect, gHover); target.DrawRectangle(mTargetRect, gBorder); } target.DrawBitmap(mImage.GetBitmap(), mImageRect, 1.0f, BitmapInterpolationMode.Linear); }
/// <summary> /// Draw a bitmap on the Render Target (Game Launcher Window). /// </summary> /// <param name="target">Destination render target which is ready to be drawn.</param> /// <param name="bitmapData">Bitmap data.</param> /// <param name="rect">Which rectangle range on the render target(window) should be drawn by the bitmap?</param> /// <param name="scaleMultiple">Which multiple should be used to scale the bitmap?</param> /// <param name="opacity">What opacity we should use to draw the bitmap? (Range: [0,1])</param> /// <param name="isFlushInstantly">Should we flush render target instantly after drawing the bitmap?</param> public static void DrawBitmap(D2D.RenderTarget target, byte[] bitmapData, RawRectangleF rect, float scaleMultiple, float opacity = 1.0f, bool isFlushInstantly = true) { var stream = new MemoryStream(bitmapData); stream.Seek(0, SeekOrigin.Begin); var bitmapWrapper = (Bitmap)Image2.FromStream(stream); bitmapWrapper = bitmapWrapper.ScaleBitmap(scaleMultiple); var bitmap = target.LoadD2DBitmapFromBitmap(bitmapWrapper); if (bitmap != null) { target.DrawBitmap(bitmap, opacity, D2D.BitmapInterpolationMode.Linear, rect); if (isFlushInstantly) { target.Flush(); } } }
//--------------------------------------------------------------------------------------------------------- /// <summary> /// Рисование изображения /// </summary> //--------------------------------------------------------------------------------------------------------- public override void Draw() { Direct2D.RenderTarget render_target = XDirect2DManager.D2DRenderTarget; if (mIsFilled) { render_target.FillRectangle(mBoundsRect.ToRawRectF(), mFill.D2DBrush); } if (mD2DBitmap != null) { render_target.DrawBitmap(mD2DBitmap, mBoundsRect.ToRawRectF(), 1.0f, Direct2D.BitmapInterpolationMode.NearestNeighbor); } if (mIsStroked) { render_target.DrawRectangle(mBoundsRect.ToRawRectF(), mStroke.Brush.D2DBrush, mStroke.Thickness, mStroke.mD2DStrokeStyle); } }
internal static async Task Render(CompositionEngine compositionEngine, SharpDX.Direct2D1.RenderTarget renderTarget, Jupiter.FrameworkElement rootElement, Jupiter.Controls.Image image) { var rect = image.GetBoundingRect(rootElement).ToSharpDX(); if (rect.Width == 0 || rect.Height == 0) { return; } var bitmap = await image.Source.ToSharpDX(renderTarget); if (bitmap == null) { return; } try { var layer = image.CreateAndPushLayerIfNecessary(renderTarget, rootElement); renderTarget.DrawBitmap( bitmap, rect, (float)image.Opacity, D2D.BitmapInterpolationMode.Linear); if (layer != null) { renderTarget.PopLayer(); layer.Dispose(); } } finally { bitmap.Dispose(); } }
internal static async Task Render(CompositionEngine compositionEngine, SharpDX.Direct2D1.RenderTarget renderTarget, Jupiter.FrameworkElement rootElement, Jupiter.Controls.Image image) { var rect = image.GetBoundingRect(rootElement).ToSharpDX(); if (rect.Width == 0 || rect.Height == 0) { return; } var bitmap = await image.Source.ToSharpDX(renderTarget); if (bitmap == null) { return; } try { //var layer = new Layer(renderTarget); //var layerParameters = new LayerParameters(); //layerParameters.ContentBounds = rect; //renderTarget.PushLayer(ref layerParameters, layer); renderTarget.DrawBitmap( bitmap, rect, (float)image.Opacity, D2D.BitmapInterpolationMode.Linear); //renderTarget.PopLayer(); } finally { bitmap.Dispose(); } }
public static void DrawBitmap(this SharpDX.Direct2D1.RenderTarget target, D2DBitmap bitmap, float destX, float destY) { target.DrawBitmap(bitmap, destX, destY, bitmap.Width, bitmap.Height); }
public void EndDraw() { if (_sbObj.IsFinished || _timing.Offset < _sbObj.MinTime || _sbObj.F.RealTime <= 0) { if (_flag) { _sbObj.ResetRealTime(); _flag = false; } return; } _flag = true; if (_sbObj is AnimatedObject ani && _timing.Offset >= ani.MinTime && _timing.Offset <= ani.MaxTime) { int imgIndex; if (ani.Loop) { imgIndex = (int)((_timing.Offset - ani.MinTime) / ani.Delay % ani.Times); } else { imgIndex = (int)((_timing.Offset - ani.MinTime) / ani.Delay); if (imgIndex >= ani.Times) { imgIndex = ani.Times - 1; } } if (imgIndex != ani.PrevIndex) { ani.PrevIndex = imgIndex; ani.Texture = ani.TextureList[imgIndex]; } } var translateMtx = Matrix3x2.Translation(-_sbObj.X.RealTime, -_sbObj.Y.RealTime); var scaleMtx = Matrix3x2.Scaling((_sbObj.UseH ? -1 : 1) * _sbObj.Vx.RealTime, (_sbObj.UseV ? -1 : 1) * _sbObj.Vy.RealTime); var rotateMtx = Matrix3x2.Rotation(_sbObj.Rad.RealTime); var negTranslateMtx = Matrix3x2.Translation(_sbObj.X.RealTime, _sbObj.Y.RealTime); _target.Transform = translateMtx * scaleMtx * rotateMtx * negTranslateMtx; float rectL = _sbObj.Rect.RealTime.Left - _sbObj.OriginOffsetX - (_sbObj.UseH ? 2 * (_sbObj.Width / 2 - _sbObj.OriginOffsetX) : 0); float rectT = _sbObj.Rect.RealTime.Top - _sbObj.OriginOffsetY - (_sbObj.UseV ? 2 * (_sbObj.Height / 2 - _sbObj.OriginOffsetY) : 0); float rectW = _sbObj.Rect.RealTime.Right - _sbObj.Rect.RealTime.Left; float rectH = _sbObj.Rect.RealTime.Bottom - _sbObj.Rect.RealTime.Top; var realRect = new RectangleF(rectL, rectT, rectW, rectH); if (_sbObj.Texture != null) { if (_sbObj.R.RealTime != 255 || _sbObj.G.RealTime != 255 || _sbObj.B.RealTime != 255) { //JUST FAKE THING var sb = new D2D.SolidColorBrush(_target, new Mathe.RawColor4(_sbObj.R.RealTime / 255f, _sbObj.G.RealTime / 255f, _sbObj.B.RealTime / 255f, _sbObj.F.RealTime)); _target.FillOpacityMask(_sbObj.Texture, sb, D2D.OpacityMaskContent.Graphics, realRect, null); sb.Dispose(); sb = null; } else { _target.DrawBitmap(_sbObj.Texture, realRect, _sbObj.F.RealTime, D2D.BitmapInterpolationMode.Linear); } } #if DEBUG //_target.DrawRectangle(realRect, _redBrush, 1); #endif _target.Transform = new Matrix3x2(1, 0, 0, 1, 0, 0); }
public void DrawImage(IImage image, Rect frame, double alpha = 1.0) { var i = GetImage(image); renderTarget.DrawBitmap(i, frame.ToRectangleF(), (float)alpha, D2D1.BitmapInterpolationMode.Linear); }
private unsafe void DrawCursor(SharpDX.Direct2D1.RenderTarget renderTarger, CursorInfo cursor) { var position = cursor.Position; var shapeBuff = cursor.PtrShapeBuffer; var shapeInfo = cursor.ShapeInfo; int width = shapeInfo.Width; int height = shapeInfo.Height; int pitch = shapeInfo.Pitch; int left = position.X; int top = position.Y; int right = position.X + width; int bottom = position.Y + height; //logger.Debug(left + " " + top + " " + right + " " + bottom); if (cursor.ShapeInfo.Type == (int)ShapeType.DXGI_OUTDUPL_POINTER_SHAPE_TYPE_COLOR) { var data = new DataPointer(shapeBuff, height * pitch); var prop = new Direct2D.BitmapProperties(new Direct2D.PixelFormat(Format.B8G8R8A8_UNorm, Direct2D.AlphaMode.Premultiplied)); var size = new Size2(width, height); var cursorBits = new Direct2D.Bitmap(renderTarger, size, data, pitch, prop); try { var cursorRect = new RawRectangleF(left, top, right, bottom); renderTarger.DrawBitmap(cursorBits, cursorRect, 1.0f, Direct2D.BitmapInterpolationMode.Linear); } finally { cursorBits?.Dispose(); } } else if (cursor.ShapeInfo.Type == (int)ShapeType.DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MONOCHROME) { height = height / 2; left = position.X; top = position.Y; right = position.X + width; bottom = position.Y + height; pitch = width * 4; Texture2D desktopRegionTex = null; try { desktopRegionTex = new Texture2D(device, new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging, OptionFlags = ResourceOptionFlags.None, }); var region = new ResourceRegion(left, top, 0, right, bottom, 1); var immediateContext = device.ImmediateContext; immediateContext.CopySubresourceRegion(screenTexture, 0, region, desktopRegionTex, 0); var dataBox = immediateContext.MapSubresource(desktopRegionTex, 0, MapMode.Read, MapFlags.None); try { var desktopBuffer = new byte[width * height * 4]; Marshal.Copy(dataBox.DataPointer, desktopBuffer, 0, desktopBuffer.Length); var shapeBufferLenght = width * height * 4; var shapeBuffer = new byte[shapeBufferLenght]; var maskBufferLenght = width * height / 8; var andMaskBuffer = new byte[maskBufferLenght]; Marshal.Copy(shapeBuff, andMaskBuffer, 0, andMaskBuffer.Length); var xorMaskBuffer = new byte[maskBufferLenght]; Marshal.Copy(shapeBuff + andMaskBuffer.Length, xorMaskBuffer, 0, xorMaskBuffer.Length); for (var row = 0; row < height; ++row) { byte mask = 0x80; for (var col = 0; col < width; ++col) { var maskIndex = row * width / 8 + col / 8; var andMask = ((andMaskBuffer[maskIndex] & mask) == mask) ? 0xFF : 0; var xorMask = ((xorMaskBuffer[maskIndex] & mask) == mask) ? 0xFF : 0; int pos = row * width * 4 + col * 4; for (int i = 0; i < 3; i++) {// RGB shapeBuffer[pos] = (byte)((desktopBuffer[pos] & andMask) ^ xorMask); pos++; } // Alpha shapeBuffer[pos] = (byte)((desktopBuffer[pos] & 0xFF) ^ 0); if (mask == 0x01) { mask = 0x80; } else { mask = (byte)(mask >> 1); } } } Direct2D.Bitmap cursorBits = null; try { fixed(byte *ptr = shapeBuffer) { var data = new DataPointer(ptr, height * pitch); var prop = new Direct2D.BitmapProperties(new Direct2D.PixelFormat(Format.B8G8R8A8_UNorm, Direct2D.AlphaMode.Premultiplied)); var size = new Size2(width, height); cursorBits = new Direct2D.Bitmap(renderTarger, size, data, pitch, prop); }; var shapeRect = new RawRectangleF(left, top, right, bottom); renderTarger.DrawBitmap(cursorBits, shapeRect, 1.0f, Direct2D.BitmapInterpolationMode.Linear); } finally { cursorBits?.Dispose(); } } finally { immediateContext.UnmapSubresource(desktopRegionTex, 0); } } finally { desktopRegionTex?.Dispose(); } } else if (cursor.ShapeInfo.Type == (int)ShapeType.DXGI_OUTDUPL_POINTER_SHAPE_TYPE_COLOR) { logger.Warn("Not supported cursor type " + ShapeType.DXGI_OUTDUPL_POINTER_SHAPE_TYPE_COLOR); } }
public static void DrawBitmap(this SharpDX.Direct2D1.RenderTarget target, D2DBitmap bitmap, float destX, float destY, float destWidth, float destHeight) { target.DrawBitmap(bitmap, destX, destY, destWidth, destHeight, BitmapInterpolationMode.Linear); }
public static void DrawBitmap(this SharpDX.Direct2D1.RenderTarget target, D2DBitmap bitmap, float destX, float destY, float destWidth, float destHeight, BitmapInterpolationMode interpolationMode) { var destRect = new RawRectangleF(destX, destY, destX + destWidth, destY + destHeight); target.DrawBitmap(bitmap.NativeBitmap, destRect, 1f, interpolationMode); }
public void OnRender(RenderTarget target) { if (mImage == null) return; target.DrawBitmap(mImage, mTargetRectangle, 1.0f, BitmapInterpolationMode.Linear, mSourceRectangle); if (mIndexLocation == 0) { target.FillRoundedRectangle(new RoundedRectangle { RadiusX = 5, RadiusY = 5, Rect = new RectangleF(Position.X + 5, Position.Y + 2, mIndexDraw.GetLayout().Metrics.Width + 10, mIndexDraw.GetLayout().Metrics.Height + 4) }, Brushes.Solid[0xDD555555]); } else { target.FillRoundedRectangle(new RoundedRectangle { RadiusX = 5, RadiusY = 5, Rect = new RectangleF(Position.X + mTargetRectangle.Width - mIndexDraw.GetLayout().Metrics.Width - 15, Position.Y + 2, mIndexDraw.GetLayout().Metrics.Width + 10, mIndexDraw.GetLayout().Metrics.Height + 4) }, Brushes.Solid[0xDD555555]); } target.DrawTextLayout(new Vector2(mPosition.X + 10, mPosition.Y + 5), mIndexDraw, Brushes.White); }
/// <summary> /// Draw a fading bitmap animation on the Render Target (Game Launcher Window). /// </summary> /// <param name="target">Destination render target which is ready to be drawn.</param> /// <param name="bitmapData">Bitmap data.</param> /// <param name="scaleMultiple">Which multiple should be used to scale the bitmap?</param> /// <param name="rect">Which rectangle range on the render target(window) should be drawn by the bitmap?</param> /// <param name="type">Which type of fade should we use to do the animation?</param> /// <param name="isStopDoing"> /// The variable reference of the sign which indicates 'Should we stop fading animation now'. /// <para>Project Rabotora Launcher will <b>instantly finish</b> fading bitmap draw process when drawing fading bitmap and <b>player clicks in the window of Rabotora Launcher</b>.<br /> /// This argument will pass the 'Instant finish' command from caller to animation method.</para> /// <para>If you do not want player finish the animation by clicking in the window, please give a <see langword="bool" /> variable whose value is <b>fixed <see langword="false" /></b> .</para> /// </param> /// <param name="duration">The animation duration of drawing fading bitmap in seconds. Default is <see langword="2.5f" /> .</param> /// <param name="segmentAlpha">How much alpha we should increase/decrease in the every round of inner drawing circulation? (Range: [0, 0.5]; Default is <see langword="0.005f" /> .)</param> /// <param name="isBeginDrawBeforeStart">Should we called <see cref="D2D.RenderTarget.BeginDraw()"/> before starting fading animation? (Default is <see langword="false" /> .)</param> /// <exception cref="ArgumentException" /> public static void DrawFadeBitmap(D2D.RenderTarget target, byte[] bitmapData, RawRectangleF rect, float scaleMultiple, FadeType type, ref bool isStopDoing, float duration = 2.5f, float segmentAlpha = 0.005f, bool isBeginDrawBeforeStart = false) { if (segmentAlpha < 0.0f || segmentAlpha > 0.5f) { throw new ArgumentException("Segment alpha value must in [0.0,0.5].", nameof(segmentAlpha)); } var stream = new MemoryStream(bitmapData); stream.Seek(0, SeekOrigin.Begin); var bitmapWrapper = (Bitmap)Image2.FromStream(stream); bitmapWrapper = bitmapWrapper.ScaleBitmap(scaleMultiple); var bitmap = target.LoadD2DBitmapFromBitmap(bitmapWrapper); if (bitmap != null) { if (isBeginDrawBeforeStart) { target.BeginDraw(); } int waitMS = (int)(duration * 1000 / (1 / segmentAlpha)); if (type == FadeType.FadeIn) { for (float i = 0f; i < 1f; i += segmentAlpha) { if (!isStopDoing) { target.DrawBitmap(bitmap, i, D2D.BitmapInterpolationMode.Linear, rect); target.EndDraw(); target.BeginDraw(); Thread.Sleep(waitMS); } else { target.DrawBitmap(bitmap, 1.0f, D2D.BitmapInterpolationMode.Linear, rect); target.EndDraw(); target.BeginDraw(); break; } } } else { for (float i = 1f; i > 0f; i -= segmentAlpha) { if (!isStopDoing) { target.DrawBitmap(bitmap, i, D2D.BitmapInterpolationMode.Linear, rect); target.EndDraw(); target.BeginDraw(); Thread.Sleep(waitMS); } else { target.DrawBitmap(bitmap, 0.0f, D2D.BitmapInterpolationMode.Linear, rect); target.EndDraw(); target.BeginDraw(); break; } } } } }
public virtual void DrawTexture(RenderTarget g, RectangleF position) { g.DrawBitmap(Texture, position, 1, BitmapInterpolationMode.NearestNeighbor); }
public static void DrawPoint(D2D1.RenderTarget renderTarget, D2D1.Factory factory, IPoint point, D2D1.Bitmap symbol, Vector2 offset, float rotation, Map map) { if (point == null) { return; } var pp = TransformToImage(point.Coordinate, map); if (double.IsNaN(pp.X)) { return; } pp += offset; bool symbolCreated = false; if (symbol == null) //We have no point style - Use a default symbol { symbol = CreateDefaultsymbol(renderTarget); symbolCreated = true; } lock (symbol) { if (rotation != 0 && !Single.IsNaN(rotation)) { var startingTransform = new Matrix3x2(renderTarget.Transform.ToArray()); var transform = renderTarget.Transform; var rotationCenter = pp; Matrix3x2.Rotation(rotation, rotationCenter); transform *= Matrix3x2.Rotation(rotation, rotationCenter); renderTarget.Transform = transform; //if (symbolscale == 1f) //{ // g.DrawImage(symbol, (pp.X - symbol.Width/2f + offset.X), // (pp.Y - symbol.Height/2f + offset.Y)); //} //else //{ // var width = symbol.Width*symbolscale; // var height = symbol.Height*symbolscale; // g.DrawImage(symbol, (int) pp.X - width/2 + offset.X*symbolscale, // (int) pp.Y - height/2 + offset.Y*symbolscale, width, height); //} var dx = 0.5d * symbol.PixelSize.Width; var dy = 0.5d * symbol.PixelSize.Height; renderTarget.DrawBitmap(symbol, new SharpDX.RectangleF(Convert.ToSingle(pp.X - dx), Convert.ToSingle(pp.Y + dy), symbol.PixelSize.Width, symbol.PixelSize.Height), 1f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear); renderTarget.Transform = startingTransform; } else { //if (symbolscale == 1f) //{ // g.DrawImageUnscaled(symbol, (int) (pp.X - symbol.Width/2f + offset.X), // (int) (pp.Y - symbol.Height/2f + offset.Y)); //} //else //{ // var width = symbol.Width*symbolscale; // var height = symbol.Height*symbolscale; // g.DrawImage(symbol, (int) pp.X - width/2 + offset.X*symbolscale, // (int) pp.Y - height/2 + offset.Y*symbolscale, width, height); //} var dx = 0.5d * symbol.PixelSize.Width; var dy = 0.5d * symbol.PixelSize.Height; renderTarget.DrawBitmap(symbol, new SharpDX.RectangleF(Convert.ToSingle(pp.X - dx), Convert.ToSingle(pp.Y + dy), symbol.PixelSize.Width, symbol.PixelSize.Height), 1f, D2D1.BitmapInterpolationMode.Linear); } } if (symbolCreated) { symbol.Dispose(); } }