[]
Represents a bitmap based on Windows Imaging Component.
public class GcWicBitmap : IImage, IDisposable
Initializes an instance of the GcWicBitmap class.
public GcWicBitmap()
Initializes a new instance of the GcWicBitmap class.
public GcWicBitmap(Image image, Rectangle? imageRect = null)
image
ImageImage used as the source of image data.
imageRect
System.Drawing.Rectangle?Clipping rectangle of the image to be loaded.
Initializes a new instance of the GcWicBitmap class.
public GcWicBitmap(ImagingFactory imagingFactory)
imagingFactory
ImagingFactoryThe existing imaging factory, to avoid duplicating factories.
Initializes a new instance of the GcWicBitmap class from an instance of GcBitmap.
If the source image is not opaque, the color channels must be premultiplied with the alpha channel.
public GcWicBitmap(GcBitmap bitmap, ImagingFactory imagingFactory = null)
bitmap
GcBitmapThe source GcBitmap.
imagingFactory
ImagingFactoryThe existing imaging factory, to avoid duplicating factories.
Initializes a new instance of the GcWicBitmap class.
public GcWicBitmap(byte[] bytes, int frameIndex = 0, Rectangle? imageRect = null)
bytes
byte[]The image data. JPEG, PNG, GIF, BMP, TIFF, ICO, JPEG XR formats are supported.
frameIndex
intIndex of an image frame to read, pass 0 for image formats not supporting multiple frames.
imageRect
System.Drawing.Rectangle?Clipping rectangle of the image to be loaded.
Initializes a new instance of the GcWicBitmap class and creates the image.
The image content is not initialized and can contain any random data.
public GcWicBitmap(int pixelWidth, int pixelHeight, bool opaque, float dpiX = 96, float dpiY = 96)
pixelWidth
intThe width of the image, in pixels.
pixelHeight
intThe height of the image, in pixels.
opaque
boolIndicates whether the alpha channel should be ignored.
dpiX
floatThe horizontal dpi of the image.
dpiY
floatThe vertical dpi of the image.
Initializes a new instance of the GcWicBitmap class.
public GcWicBitmap(Stream stream, int frameIndex = 0, Rectangle? imageRect = null)
stream
System.IO.StreamThe source stream. JPEG, PNG, GIF, BMP, TIFF, ICO, JPEG XR formats are supported.
frameIndex
intIndex of an image frame to read, pass 0 for image formats not supporting multiple frames.
imageRect
System.Drawing.Rectangle?Clipping rectangle of the image to be loaded.
Initializes a new instance of the GcWicBitmap class.
public GcWicBitmap(string path, int frameIndex = 0, Rectangle? imageRect = null)
path
stringThe file path to the image. JPEG, PNG, GIF, BMP, TIFF, ICO, JPEG XR formats are supported.
frameIndex
intIndex of an image frame to read, pass 0 for image formats not supporting multiple frames.
imageRect
System.Drawing.Rectangle?Clipping rectangle of the image to be loaded.
Gets an instance of the SolidColorBrush class.
The brush becomes available after executing the EnsureRenderTargetCreated() method.
public SolidColorBrush Brush { get; }
Gets an instance of the Factory1 class.
The factory becomes available after executing the EnsureRenderTargetCreated() method.
public Factory1 D2DFactory { get; }
Gets the x-axis dpi resolution.
public float DpiX { get; }
Gets the y-axis dpi resolution.
public float DpiY { get; }
Gets an instance of the Factory1 class.
The factory becomes available after initializing the font cache (see the SetFontCache(FontCache) method).
public Factory1 DWFactory { get; }
Gets an instance of the GcWicBitmapGraphics class.
The Graphics becomes available after executing the CreateGraphics(Color?) method.
public GcWicBitmapGraphics Graphics { get; }
Gets a value indicating if GcWicBitmap supports the CreateGraphics(Color?) method on the current platform.
public static bool GraphicsSupported { get; }
Gets a value indicating whether the underlying image exists (has been loaded or created). If this property is false, call Load() or CreateImage() to load or create the underlying image. Calling any other method will throw an exception unless this property is true.
public bool HasImage { get; }
Gets the height of the image, in DIPs.
public float Height { get; }
Gets an instance of the ImagingFactory class.
public ImagingFactory ImagingFactory { get; }
Gets a value indicating whether the GcWicBitmap has been disposed of.
public bool IsDisposed { get; }
Gets a value indicating if GcWicBitmap is available on the current platform.
Make sure that "Thread.CurrentThread.SetApartmentState(ApartmentState.MTA)" is executed at the beginning of the Program.Main() method.
public static bool IsSupported { get; }
Gets the internal image that is an IWICBitmap.
public Bitmap NativeBitmap { get; }
Gets the pixel format of the image.
public WicPixelFormat PixelFormat { get; }
Gets the pixel height of the image.
public int PixelHeight { get; }
Gets the pixel width of the image.
public int PixelWidth { get; }
Gets an instance of the RenderTarget class.
The render target becomes available after executing the EnsureRenderTargetCreated() method.
public RenderTarget RenderTarget { get; }
Gets the width of the image, in DIPs.
public float Width { get; }
Applies a license key to an instance of GcWicBitmap.
public void ApplyLicenseKey(string key)
key
stringThe license key to set.
Returns the number of bits-per-pixel (bpp) for the given value of the PixelFormat enumeration.
public static int BitsPerPixel(WicPixelFormat pixelFormat)
pixelFormat
WicPixelFormatThe PixelFormat enumeration value.
Determines if the current pixel format can be converted to the destination pixel format.
public bool CanConvertTo(WicPixelFormat pixelFormat)
pixelFormat
WicPixelFormatThe destionation pixel format.
Creates an instance of the GcWicBitmapGraphics class.
public GcWicBitmapGraphics CreateGraphics(Color? backColor = null)
backColor
System.Drawing.Color?If not null, specifies the color to clear the image with.
A new instance of GcWicBitmapGraphics.
Creates the image of the given size and resolution.
The content is not initialized and can contain any random data.
public void CreateImage(int pixelWidth, int pixelHeight, bool opaque, float dpiX = 96, float dpiY = 96)
pixelWidth
intThe width of the image, in pixels.
pixelHeight
intThe height of the image, in pixels.
opaque
boolIndicates if the alpha channel should be ignored.
dpiX
floatThe horizontal dpi of the image.
dpiY
floatThe vertical dpi of the image.
Creates a palette using a computed optimized values based on the bitmap.
public GcWicBitmap.Palette CreatePaletteFromBitmap(int colorCount, bool addTransparentColor)
colorCount
intThe number of colors to initialize the palette with.
addTransparentColor
boolA value to indicate whether to add a transparent color.
The resulting palette contains the specified number of colors which best represent the colors present in the bitmap. The algorithm operates on the opaque RGB color value of each pixel in the reference bitmap and hence ignores any alpha values. If a transparent color is required, set the addTransparentColor parameter to true and one fewer optimized color will be computed, reducing the colorCount, and a fully transparent color entry will be added.
Creates one of the pre-defined palettes specified by PaletteType and optionally adds a transparent color.
public GcWicBitmap.Palette CreatePredefinedPalette(WicPaletteType paletteType, bool addTransparentColor)
paletteType
WicPaletteTypeThe desired pre-defined palette type.
addTransparentColor
boolThe optional transparent color to add to the palette. If no transparent color is needed, use false. When initializing to a grayscale or black and white palette, set this parameter to false.
For palettes with less than 256 entries, the transparent entry is added to the end of the palette (that is, a 16-color palette becomes a 17-color palette). For palettes with 256 colors, the transparent palette entry will replace the last entry in the pre-defined palette.
Releases the internal image and clears all metadata.
public void DiscardImage()
Clean up any resources being used.
public void Dispose()
Performs cleanup operations on managed and unmanaged resources.
protected virtual void Dispose(bool disposing)
disposing
boolCreates a render target for the internal WIC image, if it has not been created yet.
public RenderTarget EnsureRenderTargetCreated()
Copies a fragment of the image to the specified GcBitmap object.
public void ExportFragment(GcBitmap dstBitmap, int xDst, int yDst, Rectangle srcRect)
dstBitmap
GcBitmapThe destination GcBitmap object.
xDst
intThe x-coordinate, in pixels, of the upper-left corner of the destination rectangle.
yDst
intThe y-coordinate, in pixels, of the upper-left corner of the destination rectangle.
srcRect
System.Drawing.RectangleThe source rectangle within the image.
Copies a fragment of the image to the unmanaged block of memory.
public int ExportFragment(IntPtr dstPtr, Rectangle srcRect)
dstPtr
System.IntPtrThe pointer to the unmanaged block of memory or IntPtr.Zero.
srcRect
System.Drawing.RectangleThe source rectangle within the image.
Returns the number of bytes in the requested fragment of the image.
Performs cleanup operations on unmanaged resources.
protected ~GcWicBitmap()
Returns the image stride (bytes per row).
public int GetImageStride()
Retrieves the color table for indexed pixel formats, or null for other formats.
public GcWicBitmap.Palette GetPalette()
Loads the image from an instance of the GcBitmap class.
If the source image is not opaque, the color channels must be premultiplied with the alpha channel.
public void Import(GcBitmap sourceBitmap)
Loads the image from another instance of GcWicBitmap.
public void Import(GcWicBitmap sourceWicBitmap)
sourceWicBitmap
GcWicBitmapThe source GcWicBitmap.
Loads the image from a byte array containing the pixels buffer.
public void Import(byte[] bytes, int width, int height, WicPixelFormat pixelFormat)
bytes
byte[]The source byte array with pixel buffer.
width
intThe width of the image, in pixels.
height
intThe height of the image, in pixels.
pixelFormat
WicPixelFormatThe pixel format of the image.
Loads the image from a byte array containing the pixels buffer with specified stride (bytes per row of pixels).
public void Import(byte[] bytes, int stride, int width, int height, WicPixelFormat pixelFormat)
bytes
byte[]The source byte array with pixel buffer.
stride
intThe stride (bytes per row) of the image data in the source byte array.
width
intThe width of the image, in pixels.
height
intThe height of the image, in pixels.
pixelFormat
WicPixelFormatThe pixel format of the image.
Loads the image from the unmanaged block of memory pointed by IntPtr.
public void Import(IntPtr srcPtr, int width, int height, WicPixelFormat pixelFormat)
srcPtr
System.IntPtrThe pointer to the beginning of the unmanaged block of memory.
width
intThe width of the image, in pixels.
height
intThe height of the image, in pixels.
pixelFormat
WicPixelFormatThe pixel format of the image.
Loads the image from a unmanaged block of memory pointed by IntPtr and having the specified stride (bytes per row of pixels).
public void Import(IntPtr srcPtr, int stride, int width, int height, WicPixelFormat pixelFormat)
srcPtr
System.IntPtrThe pointer to the beginning of the unmanaged block of memory.
stride
intThe stride (bytes per row) of the source image data.
width
intThe width of the image, in pixels.
height
intThe height of the image, in pixels.
pixelFormat
WicPixelFormatThe pixel format of the image.
Loads a GcBitmap at the given destination within the image.
If the source image is not opaque, the color channels must be premultiplied with the alpha channel.
public void ImportAsFragment(GcBitmap sourceBitmap, int xDst, int yDst)
sourceBitmap
GcBitmapThe source GcBitmap.
xDst
intThe destination X pixel coordinate within the target bitmap.
yDst
intThe destination Y pixel coordinate within the target bitmap.
Loads another GcWicBitmap at the given destination within the image.
public void ImportAsFragment(GcWicBitmap sourceWicBitmap, int xDst, int yDst)
sourceWicBitmap
GcWicBitmapThe source GcWicBitmap.
xDst
intThe destination X pixel coordinate within the target bitmap.
yDst
intThe destination Y pixel coordinate within the target bitmap.
Loads the pixel buffer from a byte array at the given destination within the image.
public void ImportAsFragment(byte[] bytes, Rectangle dstRect)
bytes
byte[]The source byte array with pixel buffer.
dstRect
System.Drawing.RectangleThe destination rectangle within the target bitmap.
Copies the unmanaged block of memory ato the given destination within the image.
public void ImportAsFragment(IntPtr srcPtr, Rectangle dstRect)
srcPtr
System.IntPtrThe pointer to the beginning of the unmanaged block of memory.
dstRect
System.Drawing.RectangleThe destination rectangle within the target bitmap.
Loads the image from a System.IO.Stream. JPEG, PNG, GIF, BMP, TIFF, ICO, JPEG XR formats are supported.
public void Load(Stream stream, params BaseTransform[] transforms)
stream
System.IO.StreamThe input stream.
transforms
BaseTransform[]The transformation chain for the image that is being loaded.
Loads the image from a System.IO.Stream. JPEG, PNG, GIF, BMP, TIFF, ICO, JPEG XR formats are supported.
public void Load(Stream stream, WicContainerFormat containerFormat, int frameIndex, Rectangle? imageRect, params BaseTransform[] transforms)
stream
System.IO.StreamThe input stream.
containerFormat
WicContainerFormatThe image container format; use Unknown to detect the format automatically.
frameIndex
intIndex of an image frame to read, pass 0 for image formats not supporting multiple frames.
imageRect
System.Drawing.Rectangle?Clipping rectangle for the image after all transformations.
transforms
BaseTransform[]The transformation chain for the image that is being loaded.
Loads the image from a file. JPEG, PNG, GIF, BMP, TIFF, ICO, JPEG XR formats are supported.
public void Load(string path, params BaseTransform[] transforms)
path
stringThe file path to the image.
transforms
BaseTransform[]The transformation chain for the image that is being loaded.
Loads the image from a file. JPEG, PNG, GIF, BMP, TIFF, ICO, JPEG XR formats are supported.
public void Load(string path, WicContainerFormat containerFormat, int frameIndex, Rectangle? imageRect, params BaseTransform[] transforms)
path
stringThe file path to the image.
containerFormat
WicContainerFormatThe image container format; use Unknown to detect the format automatically.
frameIndex
intIndex of an image frame to read, pass 0 for image formats not supporting multiple frames.
imageRect
System.Drawing.Rectangle?Clipping rectangle for the image after all transformations.
transforms
BaseTransform[]The transformation chain for the image that is being loaded.
Converts a GUID of the WIC pixel format to the PixelFormat enumeration value.
public static WicPixelFormat PixelFormatFromGuid(Guid pfGuid)
pfGuid
System.GuidThe GUID of the WIC pixel format.
Returns a GUID of the corresponding WIC pixel format for the given value of the PixelFormat enumeration.
public static Guid PixelFormatToGuid(WicPixelFormat pixelFormat)
pixelFormat
WicPixelFormatThe PixelFormat enumeration value.
Saves the image to a System.IO.Stream using the specified format and options.
public void Save(Stream stream, WicContainerFormat format, BaseOptions options = null)
stream
System.IO.StreamThe output stream.
format
WicContainerFormatThe container format that determines the image encoder.
options
BaseOptionsThe options for the specified image encoder.
Saves the image to a file using the specified format and options.
public void Save(string fileName, WicContainerFormat format, BaseOptions options = null)
fileName
stringThe output file name.
format
WicContainerFormatThe container format that determines the image encoder.
options
BaseOptionsThe options for the specified image encoder.
Saves the image to a System.IO.Stream in BMP format.
public void SaveAsBmp(Stream stream, BmpOptions options = null)
stream
System.IO.StreamThe output stream.
options
BmpOptionsThe options for the BMP image encoder.
Saves the image to a file in BMP format.
public void SaveAsBmp(string fileName, BmpOptions options = null)
fileName
stringThe output file name.
options
BmpOptionsThe options for the BMP image encoder.
Saves the image to a System.IO.Stream in GIF format.
public void SaveAsGif(Stream stream, GifOptions options = null)
stream
System.IO.StreamThe output stream.
options
GifOptionsThe options for the GIF image encoder.
Saves the image to a file in GIF format.
public void SaveAsGif(string fileName, GifOptions options = null)
fileName
stringThe output file name.
options
GifOptionsThe options for the GIF image encoder.
Saves the image to a System.IO.Stream in JPEG format.
public void SaveAsJpeg(Stream stream, JpegOptions options = null)
stream
System.IO.StreamThe output stream.
options
JpegOptionsThe options for the JPEG image encoder.
Saves the image to a file in JPEG format.
public void SaveAsJpeg(string fileName, JpegOptions options = null)
fileName
stringThe output file name.
options
JpegOptionsThe options for the JPEG image encoder.
Saves the image to a System.IO.Stream in JPEG XR format.
public void SaveAsJpegXR(Stream stream, JpegXROptions options = null)
stream
System.IO.StreamThe output stream.
options
JpegXROptionsThe options for the JPEG XR image encoder.
Saves the image to a file in JPEG XR format.
public void SaveAsJpegXR(string fileName, JpegXROptions options = null)
fileName
stringThe output file name.
options
JpegXROptionsThe options for the JPEG XR image encoder.
Saves the image to a System.IO.Stream in PNG format.
public void SaveAsPng(Stream stream, PngOptions options = null)
stream
System.IO.StreamThe output stream.
options
PngOptionsThe options for the PNG image encoder.
Saves the image to a file in PNG format.
public void SaveAsPng(string fileName, PngOptions options = null)
fileName
stringThe output file name.
options
PngOptionsThe options for the PNG image encoder.
Saves the image to a System.IO.Stream in TIFF format.
public void SaveAsTiff(Stream stream, TiffOptions options = null)
stream
System.IO.StreamThe output stream.
options
TiffOptionsThe options for the TIFF image encoder.
Saves the image to a file in TIFF format.
public void SaveAsTiff(string fileName, TiffOptions options = null)
fileName
stringThe output file name.
options
TiffOptionsThe options for the TIFF image encoder.
Changes the physical resolution of the image.
public void SetDpi(float dpiX, float dpiY)
dpiX
floatThe horizontal resolution.
dpiY
floatThe vertical resolution.
Changes the physical resolution of the image.
public void SetDpi(float dpi)
dpi
floatThe horizontal and vertical resolution.
Assigns a shared instance of the GrapeCity.Documents.Imaging.Windows.GcWicBitmap.FontCache object.
public void SetFontCache(FontCache fontCache)
fontCache
FontCacheSets the license key.
public static void SetLicenseKey(string key)
key
stringThe license key to set.
Sets the new color table for the bitmap.
public void SetPalette(GcWicBitmap.Palette palette)
palette
GcWicBitmap.PaletteStores the image buffer to a byte array (without the palette and metadata information).
public byte[] ToByteArray()
Stores a rectangular area of the image to a byte array.
public byte[] ToByteArray(Rectangle srcRect)
srcRect
System.Drawing.RectangleThe source rectangle within the image.
Stores the image buffer to a byte array with the same stride (bytes per row).
public byte[] ToByteArray(out int stride)
stride
intReturns the stride (bytes per row) of the image.
Stores the image buffer into an existing instance of GcBitmap.
public void ToGcBitmap(GcBitmap bmp, bool updatePixelFormat = false)
bmp
GcBitmapThe destination GcBitmap object.
updatePixelFormat
boolIndicates if all pixels should be converted from premultiplied alpha format or to opaque format with alpha = 255.
Stores the image buffer to a GcBitmap.
public GcBitmap ToGcBitmap(bool updatePixelFormat = false)
updatePixelFormat
boolIndicates if all pixels should be converted from premultiplied alpha format or to opaque format with alpha = 255.
Stores a rectangular area of the image to a GcBitmap.
public GcBitmap ToGcBitmap(Rectangle srcRect, bool updatePixelFormat = false)
srcRect
System.Drawing.RectangleThe source rectangle within the image.
updatePixelFormat
boolIndicates if all pixels should be converted from premultiplied alpha format or to opaque format with alpha = 255.
Creates a new instance of GcWicBitmap as a copy of the current bitmap passed through the set of transformations.
public GcWicBitmap Transform(params BaseTransform[] transforms)
transforms
BaseTransform[]The transformation chain, can be empty to just copy the image.