Platforms to show: All Mac Windows Linux Cross-Platform

Back to CGBitmapContextMBS class.

CGBitmapContextMBS.CGImage(shouldInterpolate as boolean = false, intent as Integer = 0) as CGImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 4.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a CGImageMBS object referencing the CGBitmapContext object.
Example
dim c as CGPictureContextMBS
dim w as CGContextMBS // of window

c=new CGPictureContextMBS(100,100)

c.SetRGBFillColor 1,0,0,1
c.FillRect CGMakeRectMBS(0,0,50,50)

w=window1.CGContextMBS // we are inside paint event!
w.DrawPicture c.CGImage(false,0),CGMakeRectMBS(0,0,c.BitmapWidth,c.BitmapHeight)
w.Flush

You will crash your application if you use this Image after the CGBitmapContext object was destroyed.
Changes made to the connected CGBitmapContext will be seen in the CGImage.
Returns nil on low memory.

Constants for intent:
kCGRenderingIntentDefault0
kCGRenderingIntentAbsoluteColorimetric1
kCGRenderingIntentRelativeColorimetric2
kCGRenderingIntentPerceptual3
kCGRenderingIntentSaturation4

Set shouldInterpolate to true if the image should use interpolation.

CGBitmapContextMBS.Constructor   Private

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 13.1 ✅ Yes ❌ No ❌ No ✅ Yes All
The private constructor.

CGBitmapContextMBS.CreateImage as CGImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 13.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Return an image containing a snapshot of the bitmap context.
Example
// a new picture in RB
dim pic as new Picture(500, 500)

// and create CGBitmapContextMBS pointing to it
dim b as CGBitmapContextMBS = CGBitmapContextMBS.CreateWithPicture(pic)

// color set to full red
b.SetRGBFillColor 1.0, 0.0, 0.0, 1.0

// draw ellipse
dim r as CGRectMBS = CGRectMBS.Make(0, 0, 500, 500)
b.FillEllipseInRect r

// flush drawings
b.Flush

// now try CGImage creation
dim cgimage as CGImageMBS = b.CreateImage

// and display by converting to a new picture
Backdrop = cgimage.Picture

If context is not a bitmap context, or if the image cannot be created for any reason, this function returns NULL. This is a "copy" operation subsequent changes to context will not affect the contents of the returned image.

Note that in some cases the copy will actually follow "copy-on-write" semantics, so that the actual physical copy of the bits will only occur if the underlying data in the bitmap context is modified. As a consequence, you may wish to use the resulting image and release it before performing more drawing into the bitmap context; in this way, the actual physical copy of the data may be avoided.

The items on this page are in the following plugins: MBS MacCG Plugin.


The biggest plugin in space...