iOS Guides | Samples

CoreGraphics.CGContext.AsBitmapContext Method

Casts the CGContext into a CGBitmapContext.


public CGBitmapContext AsBitmapContext ()



While there are different kinds of CGContext kinds (regular, bitmap and PDF), Apple does not support a way to tell those apart. Certain CGContext objects are actually known to be CGBitmapContext objects in a few situations (calling UIGraphics.GetCurrentContext after creating a context with UIGraphics.BeginImageContext or UIGraphics.BeginImageContextWithOptions).

Those are really CGBitmapContext objects and by converting it, application developers can access the various bitmap properties on it.

C# Example

UIGraphics.BeginImageContextWithOptions (image.Size, false, UIScreen.MainScreen.Scale);
CGBitmapContext effectInContext = UIGraphics.GetCurrentContext ().AsBitmapContext ()
// Now, you can access some interesting properties like "Data", "Width", 
// "Height", "BytesPerRow" from the underlying bitmap
var effectInBuffer = new vImageBuffer () {
        Data = effectInContext.Data,
        Width = effectInContext.Width,
        Height = effectInContext.Height,
        BytesPerRow = effectInContext.BytesPerRow


Namespace: CoreGraphics
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: