Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSImageMBS class.

NSImageMBS.imageByFadingToFraction(fraction as Double) as NSImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns an image with a mask faded to the given percentage
Example
Var img as NSImageMBS
Var p as Picture
Var f as FolderItem
Var b as BinaryStream

p=New Picture(100,100,32)
p.Graphics.ForeColor=&cFF0000
p.Graphics.FillOval 0,0,100,100
Backdrop=p
img=new NSImageMBS(p)

img=img.imageByFadingToFraction(0.1)

f=SpecialFolder.Desktop.Child("test.png")
b=f.CreateBinaryFile("")
b.Write img.PNGRepresentation
b.Close

f.Launch

Returns nil on failure.

NSImageMBS.imageByScalingToSize(width as Double, height as Double) as NSImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Scales image to the new size.
Example
Var img as NSImageMBS
Var p as Picture
Var f as FolderItem
Var b as BinaryStream

p=New Picture(100,100,32)
p.Graphics.ForeColor=&cFF0000
p.Graphics.FillOval 0,0,100,100
Backdrop=p
img=new NSImageMBS(p)

img=img.imageByScalingToSize(200,200)

f=SpecialFolder.Desktop.Child("test.png")
b=f.CreateBinaryFile("")
b.Write img.PNGRepresentation
b.Close

f.Launch

Returns nil on failure.
Internally creates a copy of the image.

See also:

Some examples using this method:

NSImageMBS.imageByScalingToSize(width as Double, height as Double, fraction as Double) as NSImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Scales image to the new size with given fading.
Example
Var img as NSImageMBS
Var p as Picture
Var f as FolderItem
Var b as BinaryStream

p=New Picture(100,100,32)
p.Graphics.ForeColor=&cFF0000
p.Graphics.FillOval 0,0,100,100
Backdrop=p
img=new NSImageMBS(p)

img=img.imageByScalingToSize(200,200,0.5)

f=SpecialFolder.Desktop.Child("test.png")
b=f.CreateBinaryFile("")
b.Write img.PNGRepresentation
b.Close

f.Launch

Returns nil on failure.
Internally creates a copy of the image.

See also:

NSImageMBS.imageByScalingToSize(width as Double, height as Double, fraction as Double, flip as boolean, proportionally as boolean) as NSImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Scales image to the new size with given fading fraction.
Example
Var img as NSImageMBS
Var p as Picture
Var f as FolderItem
Var b as BinaryStream

p=New Picture(100,100,32)
p.Graphics.ForeColor=&cFF0000
p.Graphics.FillOval 0,0,100,100
Backdrop=p
img=new NSImageMBS(p)

img=img.imageByScalingToSize(200,200)

f=SpecialFolder.Desktop.Child("test.png")
b=f.CreateBinaryFile("")
b.Write img.PNGRepresentation
b.Close

f.Launch

Returns nil on failure.
The image can be flipped vertically with the flip property.
Internally creates a copy of the image.

See also:

NSImageMBS.imageWithSymbolConfiguration(configuration as NSImageSymbolConfigurationMBS) as NSImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 22.1 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Creates a new symbol image with the specified configuration.
Example
Var config As NSImageSymbolConfigurationMBS = NSImageSymbolConfigurationMBS.configurationWithPointSize(40, 0)
Var n As NSImageMBS = NSImageMBS.imageWithSystemSymbolName("trash")
Var o As NSImageMBS = n.imageWithSymbolConfiguration(config)

Backdrop = o.CopyPictureWithAlpha

NSImageMBS.imageWithTintColor(tintColor as NSColorMBS) as NSImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 20.1 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Creates a copy of the image colored with the given tint.

Input image should be grayscale.

NSImageMBS.initWithContentsOfURL(file as folderitem) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes and returns an NSImage instance with the contents of the specified folderitem.

Returns true on success and false on failure.

See also:

NSImageMBS.initWithContentsOfURL(url as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes and returns an NSImage instance with the contents of the specified URL.

Returns true on success and false on failure.

See also:

NSImageMBS.initWithData(data as Memoryblock) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes and with the contents of the specified data in the string.

Returns true on success and false on failure.

NSImageMBS.initWithDataIgnoringOrientation(data as Memoryblock) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 9.6 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Initializes and returns an NSImage instance with the contents of the specified memoryblock, ignoring the EXIF orientation tags.

An initialized NSImage instance, or nil if the method cannot create an image representation from the contents of the specified data object.
Available in Mac OS X v10.6 and later.

NSImageMBS.initWithIconRef(IconHandle as Integer) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 9.6 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Initializes the image object with a Carbon-style icon resource.

IconHandle: A reference to a Carbon icon resource (IconRef).

Creates one or more bitmap image representations, one for each size icon contained in the IconRef data structure. This initialization method automatically retains the data in the iconRef parameter and loads the bitmaps from that data file lazily.
Available in Mac OS X v10.5 and later.

NSImageMBS.initWithPasteboard as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 9.6 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes an NSImage instance with data from the pasteboard.

The specified pasteboard should contain a type supported by one of the registered NSImageRep subclasses. Table 1 lists the default pasteboard types and file extensions for several NSImageRep subclasses.

NSImageMBS.initWithPicture(img as picture, mask as picture = nil) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes the image object with image data from the Xojo pictures.
Example
Var img as new NSImageMBS
if img.initWithPicture(pict, pict.mask) then
MsgBox "OK"
end if

Optional you can pass a picture with the mask. It is valid to use the mask property of the image for the second parameter.

With 11.3 plugins we are deprecating to pass a mask. The plugin prefers to simply take the mask or alpha channel of the picture itself.

On success the image is valid and the handle is not zero.

Some examples using this method:

NSImageMBS.initWithSize(width as Double, height as Double) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Initializes an empty image object with the given size.

Returns true on success and false on failure.

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


The biggest plugin in space...