Description
In
BBj 9.00 and higher, the
BBXImage
utility provides an object-oriented way to manipulate an image in a variety of ways.
Obtain the
BBXImage
from a BBjImage, from a file on the server, or from a URL such as an HTTP URL that retrieves an image from the Internet.
You can then modify the
BBXImage
in a number of ways and affect its scale (as a percentage or proportional to width or height),
rotation, and opacity. It is also possible to add borders, drop shadows, reflections, and even crop the corners of the image.
After manipulating the
BBXImage
, the class offers methods to save it in a variety of image formats such as a PNG or JPG file with a configurable compression percentage.
In
BBj 15.0 and higher, the
BBXImage
Utility provides filtering methods to
- Adjust the brightness of the image
- Adjust the contrast of the image
- Blur the image
- Sharpen the image
- Convert the image to grayscale
In BBj 16.0 and higher, the BBXImage
Utility provides methods to
- Modify the canvas size and facilitate scaling an image while maintaining the original aspect ratio
- Create an image object by drawing text on a graphics context with customized fonts, colors, and alignment
In BBj 17.0 and higher, the BBXImage
Utility provides a method to
- Get a base64-encoded ASCII string version of an image
In BBj 18.0 and higher, the BBXImage
Utility provides methods to
- Crop an image to a specified rectangular region
- Return a subimage defined by a specified rectangular region
- Draw bordered or filled rectangles and ovals in a specified color
- Add borders to the image
- Resize the image's canvas
- Add a color overlay to the image
In BBj 19.0 and higher, the BBXImage
Utility provides methods to
- Save the image in the GIF, BMP, and TIFF image formats
In BBj 21.12 and higher, the BBXImage
Utility has been updated with the following features:
- The manipulation methods have been updated to return the
BBXImage
. This makes it possible to chain multiple method calls, as in:
xImage!.scale(100, 100).rotate(90).saveAsPNG("myScaledAndRotatedeImage.png")
-
The new
drawText()
method allows you to draw single or multiline text on the BBXImage
providing values for foreground/background color, font, alignment, and offsets.
How to use the BBXImage Utility
Here's a quick rundown of what you need to do to use it in your program:
- Ensure the
<bbjhome>/utils/
directory is in your prefix. The BBXImage.bbj
source program is located there,
so if that directory is in your prefix then the utility will be accessible in your applications.
- Add a
USE
statement for the utility so that your application can reference the custom class and provide code completion for its methods.
The USE
statement should look like this:
USE ::BBXImage.bbj::BBXImage
To use the
BBXImage
class in your application, the process goes something like this:
- Create a
BBXImage
object from something like a BBjImage, a Java Image or ImageIcon, URL, etc:
declare BBXImage xImage!
xImage! = new BBXImage(mySource!)
- Manipulate the image in some way, such as resizing the image using one of the scale methods:
xImage!.scaleProportionally(maxWidth, maxHeight)
- Do something with the resultant image, like setting the contents of a BBjImageCtrl or saving it out as a compressed JPG file:
myImageCtrl!.setImage(xImage!.getBBjImage())
xImage!.saveAsJPG(fullPathToJpgFile$, compressionLevel75)
THROWn Error Codes:
313
: Invalid color specified. The specified string for a hex color description was invalid. It should in a format like #fafbfc
or #f0c
.
400
: Invalid image source provided or missing file.