Implement CachedBitmap functionality in System.Drawing
See original GitHub issueBackground
Drawing a Bitmap in GDI+ has relatively poor performance, since the image is stored in a device-independent format. The CachedBitmap class stores an image in a format that is optimized for display on a particular device. Thus, rendering an image stored in a CachedBitmap is fast, because no processing time is spent converting the image to the format required by the display device. Naturally, such a capability can substantially improve graphics performance in many scenarios. However, for whatever reason, it’s not directly usable from the System.Drawing APIs.
API Proposal
This API is derived from this page of the GDI+ flat API. (I don’t know what GdipEmfToWmfBits is doing on that page, but System.Drawing doesn’t support saving metafiles anyway.)
namespace System.Drawing.Imaging
{
+ public sealed class CachedBitmap : MarshalByRefObject, IDisposable
+ {
+ public CachedBitmap(Bitmap bitmap, Graphics graphics);
+ public void Dispose();
+ }
}
namespace System.Drawing
{
public sealed class Graphics : MarshalByRefObject, IDisposable, IDeviceContext
{
+ public void DrawCachedBitmap(CachedBitmap cachedBitmap, int x, int y);
}
}
As an aside: currently, libgdiplus doesn’t implement this functionality. I imagine it would be fine to just PNSE when not on Windows for now (or, alternatively, making it “lie” about being a CachedBitmap, and simply calling DrawImage from DrawCachedBitmap).
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:17 (10 by maintainers)

Top Related StackOverflow Question
Btw, I set the milestone to future as there’s no rush to implement this, but if we’re able to get it in the next couple of weeks and make it into 5.0, great 😄
GetLibgdiplusVersionis not supported in some old versions oflibgdiplusso we should consider that when we implement that and trhowing if the version doesn’t support it or if we can’t get the version at all.