Hi! I'm trying to optimize the efficiency of a glance I've written. Drawing all the primitives each time onUpdate() is called slows down the scrolling speed significantly. So I thought I'd render this to a BufferedBitmap once and then just redraw that as long as the data is still the same. However, the BufferedBitmap is just black, there's nothing on the screen.
Here's the code I use in the glance's onUpdate(), with the image caching parts removed so as to highlight the problem.
var bitmapOpts = { :width => dc.getWidth(), :height => dc.getHeight() /* :palette => [Graphics.COLOR_BLACK, Graphics.COLOR_WHITE, Graphics.COLOR_RED, Graphics.COLOR_BLUE]*/ }; var bitmap = Graphics has :createBufferedBitmap ? Graphics.createBufferedBitmap(bitmapOpts).get() as BufferedBitmap : new Graphics.BufferedBitmap(bitmapOpts); bitmap.getDc().clearClip(); bitmap.getDc().setColor(Graphics.COLOR_BLACK, Graphics.COLOR_BLACK); bitmap.getDc().clear(); var soc = sd.getSOC(); bitmap.getDc().setColor(Graphics.COLOR_RED, Graphics.COLOR_BLACK); bitmap.getDc().drawRectangle(0, 0, dc.getWidth(), dc.getHeight()); var histogram = sd.getGridHistogram(); var maxValue = sd.getMaxValue(histogram); for (var x = 0; x < histogram.size()*2; x++) { var height = histogram[x/2].toFloat() / maxValue.toFloat() * dc.getHeight().toFloat() - 2.0f; bitmap.getDc().drawLine(x+1, dc.getHeight()-1-height.toNumber(), x+1, dc.getHeight()-1); } bitmap.getDc().setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT); bitmap.getDc().drawText(25, 60, Graphics.FONT_SYSTEM_XTINY, soc+"%", Graphics.TEXT_JUSTIFY_CENTER); dc.drawBitmap(0, 0, bitmap);
