Coordinates (x,y) for this interface are based on an origin (0,0) at the top, left. (This is common for 2D drawing APIs, but is different than OpenGL's default coordinate system).
Bitmap pixel values and color values are always represented as 32-bit integer RGBA color values. That is, red is in the most significant byte and alpha is in the least significant byte.
Implemented by
Supported Methods
- Clear(rgba as Integer) as Void
- GetWidth() as Integer
- GetHeight() as Integer
- GetByteArray(x as Integer, y as Integer, width as Integer, height as Integer) as Object
- GetPng(x as Integer, y as Integer, width as Integer, height as Integer) as Object
- GetAlphaEnable() as Boolean
- SetAlphaEnable(enable as Boolean) as Void
- DrawRect(x as Integer, y as Integer, width as Integer, height as Integer, rgba as Integer) as Void
- DrawPoint(x as Integer, y as Integer, size as Float, rgba as Integer) as Void
- DrawLine(xStart as Integer, yStart as Integer, xEnd as Integer, yEnd as Integer, rgba as Integer) as Void
- DrawObject(x as Integer, y as Integer, src as Object) as Boolean
- DrawScaledObject(x as Integer, y as Integer, scaleX as Float, scaleY as Float, src as Object) as Boolean
- DrawScaledObject(x as Integer, y as Integer, scaleX as Float, scaleY as Float, src as Object, rgba as Integer) as Boolean
- DrawRotatedObject(x as Integer, y as Integer, theta as Float, src as Object) as Boolean
- DrawText(text as String, x as Integer, y as Integer, rgba as Integer, font as Object) as Boolean
- Finish() as Void
Description of Methods
Clear(rgba as Integer) as Void
Clear the bitmap, and fill with the specified RGBA color.
Note that the alpha channel will be filled into the bitmap, even when not used. Once AlphaEnable is set to true, the alpha channel will be taken into account when using this bitmap as a source. See SetAlphaEnable() for more information on alpha blending.
Note that Clear() is not the same as a DrawRect() for the entire bitmap. Clear() fills the bitmap with the specified RGBA; it does not perform any alpha blending operations.
GetWidth() as Integer
Returns the width of the bitmap in pixels.
GetHeight() as Integer
Returns the height of the bitmap in pixels.
GetByteArray(x as Integer, y as Integer, width as Integer, height as Integer) as Object
Returns an roByteArray representing the RGBA pixel values for the rectangle described by the parameters.
GetPng(x as Integer, y as Integer, width as Integer, height as Integer) as Object
If successful, returns an roByteArray object containing PNG image data for the specified area of the bitmap.
If the coordinates are out of bounds, or the PNG conversion fails for any reason, then invalid is returned.
The PNG is in 32-bit RGBA format.
This function is available in firmware 7.0 or later.
Function SaveTestPng() w = 200 : h = 100 bm = CreateObject("roBitmap", {width: w, height: h, AlphaEnable: true}) bm.DrawRect(10, 10, w-20, h-20, &hFF0000FF) bm.Finish() ba = bm.GetPng(0, 0, w, h) ba.WriteFile("tmp:/test.png") End Function
GetAlphaEnable() as Boolean
Returns true if alpha blending is enabled.
SetAlphaEnable(enable as Boolean) as Void
If enable is true, do alpha blending when this bitmap is the destination. The setting of the source bitmap's alpha enable is ignored.
When turned on, each pixel in the destination bitmap is set by combining the destination and source pixels according to the alpha value in the source bitmap (or rectangle). The destination alpha is not used. (In OpenGL this is referred to as GL_ONE_MINUS_SRC_ALPHA).
By default, alpha blending is off.
Even when alpha blending is off, the alpha value is still present in the bitmap, and must be passed when a function parameter is a color (which are always RGBA).
Function Main() s=CreateObject("roScreen") ' Clear to White with alpha fully opaque ' but alpha not actually ever used since it is the bottom most plane ' alpha is only looked at on "source" planes, not "destination". s.Clear(&hFFFFFFFF) ' AlphaEnable must be enabled in the destination surface to have effect. s.SetAlphaEnable(true) bm=CreateObject("roBitmap", {width:100, height: 100, alphaenable: false} ) bm.Clear(&h0000FFFF) 'blue, fully opaque alpha ' draw a blue rect in the upper left corner s.DrawObject(0,0, bm) s.Finish() Sleep(2000) s.Clear(&hFFFFFFFF) bm.Clear(&h0000FF00) 'blue, fully transparent alpha ' draw a blue rect in the upper left corner ' but, since it is transparent, nothing will appear on the screen. s.DrawObject(0, 0, bm) s.Finish() Sleep(2000) End Function
DrawRect(x as Integer, y as Integer, width as Integer, height as Integer, rgba as Integer) as Void
Fill the specified rectangle from left (x), top (y) to right (x + width), bottom (y + height) with the RGBA color.
DrawPoint(x as Integer, y as Integer, size as Float, rgba as Integer) as Void
Draws a point at (x,y) with the given size and RGBA color.
This function is available in firmware 6.2 or later.
DrawLine(xStart as Integer, yStart as Integer, xEnd as Integer, yEnd as Integer, rgba as Integer) as Void
Draw a line from (xStart, yStart) to (xEnd, yEnd) with RGBA color.
Returns true if successful.
DrawObject(x as Integer, y as Integer, src as Object) as Boolean
Draw the source object, where src is an roBitmap or an roRegion object, at position x,y.
Returns true if successful.
DrawScaledObject(x as Integer, y as Integer, scaleX as Float, scaleY as Float, src as Object) as Boolean
Draw the source object, where src is an roBitmap or an roRegion object, at position x,y, scaled in the x direction by scaleX and in the y direction by scaleY.
scaleX and scaleY should each be greater than zero and less than one to reduce the object size, or greater than one to increase the object size.
Returns true if successful.
DrawScaledObject(x as Integer, y as Integer, scaleX as Float, scaleY as Float, src as Object, rgba as Integer) as Boolean
Draw the source object, where src is an roBitmap or an roRegion object, at position x,y, scaled in the x direction by scaleX and in the y direction by scaleY, with RGBA color.
scaleX and scaleY should each be greater than zero and less than one to reduce the object size, or greater than one to increase the object size.
Returns true if successful.
DrawRotatedObject(x as Integer, y as Integer, theta as Float, src as Object) as Boolean
Draw the source object, where src is an roBitmap or an roRegion object, at position x,y rotated by angle theta degrees.
Theta is currently limited to 0, 90, 180, and 270 degrees.
Returns true if successful.
DrawText(text as String, x as Integer, y as Integer, rgba as Integer, font as Object) as Boolean
Draws the text at position (x,y) using the specified RGBA color and roFont font object.
Text is drawn anti-aliased.
The background image/color behind the text will show through the spaces and holes in the text. To have the text erase the background, make a call to DrawRect() before calling DrawText().
The size, bold, and italic attributes are specified when creating the roFont.
Returns true if successful.
Finish() as Void
Realize the bitmap by finishing all queued draw calls. Until Finish() is called, prior graphics operations may not be user visible.
For example, they may be in the graphics display pipeline, or in a server queue.
Note that Finish() is synchronous, i.e. it does not return until all graphic operations are complete.
Note: when working with an roScreen object, ifScreen.SwapBuffers() should be used instead of Finish().