Picture.CopyOSHandle

From Xojo Documentation

Method

Picture.CopyOSHandle(type As Picture.HandleType) As Ptr

New in 2011r1

Supported for all project types and targets.

Returns a platform-specific image handle.


Method

Picture.CopyOSHandle(width As Integer, height As Integer, scale As Double, type As Picture.HandleType) As Ptr

New in 2016r1

Supported for all project types and targets.

Returns a platform-specific image handle that is the best match for drawing at the given resolution, using the same logic as Picture.BestRepresentation.

fa-info-circle-32.png
The handle returned is a copy of the underlying data and will not be modified if the Picture itself is modified. Also, since it is a copy, it is your responsibility to release it using the proper OS API.
Class Constant Description
MacCGImage A CGImageRef that you are responsible for releasing with CFRelease. Supported in macOS GUI applications.
WindowsBMP A 32-bit HBITMAP that you are responsible for releasing with DeleteObject. Supported in Windows GUI applications.
WindowsICON A 32-bit HICON that you are responsible for releasing with DeleteObject. Supported in Windows GUI applications.
LinuxGdkPixbuf A 32-bit GdkPixbuf that you are responsible for releasing with g_object_unref. Supported in Linux GUI applications.
ConsoleGDImage A gdImagePtr that you are responsible for releasing with gdFree. This requires the use of the libgd library. Supported in console applications (all platforms).
MacNSImage An NSImage object that has been autoreleased, so an explicit release is not necessary. This is supported for all types of Pictures, including vector images. Supported in macOS GUI applications.

Example

The following code gets the CGImageRef from the Picture and properly releases it.

Declare Sub CFRelease Lib "CoreFoundation" (obj As Ptr)

Dim pict As New Picture(100, 100, 32)
Dim cgImage As Ptr = pict.CopyOSHandle(Picture.HandleType.MacCGImage)
// Do something with the 'cgImage' object
CFRelease(cgImage)