Platforms to show: All Mac Windows Linux Cross-Platform

Back to CGImageMBS class.

CGImageMBS.Constructor   Private

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

CGImageMBS.Copy as CGImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 8.6 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a copy of a bitmap image.

See also:

CGImageMBS.Copy(r as CGRectMBS) as CGImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 8.6 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a copy of a bitmap image.

See also:

CGImageMBS.CopyWithColorSpace(profile as CGColorSpaceMBS) as CGImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a copy of the image with the new Colorspace included.
Example
// load a picture
dim f as FolderItem = SpecialFolder.Desktop.Child("ColorSpin.jpg")
dim pic as Picture = picture.Open(f)

// open printer
dim g as Graphics = OpenPrinterDialog
if g = nil then Return

// draw
g.DrawPicture pic, 0, 0

// now load again
dim ImageSource as new CGImageSourceMBS(f)
dim img as CGImageMBS = ImageSource.CreateImageAtIndex(0)
dim cs as CGColorSpaceMBS = CGColorSpaceMBS.CreateDeviceRGB

// copy with replacing colorspace
img = img.CopyWithColorSpace(cs)

// and draw
#If XojoVersion >= 2019.02 Then
Dim p As ptr = g.Handle(Graphics.HandleTypes.CGContextRef)
Dim c As CGContextMBS = CGContextMBS.contextWithCGContext(p)
#Else
Dim h As Integer = g.Handle(g.HandleTypeCGContextRef)
Dim c As CGContextMBS = CGContextMBS.contextWithCGContext(h)
#EndIf
dim r as CGRectMBS = CGMakeRectMBS(0, 0, img.Width, img.Height)

c.DrawPicture(img, r)
c.Flush

profile must be a CGColorSpaceMBS.
Requires Mac OS X 10.3.

CGImageMBS.CopyWithMask(mask as CGImageMBS) as CGImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 8.6 ✅ Yes ❌ No ❌ No ✅ Yes All
reates a bitmap image from an existing image and an image mask.

Parameters:

self: The image to apply the mask parameter to. This image must not be an image mask and may not have an image mask or masking color associated with it.

mask: A mask. If the mask is an image, it must be in the DeviceGray color space, must not have an alpha component, and may not itself be masked by an image mask or a masking color. If the mask is not the same size as the image specified by the image parameter, then Quartz scales the mask to fit the image.

Return Value: An image created by masking image with mask. You are responsible for releasing this object by calling CGImageRelease.

The resulting image depends on whether the mask parameter is an image mask or an image. If the mask parameter is an image mask, then the source samples of the image mask act as an inverse alpha value. That is, if the value of a source sample in the image mask is S, then the corresponding region in image is blended with the destination using an alpha value of (1-S). For example, if S is 1, then the region is not painted, while if S is 0, the region is fully painted.

If the mask parameter is an image, then it serves as an alpha mask for blending the image onto the destination. The source samples of mask' act as an alpha value. If the value of the source sample in mask is S, then the corresponding region in image is blended with the destination with an alpha of S. For example, if S is 0, then the region is not painted, while if S is 1, the region is fully painted.

CGImageMBS.DataProvider as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ✅ Yes All
The data provider used for the image.

Value is a CGDataProviderMBS object.
Returns nil on any error.

CGImageMBS.DecodeArray as memoryblock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 3.3 ✅ Yes ❌ No ❌ No ✅ Yes All
The decode array used for the image.

A memoryblock with an array of double variables.
Returns nil on any error.

CGImageMBS.JPEGData(Compression as Integer = 90) as MemoryBlock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 14.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns image compressed as JPEG file.

Compression defines the compression level from 0 to 100.
Returns nil on any error.

CGImageMBS.Picture(ColorSpace as CGColorSpaceMBS = nil) as Picture

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a copy of the CGImage as a picture.
Example
// get CGImage
dim f as FolderItem = SpecialFolder.Desktop.Child("bild.jpg")
dim c as CGImageMBS = CGImageMBS.CreateImageWithFile(f)
// get picture
dim p as Picture = c.Picture
// save as jpeg
dim d as FolderItem = SpecialFolder.Desktop.Child("output.jpg")
p.Save(d, p.SaveAsJPEG, 80)

Colorspace: the optional CoreGraphcis Colorspace to use for the bitmap conversion (CGColorSpaceMBS class).
Returns nil on any error.

CGImageMBS.PictureScaled(OutputWidth as Integer, OutputHeight as Integer, ColorSpace as CGColorSpaceMBS = nil) as Picture

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 17.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a copy of the CGImage as a picture scaled.
Example
// get CGImage
dim f as FolderItem = SpecialFolder.Desktop.Child("bild.jpg")
dim c as CGImageMBS = CGImageMBS.CreateImageWithFile(f)
// get picture
dim p as Picture = c.PictureScaled(640,480)
// save as jpeg
dim d as FolderItem = SpecialFolder.Desktop.Child("output.jpg")
p.Save(d, p.SaveAsJPEG, 80)

Colorspace: the optional CoreGraphcis Colorspace to use for the bitmap conversion (CGColorSpaceMBS class).
Returns nil on any error.

If output width and height are zero, we use the image sizes.

CGImageMBS.PNGData as MemoryBlock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 14.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns image compressed as PNG file.

Returns nil on any error.

Some examples using this method:

CGImageMBS.ReleaseHandle

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 14.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Decrements the retain count of a CGImageRef.

Each retain must have a release. Too many releases and your app will crash, too many retains and it will leak memory.
Use only if you really know what you are doing.

CGImageMBS.RetainHandle

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreGraphics MBS MacCG Plugin 14.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Increments the retain count of a CGImageRef.

Each retain must have a release. Too many releases and your app will crash, too many retains and it will leak memory.
Use only if you really know what you are doing.

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


The biggest plugin in space...