Table of Contents

Method CreateSharedBitmap

Namespace
PaintDotNet.Direct2D1
Assembly
PaintDotNet.Windows.dll

CreateSharedBitmap(IBitmapLock, in SharedBitmapProperties?)

Creates an IDeviceBitmap whose data is shared (not copied) with an IBitmapLock.

IDeviceBitmap CreateSharedBitmap(IBitmapLock bitmapLock, in SharedBitmapProperties? bitmapProperties = null)

Parameters

bitmapLock IBitmapLock

The IBitmapLock that contains the data to share with the new device bitmap.

bitmapProperties SharedBitmapProperties?

The pixel format and DPI of the bitmap to create. The DxgiFormat portion of the pixel format must match the DxgiFormat of the data or the method will fail, but the alpha modes don't have to match. To prevent a mismatch, you can pass null. The DPI settings do not have to match those of data. If both dpiX and dpiY are 0.0f, the DPI of the device context is used.

Returns

IDeviceBitmap

The new shared bitmap.

Remarks

The CreateSharedBitmap method is useful for efficiently reusing bitmap data when using a software device context.
An IBitmapLock stores the content of a bitmap and shields it from simultaneous accesses. By passing an IBitmapLock to the CreateSharedBitmap method, you can create an IDeviceBitmap that points to the bitmap data already stored in the IBitmapLock.
To use an IBitmapLock with the CreateSharedBitmap method, the device context must be using software rendering. To check whether a device context uses software rendering, use the IsSupported(in DeviceContextProperties) method or the IsSoftwareContext extension method.

CreateSharedBitmap(IDeviceBitmap, in SharedBitmapProperties?)

Creates an IDeviceBitmap whose data is shared (not copied) with another IDeviceBitmap.

IDeviceBitmap CreateSharedBitmap(IDeviceBitmap bitmap, in SharedBitmapProperties? bitmapProperties = null)

Parameters

bitmap IDeviceBitmap

The IDeviceBitmap that contains the data to share with the new device bitmap.

bitmapProperties SharedBitmapProperties?

The pixel format and DPI of the bitmap to create. The DxgiFormat portion of the pixel format must match the DxgiFormat of the data or the method will fail, but the alpha modes don't have to match. To prevent a mismatch, you can pass null. The DPI settings do not have to match those of data. If both dpiX and dpiY are 0.0f, the DPI of the device context is used.

Returns

IDeviceBitmap

The new shared bitmap.

Remarks

By passing an IDeviceBitmap created by a device context that is resource-compatible, you can share a bitmap with that render target; both the original IDeviceBitmap and the new IDeviceBitmap created by this method will point to the same bitmap data (it is not copied). For more information about when device context resources can be shared, see the Sharing Render Target Resources section of the Resources Overview.
You may also use this method to reinterpret the data of an existing bitmap and specify a new DPI or alpha mode. For example, in the case of a bitmap atlas, an IDeviceBitmap may contain multiple sub-images, each of which should be rendered with a different AlphaMode (either Premultiplied or Ignore). You could use the CreateSharedBitmap method to reinterpret the bitmap using the desired alpha mode without having to load a separate copy of the bitmap into memory.