Share via


CGContext.AsBitmapContext 方法

定义

将 CGContext 强制转换为 CGBitmapContext。

public CoreGraphics.CGBitmapContext AsBitmapContext ();
member this.AsBitmapContext : unit -> CoreGraphics.CGBitmapContext

返回

注解

虽然有不同类型的 CGContext 类型 (常规、位图和 PDF) ,但 Apple 不支持区分这些类型。 某些 CGContext 对象实际上已知为 CGBitmapContext 对象,在创建上下文或BeginImageContextWithOptions(CGSize, Boolean, nfloat)) 后BeginImageContext(CGSize) (调用GetImageFromCurrentImageContext()

这些实际上是 CGBitmapContext 对象,通过转换它,应用程序开发人员可以访问其上的各种位图属性。

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
};

适用于