I'm not clear on how SKBitmap.InstallPixels()
and SKBitmap.SetPixels()
work. Here's the documentation for one of each method (there are several method overloads):
// Summary:
// Installs the specified pixels into the bitmap.
//
// Parameters:
// info:
// The image information describing the pixels.
//
// pixels:
// The pixels to install.
//
// Returns:
// Returns true on success, or false on failure. If there was an error, the bitmap
// will be set to empty.
public bool InstallPixels(SKImageInfo info, IntPtr pixels);
// Summary:
// Replaces the current pixel address for the bitmap.
//
// Parameters:
// pixels:
// The new pixel address.
public void SetPixels(IntPtr pixels);
My guess is that InstallPixels()
copies the data from the IntPtr
to a local byte array, whereas SetPixels()
makes the passed IntPtr
the byte array to use.
If my assumption is correct, does that mean that if I want to use InstallPixels()
I need to first call TryAllocPixels()
to create the internal byte array? If I want to use SetPixels()
, do I need to manually dispose of the byte array or does it get disposed when the SKBitmap
is disposed?
InstallPixels
. After creating a bitmap as shown in Matthew's code, can do high-performance manipulation of individual pixels (via the correspondingpixelArray
), without needingunsafe
code. – Thermidor