Class Bitmap
Holds a bitmap image.
public class Bitmap : IImage, IDisposable, IImageBrushSource
- Inheritance
-
Bitmap
- Implements
- Derived
- Inherited Members
Constructors
Bitmap(IBitmapImpl)
Initializes a new instance of the Bitmap class.
protected Bitmap(IBitmapImpl impl)
Parameters
impl
IBitmapImplA platform-specific bitmap implementation. Bitmap class takes the ownership.
Bitmap(PixelFormat, AlphaFormat, nint, PixelSize, Vector, int)
Initializes a new instance of the Bitmap class.
public Bitmap(PixelFormat format, AlphaFormat alphaFormat, nint data, PixelSize size, Vector dpi, int stride)
Parameters
format
PixelFormatThe pixel format.
alphaFormat
AlphaFormatThe alpha format.
data
nintThe pointer to the source bytes.
size
PixelSizeThe size of the bitmap in device pixels.
dpi
VectorThe DPI of the bitmap.
stride
intThe number of bytes per row.
Bitmap(Stream)
Initializes a new instance of the Bitmap class.
public Bitmap(Stream stream)
Parameters
stream
StreamThe stream to read the bitmap from.
Bitmap(string)
Initializes a new instance of the Bitmap class.
public Bitmap(string fileName)
Parameters
fileName
stringThe filename of the bitmap.
Properties
AlphaFormat
public virtual AlphaFormat? AlphaFormat { get; }
Property Value
Dpi
Gets the dots per inch (DPI) of the image.
public Vector Dpi { get; }
Property Value
Remarks
Note that Skia does not currently support reading the DPI of an image so this value will always be 96dpi on Skia.
Format
public virtual PixelFormat? Format { get; }
Property Value
PixelSize
Gets the size of the bitmap, in device pixels.
public PixelSize PixelSize { get; }
Property Value
Size
Gets the size of the image, in device independent pixels.
public Size Size { get; }
Property Value
Methods
CopyPixels(PixelRect, nint, int, int)
public virtual void CopyPixels(PixelRect sourceRect, nint buffer, int bufferSize, int stride)
Parameters
CopyPixels(ILockedFramebuffer, AlphaFormat)
Copies pixels to the target buffer and transcodes the pixel and alpha format if needed.
public void CopyPixels(ILockedFramebuffer buffer, AlphaFormat alphaFormat)
Parameters
buffer
ILockedFramebufferThe target buffer.
alphaFormat
AlphaFormatThe alpha format.
Exceptions
CreateScaledBitmap(PixelSize, BitmapInterpolationMode)
Creates a Bitmap scaled to a specified size from the current bitmap.
public Bitmap CreateScaledBitmap(PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
Parameters
destinationSize
PixelSizeThe destination size.
interpolationMode
BitmapInterpolationModeThe BitmapInterpolationMode to use should any scaling be required.
Returns
DecodeToHeight(Stream, int, BitmapInterpolationMode)
Loads a Bitmap from a stream and decodes at the desired height. Aspect ratio is maintained. This is more efficient than loading and then resizing.
public static Bitmap DecodeToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
Parameters
stream
StreamThe stream to read the bitmap from. This can be any supported image format.
height
intThe desired height of the resulting bitmap.
interpolationMode
BitmapInterpolationModeThe BitmapInterpolationMode to use should any scaling be required.
Returns
DecodeToWidth(Stream, int, BitmapInterpolationMode)
Loads a Bitmap from a stream and decodes at the desired width. Aspect ratio is maintained. This is more efficient than loading and then resizing.
public static Bitmap DecodeToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
Parameters
stream
StreamThe stream to read the bitmap from. This can be any supported image format.
width
intThe desired width of the resulting bitmap.
interpolationMode
BitmapInterpolationModeThe BitmapInterpolationMode to use should any scaling be required.
Returns
Dispose()
public virtual void Dispose()
Save(Stream, int?)
Saves the bitmap to a stream.
public void Save(Stream stream, int? quality = null)
Parameters
stream
StreamThe stream.
quality
int?The optional quality for compression. The quality value is interpreted from 0 - 100. If quality is null the default quality setting is applied.
Save(string, int?)
Saves the bitmap to a file.
public void Save(string fileName, int? quality = null)