public static async Task <ID2D1Bitmap> LoadBitmapFromFileAsync( this D2DImageLoader loader, ID2D1RenderTarget renderTarget, string filePath, Guid?format = null, WICBitmapDitherType dither = WICBitmapDitherType.None, double alphaThresholdPercent = 0, WICBitmapPaletteType paletteTranslate = WICBitmapPaletteType.Custom, IWICPalette palette = null) { if (!format.HasValue) { format = PixelFormatGUID.Format32bppPBGRA; } ID2D1Bitmap bitmap = await Task.Run(() => { return(loader.LoadBitmapFromFile( renderTarget, filePath, format, dither, alphaThresholdPercent, paletteTranslate, palette )); }).ConfigureAwait(false); return(bitmap); }
public static void SetInput(this ID2D1Effect effect, int index, ID2D1Bitmap input = null, bool invalidate = false) { if (effect == null) { throw new ArgumentNullException(nameof(effect)); } effect.SetInput(index, input, invalidate); }
public static D2D_SIZE_F GetDpi(this ID2D1Bitmap bitmap) { if (bitmap == null) { throw new ArgumentNullException(nameof(bitmap)); } bitmap.GetDpi(out var dx, out var dy); return(new D2D_SIZE_F(dx, dy)); }
public static D2D1_PIXEL_FORMAT GetPixelFormat(this ID2D1Bitmap bitmap) { if (bitmap == null) { throw new ArgumentNullException(nameof(bitmap)); } bitmap.GetPixelFormat(out var format); return(format); }
public static D2D_SIZE_U GetPixelSize(this ID2D1Bitmap bitmap) { if (bitmap == null) { throw new ArgumentNullException(nameof(bitmap)); } bitmap.GetPixelSize(out var size); return(size); }
public static D2D_SIZE_F GetDpi(this ID2D1Bitmap bitmap) { if (bitmap == null) { throw new ArgumentNullException(nameof(bitmap)); } #pragma warning disable CA2010 // Always consume the value returned by methods marked with PreserveSigAttribute bitmap.GetDpi(out var dx, out var dy); #pragma warning restore CA2010 // Always consume the value returned by methods marked with PreserveSigAttribute return(new D2D_SIZE_F(dx, dy)); }
public static D2D_SIZE_F GetSize(this ID2D1Bitmap bitmap) { if (bitmap == null) { throw new ArgumentNullException(nameof(bitmap)); } // if this doesn't compile, you must change ID2B1Bitmap method like this: // [PreserveSig] // void GetSize(out D2D_SIZE_F size); bitmap.GetSize(out var size); return(size); }
public static D2D_SIZE_F GetSize(this ID2D1Bitmap bitmap) { if (bitmap == null) { throw new ArgumentNullException(nameof(bitmap)); } // if this doesn't compile, you must change ID2B1Bitmap method like this: // [PreserveSig] // void GetSize(out D2D_SIZE_F size); #pragma warning disable CA2010 // Always consume the value returned by methods marked with PreserveSigAttribute bitmap.GetSize(out var size); #pragma warning restore CA2010 // Always consume the value returned by methods marked with PreserveSigAttribute return(size); }
protected override void OnPopupShow(CefBrowser browser, bool show) { _isPopupShown = show; if (show == false) { _popupRect = null; if (_cachedPopupImage != null) { _cachedPopupImage.Dispose(); _cachedPopupImage = null; GC.Collect(); } } base.OnPopupShow(browser, show); }
public static void DrawBitmap(this ID2D1RenderTarget renderTarget, ID2D1Bitmap bitmap, float opacity = 1, D2D1_BITMAP_INTERPOLATION_MODE interpolationMode = D2D1_BITMAP_INTERPOLATION_MODE.D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2D_RECT_F?destinationRectangle = null, D2D_RECT_F?sourceRectangle = null) { if (renderTarget == null) { throw new ArgumentNullException(nameof(renderTarget)); } using (var drc = destinationRectangle.StructureToMemory()) { using (var src = sourceRectangle.StructureToMemory()) { renderTarget.DrawBitmap(bitmap, drc.Pointer, opacity, interpolationMode, src.Pointer); } } }
public static void DrawBitmap(this ID2D1DeviceContext device, ID2D1Bitmap bitmap, float opacity, D2D1_BITMAP_INTERPOLATION_MODE interpolationMode, D2D_RECT_F?destinationRectangle = null, D2D_RECT_F?sourceRectangle = null) { if (device == null) { throw new ArgumentNullException(nameof(device)); } using (var drc = destinationRectangle.StructureToMemory()) { using (var src = sourceRectangle.StructureToMemory()) { device.DrawBitmap(bitmap, drc.Pointer, opacity, interpolationMode, src.Pointer); } } }
public static void DrawBitmap(this ID2D1DeviceContext device, ID2D1Bitmap bitmap, float opacity, D2D1_BITMAP_INTERPOLATION_MODE interpolationMode, D2D_RECT_F?destinationRectangle = null, D2D_RECT_F?sourceRectangle = null) { if (device == null) { throw new ArgumentNullException(nameof(device)); } using (var drc = destinationRectangle.StructureToMemory()) { using (var src = sourceRectangle.StructureToMemory()) { #pragma warning disable CA2010 // Always consume the value returned by methods marked with PreserveSigAttribute device.DrawBitmap(bitmap, drc.Pointer, opacity, interpolationMode, src.Pointer); #pragma warning restore CA2010 // Always consume the value returned by methods marked with PreserveSigAttribute } } }
public static void DrawBitmap(this ID2D1DeviceContext context, ID2D1Bitmap bitmap, float opacity = 1, D2D1_INTERPOLATION_MODE interpolationMode = D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2D_RECT_F?destinationRectangle = null, D2D_RECT_F?sourceRectangle = null, D2D_MATRIX_4X4_F?perspectiveTransform = null) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (bitmap == null) { throw new ArgumentNullException(nameof(bitmap)); } using (var drc = destinationRectangle.StructureToMemory()) { using (var src = sourceRectangle.StructureToMemory()) { if (perspectiveTransform.HasValue || (int)interpolationMode > (int)D2D1_BITMAP_INTERPOLATION_MODE.D2D1_BITMAP_INTERPOLATION_MODE_LINEAR) { using (var per = perspectiveTransform.StructureToMemory()) { context.DrawBitmap(bitmap, drc.Pointer, opacity, interpolationMode, src.Pointer, per.Pointer); } } else { context.DrawBitmap(bitmap, drc.Pointer, opacity, (D2D1_BITMAP_INTERPOLATION_MODE)interpolationMode, src.Pointer); } } } }
public void DrawBitmap(ID2D1Bitmap bitmap, float opacity, InterpolationMode interpolationMode, in Matrix4x4 perspectiveTransform)
public ID2D1BitmapBrush1 CreateBitmapBrush(ID2D1Bitmap bitmap) { return(CreateBitmapBrush(bitmap, null, null)); }
public void DrawBitmap(ID2D1Bitmap bitmap, float opacity, InterpolationMode interpolationMode) { DrawBitmap(bitmap, null, opacity, interpolationMode, null, null); }
protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height) { if (width <= 0 || height <= 0) { return; } var handle = _owner.HostWindowHandle; CreateDeviceResource(); _renderTarget.BeginDraw(); if (type == CefPaintElementType.View) { var bmp = _renderTarget.CreateBitmap(new Vortice.Mathematics.Size(width, height), buffer, width * 4, new BitmapProperties(new PixelFormat(Vortice.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied))); if (!_isPopupShown) { _renderTarget.Clear(Color.Transparent); } _renderTarget.DrawBitmap(bmp); bmp.Dispose(); } else if (type == CefPaintElementType.Popup) { var bmp = _renderTarget.CreateBitmap(new Vortice.Mathematics.Size(width, height), buffer, width * 4, new BitmapProperties(new PixelFormat(Vortice.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied))); if (_cachedPopupImage != null) { _cachedPopupImage.Dispose(); _cachedPopupImage = null; GC.Collect(); } _cachedPopupImage = _renderTarget.CreateSharedBitmap(bmp, new BitmapProperties { PixelFormat = new PixelFormat(Vortice.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied) }); bmp.Dispose(); } if (_cachedPopupImage != null && _isPopupShown && _popupRect.HasValue) { var scaleFactor = DpiHelper.GetScaleFactorForCurrentWindow(_owner.HostWindowHandle); var x = _popupRect.Value.X * scaleFactor; var y = _popupRect.Value.Y * scaleFactor; var popupWidth = _popupRect.Value.Width * scaleFactor; var popupHeight = _popupRect.Value.Height * scaleFactor; var right = x + popupWidth; var bottom = y + popupHeight; _renderTarget.DrawBitmap(_cachedPopupImage, new Vortice.RawRectF(x, y, right, bottom), 1f, BitmapInterpolationMode.Linear, new Vortice.RawRectF(0, 0, popupWidth, popupHeight)); } if (_renderTarget.EndDraw().Failure) { DiscardDeviceResources(); } unsafe { var rect = new RECT(); User32.GetWindowRect(handle, ref rect); var newLocation = new POINT(rect.left, rect.top); var newSize = new SIZE(rect.Width, rect.Height); var zeroPoint = new POINT(0, 0); if (rect.Width == 0 || rect.Height == 0) { return; } var blend = new BLENDFUNCTION { BlendOp = AcSrcOver, BlendFlags = 0, SourceConstantAlpha = 255, AlphaFormat = AcSrcAlpha }; var ulwi = new UPDATELAYEREDWINDOWINFO { cbSize = Marshal.SizeOf(typeof(UPDATELAYEREDWINDOWINFO)), hdcDst = _screenDC, pptDst = &newLocation, psize = &newSize, hdcSrc = _memDC, pptSrc = &zeroPoint, //crKey = new COLORREF(0), pblend = &blend, dwFlags = BlendFlags.ULW_ALPHA, prcDirty = null }; User32.UpdateLayeredWindowIndirect(_owner.HostWindowHandle, ref ulwi); } GC.Collect(); }
/// <summary> /// Copies the specified bitmap into the current bitmap. /// </summary> /// <param name="destinationPoint">In the current bitmap, the upper-left corner of the area to which the data is copied</param> /// <param name="sourceBitmap">The bitmap to copy from.</param> /// <returns>The result of the operation.</returns> public Result CopyFromBitmap(Int2 destinationPoint, ID2D1Bitmap sourceBitmap) => CopyFromBitmap(&destinationPoint, sourceBitmap, null);
protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height) { if (width <= 0 || height <= 0) { return; } CreateDeviceResource(); _renderTarget.BeginDraw(); if (type == CefPaintElementType.View) { var bmp = _renderTarget.CreateBitmap(new Vortice.Mathematics.Size(width, height), buffer, width * 4, new BitmapProperties(new PixelFormat(Vortice.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied))); if (!_isPopupShown) { _renderTarget.Clear(Color.Transparent); } _renderTarget.DrawBitmap(bmp); bmp.Dispose(); } else if (type == CefPaintElementType.Popup) { var bmp = _renderTarget.CreateBitmap(new Vortice.Mathematics.Size(width, height), buffer, width * 4, new BitmapProperties(new PixelFormat(Vortice.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied))); if (_cachedPopupImage != null) { _cachedPopupImage.Dispose(); _cachedPopupImage = null; GC.Collect(); } _cachedPopupImage = _renderTarget.CreateSharedBitmap(bmp, new BitmapProperties { PixelFormat = new PixelFormat(Vortice.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied) }); bmp.Dispose(); } //var layer = _renderTarget.CreateLayer(); //var layerParameter = new LayerParameters //{ // ContentBounds = new Vortice.RawRectF(0, 0, width, height), // Opacity = 1 //}; //_renderTarget.PushLayer(ref layerParameter, layer); if (_cachedPopupImage != null && _isPopupShown && _popupRect.HasValue) { var scaleFactor = DpiHelper.GetScaleFactorForCurrentWindow(_owner.HostWindowHandle); var x = _popupRect.Value.X * scaleFactor; var y = _popupRect.Value.Y * scaleFactor; var popupWidth = _popupRect.Value.Width * scaleFactor; var popupHeight = _popupRect.Value.Height * scaleFactor; var right = x + popupWidth; var bottom = y + popupHeight; _renderTarget.DrawBitmap(_cachedPopupImage, new Vortice.RawRectF(x, y, right, bottom), 1f, BitmapInterpolationMode.Linear, new Vortice.RawRectF(0, 0, popupWidth, popupHeight)); } //_renderTarget.PopLayer(); //layer.Dispose(); if (_renderTarget.EndDraw().Failure) { DiscardDeviceResources(); } }
/// <summary> /// Copies the specified region from the specified bitmap into the current bitmap. /// </summary> /// <param name="destinationPoint"> /// In the current bitmap, the upper-left corner of the area to which the region specified by sourceRectangle is copied.</param> /// <param name="sourceBitmap">The bitmap to copy from.</param> /// <param name="sourceRectangle">The area of bitmap to copy.</param> /// <returns>The result of the operation.</returns> public Result CopyFromBitmap(Int2 destinationPoint, ID2D1Bitmap sourceBitmap, RectI sourceRectangle) { RawRect sourceRect = sourceRectangle; return(CopyFromBitmap(&destinationPoint, sourceBitmap, &sourceRect)); }
internal D2D1Bitmap(ID2D1Bitmap bitmap) { this.bitmap = bitmap; }
/// <summary> /// Copies the specified bitmap into the current bitmap. /// </summary> /// <param name="sourceBitmap">The bitmap to copy from.</param> /// <returns>The result of the operation.</returns> public Result CopyFromBitmap(ID2D1Bitmap sourceBitmap) => CopyFromBitmap(null, sourceBitmap, null);
public void CopyFromBitmap(ID2D1Bitmap sourceBitmap) { CopyFromBitmap(null, sourceBitmap, null); }
public void CopyFromBitmap(Point destinationPoint, ID2D1Bitmap sourceBitmap) { CopyFromBitmap(destinationPoint, sourceBitmap, null); }
public void CopyFromBitmap(Point destinationPoint, ID2D1Bitmap sourceBitmap, Rectangle sourceArea) { RawRect rawSourceArea = sourceArea; CopyFromBitmap(destinationPoint, sourceBitmap, rawSourceArea); }
public ID2D1Bitmap CreateSharedBitmap(ID2D1Bitmap bitmap, BitmapProperties?bitmapProperties) { Guard.NotNull(bitmap, nameof(bitmap)); return(CreateSharedBitmap(typeof(ID2D1Bitmap).GUID, bitmap.NativePointer, bitmapProperties)); }