/// <summary> /// Ensures the bitmap cache. /// </summary> /// <param name="context">The context.</param> /// <param name="size">The size.</param> /// <param name="maxSize">The maximum size.</param> private void EnsureBitmapCache(RenderContext2D context, Size2 size, int maxSize) { IsBitmapCacheValid = false; if (size.Width <= 0 || size.Height <= 0 || !EnableBitmapCache || size.Width * size.Height < MinimumBitmapSize) { Disposer.RemoveAndDispose(ref bitmapCache); } else if (size.Width > maxSize || size.Height > maxSize) { return; } else if (bitmapCache == null || size.Width > bitmapCache.Size.Width || size.Height > bitmapCache.Size.Height) { #if DEBUGCACHECREATE Debug.WriteLine("Create new bitmap cache."); #endif Disposer.RemoveAndDispose(ref bitmapCache); bitmapCache = BitmapProxy.Create("Cache", context.DeviceContext, size, Format.B8G8R8A8_UNorm); IsBitmapCacheValid = true; IsVisualDirty = true; } else { IsBitmapCacheValid = true; } }
/// <summary> /// /// </summary> /// <param name="texture"></param> /// <param name="deviceContext"></param> public void Initialize(Texture2D texture, DeviceContext2D deviceContext) { RemoveAndDispose(ref d2DTarget); using (var surface = texture.QueryInterface <global::SharpDX.DXGI.Surface>()) { d2DTarget = Collect(BitmapProxy.Create("TextureTarget", deviceContext, surface)); } }
/// <summary> /// /// </summary> /// <param name="swapChain"></param> /// <param name="deviceContext"></param> public void Initialize(SwapChain1 swapChain, DeviceContext2D deviceContext) { RemoveAndDispose(ref d2DTarget); using (var surf = swapChain.GetBackBuffer <Surface>(0)) { d2DTarget = Collect(BitmapProxy.Create("SwapChainTarget", deviceContext, surf)); } }
protected SettingsDialogSection(PaintDotNet.Settings.App.AppSettings appSettings, string displayName, Image icon) { Validate.Begin().IsNotNull <PaintDotNet.Settings.App.AppSettings>(appSettings, "appSettings").IsNotNullOrWhiteSpace(displayName, "displayName").IsNotNull <Image>(icon, "icon").Check(); this.appSettings = appSettings; this.displayName = displayName; this.icon = icon; Surface cleanupObject = Surface.CopyFromGdipImage(this.icon); this.bitmapIcon = new BitmapProxy(cleanupObject.CreateAliasedImagingBitmap(), ObjectRefProxyOptions.AssumeOwnership); this.bitmapIcon.AddCleanupObject(cleanupObject); this.deviceIcon = new DeviceBitmap(this.bitmapIcon); this.sectionSettings = new HashSet <Setting>(); }
private PlacedBitmap CreateFontPreview(string gdiFontName, float fontSize, PaintDotNet.UI.Media.Brush textBrush) { FontProperties fontProperties; TextMetrics metrics; OverhangMetrics overhangMetrics; try { fontProperties = this.fontMap.GetFontProperties(gdiFontName); using (IDrawingContext context = DrawingContext.CreateNull(FactorySource.PerThread)) { TextLayoutAlgorithm?layoutAlgorithm = null; TextLayout resourceSource = UIText.CreateLayout(context, this.fontSampleText, fontProperties, (double)fontSize, layoutAlgorithm, HotkeyRenderMode.Ignore, 65535.0, 65535.0); ITextLayout cachedOrCreateResource = context.GetCachedOrCreateResource <ITextLayout>(resourceSource); metrics = cachedOrCreateResource.Metrics; overhangMetrics = cachedOrCreateResource.OverhangMetrics; } } catch (Exception exception) { if ((!(exception is NoFontException) && !(exception is FontFileAccessException)) && (!(exception is FontFileFormatException) && !(exception is FontFileNotFoundException))) { throw; } Surface cleanupObject = Surface.CopyFromGdipImage(PdnResources.GetImageResource("Icons.WarningIcon.png").Reference); BitmapProxy proxy = new BitmapProxy(cleanupObject.CreateAliasedImagingBitmap(), ObjectRefProxyOptions.AssumeOwnership); proxy.AddCleanupObject(cleanupObject); return(new PlacedBitmap(proxy, new RectDouble(0.0, 0.0, (double)proxy.Size.Width, (double)proxy.Size.Height), true)); } RectDouble a = new RectDouble((double)metrics.Left, (double)metrics.Top, (double)(metrics.Left + metrics.WidthMax), (double)(metrics.Top + metrics.Height)); RectDouble b = RectDouble.FromEdges((double)(metrics.Left - overhangMetrics.Left), (double)(metrics.Top - overhangMetrics.Top), (double)(metrics.LayoutWidth + overhangMetrics.Right), (double)(metrics.LayoutHeight + overhangMetrics.Bottom)); RectInt32 num4 = RectDouble.Union(a, b).Int32Bound; IBitmap bitmap = new PaintDotNet.Imaging.Bitmap(num4.Width, num4.Height, PixelFormats.Pbgra32, BitmapCreateCacheOption.CacheOnLoad); using (IDrawingContext context2 = DrawingContext.FromBitmap(bitmap, FactorySource.PerThread)) { context2.Clear(null); using (context2.UseTranslateTransform((float)-num4.X, (float)-num4.Y, MatrixMultiplyOrder.Prepend)) { using (context2.UseTextRenderingMode(TextRenderingMode.Outline)) { TextLayout textLayout = UIText.CreateLayout(context2, this.fontSampleText, fontProperties, (double)fontSize, null, HotkeyRenderMode.Ignore, 65535.0, 65535.0); context2.TextAntialiasMode = TextAntialiasMode.Grayscale; context2.DrawTextLayout(0.0, 0.0, textLayout, textBrush, DrawTextOptions.None); } } } return(new PlacedBitmap(bitmap, b, true)); }
public void PushRenderTarget(BitmapProxy target, bool clear) { if (targetStack.Count > 0) { DeviceContext.EndDraw(); } targetStack.Push(target); DeviceContext.Target = targetStack.Peek(); HasTarget = true; DeviceContext.BeginDraw(); if (clear) { DeviceContext.Clear(Color.Transparent); } }
public Item(System.Drawing.Image image, string name, bool selected) { this.image = image; this.name = name; this.selected = selected; if (image != null) { Surface cleanupObject = Surface.CopyFromGdipImage(this.image); using (BitmapProxy proxy = new BitmapProxy(cleanupObject.CreateAliasedImagingBitmap(), ObjectRefProxyOptions.AssumeOwnership)) { proxy.AddCleanupObject(cleanupObject); this.deviceImage = new DeviceBitmap(proxy); } } }