Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

Previous items

NSImageMBS.initWithPicture(img as picture, mask as picture = nil) as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: Initializes the image object with image data from the Realbasic pictures.
Example:
dim img as new NSImageMBS
if img.initWithPicture(pict, pict.mask) then
MsgBox "OK"
end if
Notes:
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.

Feedback, Comments & Corrections

NSImageMBS.initWithSize(width as Double, height as Double) as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: Initializes an empty image object with the given size.
Notes: Returns true on success and false on failure.

Feedback, Comments & Corrections

NSImageMBS.JPEGRepresentation as Memoryblock
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: The image as the binary data in a JPEG file.
Example:
dim img as NSImageMBS
dim p as Picture
dim f as FolderItem
dim b as BinaryStream

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

f=SpecialFolder.Desktop.Child("test.jpeg")
b=f.CreateBinaryFile("")
b.Write img.JPEGRepresentation
b.Close

f.Launch
Notes: JPEG does not support masks. Uses 80% for the quality.

Feedback, Comments & Corrections

NSImageMBS.JPEGRepresentationMT as Memoryblock
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 13.1 Yes No No Yes, macOS only No
Function: The image as the binary data in a JPEG file.
Example:
// take some Picture
dim logo as Picture = LogoMBS(500)

// make a NSImageMBS from it
dim nsimage as new NSImageMBS(logo)

// use thread friendly compress function
dim jpeg as MemoryBlock = nsimage.JPEGRepresentationMT

// decode to see if it worked
dim test as Picture = JPEGStringToPictureMBS(jpeg)

// and display
Backdrop = test
Notes:
JPEG does not support masks. Uses 80% for the quality.
Must be called inside a Xojo (Real Studio) thread so time yields to main thread and you can keep the GUI running.

Feedback, Comments & Corrections

NSImageMBS.JPEGRepresentationWithCompressionFactor(factor as Double) as Memoryblock
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: The image as the binary data in a JPEG file.
Example:
dim img as NSImageMBS
dim p as Picture
dim f as FolderItem
dim b as BinaryStream

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

f=SpecialFolder.Desktop.Child("test.jpeg")
b=f.CreateBinaryFile("")
b.Write img.JPEGRepresentationWithCompressionFactor(0.01)
b.Close

f.Launch
Notes:
Factor for compression goes from 0.0 to 1.0.
JPEG does not support masks.

Feedback, Comments & Corrections

NSImageMBS.JPEGRepresentationWithCompressionFactorMT(factor as Double) as Memoryblock
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 13.1 Yes No No Yes, macOS only No
Function: The image as the binary data in a JPEG file.
Example:
// take some Picture
dim logo as Picture = LogoMBS(500)

// make a NSImageMBS from it
dim nsimage as new NSImageMBS(logo)

// use thread friendly compress function
dim jpeg as MemoryBlock = nsimage.JPEGRepresentationWithCompressionFactorMT(1.0)

// decode to see if it worked
dim test as Picture = JPEGStringToPictureMBS(jpeg)

// and display
Backdrop = test
Notes:
Factor for compression goes from 0.0 to 1.0.
JPEG does not support masks.
Must be called inside a Xojo (Real Studio) thread so time yields to main thread and you can keep the GUI running.

Feedback, Comments & Corrections

NSImageMBS.PNGRepresentation as Memoryblock
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: The image as the binary data in a PNG file.
Example:
dim img as NSImageMBS
dim p as Picture
dim f as FolderItem
dim b as BinaryStream

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

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

f.Launch
Notes: PNG does support masks.

Feedback, Comments & Corrections

NSImageMBS.PNGRepresentationMT as Memoryblock
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 13.1 Yes No No Yes, macOS only No
Function: The image as the binary data in a PNG file.
Example:
// take some Picture
dim logo as Picture = LogoMBS(500)

// make a NSImageMBS from it
dim nsimage as new NSImageMBS(logo)

// use thread friendly compress function
dim jpeg as MemoryBlock = nsimage.PNGRepresentationMT

// decode to see if it worked
dim test as Picture = PNGStringToPictureMBS(jpeg)

// and display
Backdrop = test
Notes:
PNG does support masks.
Must be called inside a Xojo (Real Studio) thread so time yields to main thread and you can keep the GUI running.

Feedback, Comments & Corrections

NSImageMBS.recache
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 9.6 Yes No No Yes, macOS only No
Function: Invalidates and frees the offscreen caches of all image representations.
Notes:
If you modify an image representation, you must send a recache message to the corresponding image object to force the changes to be recached. The next time any image representation is drawn, it is asked to recreate its cached image. If you do not send this message, the image representation may use the old cache data. This method simply clears the cached image data; it does not delete the NSCachedImageRep objects associated with any image representations.
If you do not plan to use an image again right away, you can free its caches to reduce the amount of memory consumed by your program.

Feedback, Comments & Corrections

NSImageMBS.removeRepresentation(img as NSImageRepMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 8.4 Yes No No Yes, macOS only No
Function: Removes the specified image representation from the receiver and releases it.

Feedback, Comments & Corrections

NSImageMBS.RepresentationHeight(index as Integer) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: Height of the representation with the given index in pixel.
Notes:
Index from 0 to RepresetationCount-1.
Returns 0 on invalid index.

Feedback, Comments & Corrections

NSImageMBS.representations as NSImageRepMBS()
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: Returns an array containing all of the receiver's image representations.
Notes:
An array containing zero or more NSImageRep objects.
Returns nil on any error.

Feedback, Comments & Corrections

NSImageMBS.RepresentationWidth(index as Integer) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: Width of the representation with the given index in pixel.
Notes:
Index from 0 to RepresetationCount-1.
Returns 0 on invalid index.

Feedback, Comments & Corrections

NSImageMBS.setName(value as String) as Boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: Registers the image under the specified name.
Notes:
Returns true if the receiver was successfully registered with the given name; otherwise, false.

Discussion
If the receiver is already registered under a different name, this method unregisters the other name. If a different image is registered under the name specified in aString, this method does nothing and returns false.

When naming an image using this method, it is convention not to include filename extensions in the names you specify. That way, you can easily distinguish between images you have named explicitly and those you want to load from the application's bundle. For information about the rules used to search for images, see the imageNamed method.

Feedback, Comments & Corrections

NSImageMBS.setSize(width as Double, height as Double)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: Sets the width and height of the image.
Notes:
Pass the new size of the image, measured in points.

Discussion:
The size of an NSImage object must be set before it can be used. If the size of the image hasn't already been set when an image representation is added, the size is taken from the image representation's data. For EPS images, the size is taken from the image's bounding box. For TIFF images, the size is taken from the ImageLength and ImageWidth attributes.

Changing the size of an NSImage after it has been used effectively resizes the image. Changing the size invalidates all its caches and frees them. When the image is next composited, the selected representation will draw itself in an offscreen window to recreate the cache.

Feedback, Comments & Corrections

NSImageMBS.TIFFRepresentation as Memoryblock
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: Returns a string containing TIFF data for all of the image representations in the receiver.
Notes:
A string containing the TIFF data, or nil if the TIFF data could not be created.

Discussion:
You can use the returned data object to write the TIFF data to a file. For each image representation, this method uses the TIFF compression option associated with that representation or NSTIFFCompressionNone, if no option is set.

If one of the receiver's image representations does not support the creation of TIFF data natively (PDF and EPS images, for example), this method creates the TIFF data from that representation's cached content.

Feedback, Comments & Corrections

NSImageMBS.TIFFRepresentationMT as Memoryblock
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 13.1 Yes No No Yes, macOS only No
Function: Returns a string containing TIFF data for all of the image representations in the receiver.
Example:
// take some Picture
dim logo as Picture = LogoMBS(500)

// make a NSImageMBS from it
dim nsimage as new NSImageMBS(logo)

// use thread friendly compress function
dim data as MemoryBlock = nsimage.TIFFRepresentationMT

// decode to see if it worked
dim test as Picture = TIFFStringToPictureMBS(data)

// and display
Backdrop = test
Notes:
A string containing the TIFF data, or nil if the TIFF data could not be created.

Discussion:
You can use the returned data object to write the TIFF data to a file. For each image representation, this method uses the TIFF compression option associated with that representation or NSTIFFCompressionNone, if no option is set.

If one of the receiver's image representations does not support the creation of TIFF data natively (PDF and EPS images, for example), this method creates the TIFF data from that representation's cached content.

Must be called inside a Xojo (Real Studio) thread so time yields to main thread and you can keep the GUI running.

Feedback, Comments & Corrections

NSImageMBS.TIFFRepresentationUsingCompression(comp as Integer, factor as Double) as Memoryblock
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 7.2 Yes No No Yes, macOS only No
Function: Returns a string containing TIFF data for all of the image representations in the receiver.
Notes:
comp: The type of compression to use. For a list of values, see the constants in NSBitmapImageRep.

aFloat: Provides a hint for compression types that implement variable compression ratios. Currently, only JPEG compression uses a compression factor.

Returns a string containing the TIFF data, or nil if the TIFF data could not be created.

Discussion:
You can use the returned data object to write the TIFF data to a file. If the specified compression isn't applicable, no compression is used. If a problem is encountered during generation of the TIFF data, this method may raise an exception.

If one of the receiver's image representations does not support the creation of TIFF data natively (PDF and EPS images, for example), this method creates the TIFF data from that representation's cached content.

Feedback, Comments & Corrections

NSImageMBS.TIFFRepresentationUsingCompressionMT(comp as Integer, factor as Double) as Memoryblock
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa Drawing MBS MacBase Plugin 13.1 Yes Yes Yes Yes No
Function: Returns a string containing TIFF data for all of the image representations in the receiver.
Notes:
comp: The type of compression to use. For a list of values, see the constants in NSBitmapImageRep.

aFloat: Provides a hint for compression types that implement variable compression ratios. Currently, only JPEG compression uses a compression factor.

Returns a string containing the TIFF data, or nil if the TIFF data could not be created.

Discussion:
You can use the returned data object to write the TIFF data to a file. If the specified compression isn't applicable, no compression is used. If a problem is encountered during generation of the TIFF data, this method may raise an exception.

If one of the receiver's image representations does not support the creation of TIFF data natively (PDF and EPS images, for example), this method creates the TIFF data from that representation's cached content.

Must be called inside a Xojo (Real Studio) thread so time yields to main thread and you can keep the GUI running.

Feedback, Comments & Corrections

Previous items

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




Links
MBS Xojo Chart Plugins