Draw 'Component' to Bitmap


#1

Hello,

is it possible to draw manually the content (graphics) of a component to a bitmap? I have a display in my plugin that have to update sometimes automatically and i set a flag to call the repaint method when it is necessary. Whe the flag is true, the method draw some sexy lines, but when it is false, then the lines are not drawn. I donßt want to recall the repaint method at every frame so it would be nice if it is possible to cache the result into a bitmap and draw the bitmap if there are no changes.

how can i do this?

greetz from germany
t.


#2

Have a read about setBufferedToImage


#3

ok thanks. I tried it but have problems with it. I wrote this code, it´s very simple, but gives error at runtime…

void DelayDisplay::paint(Graphics& g)
{
	if (haveToRepaint() == false)
		return;
	drawGrid(g);
	drawDry(g);
	drawDelay(g);
}

bool DelayDisplay::haveToRepaint()
{
	if (_timeL != _timeLOld || _timeR != _timeROld)
	{
		_timeLOld = _timeL;
		_timeROld = _timeR;
		if (_buffering == true)
		{
			setBufferedToImage(false);
			_buffering = false;
		}
		return true;
	}
	if (_buffering == false)
	{
		setBufferedToImage(true);
		_buffering = true;
	}
	
	return false;
}

#4

void DelayDisplay::paint(Graphics& g) { if (haveToRepaint() == false)

If paint() gets called, there will be a redraw if you want or not, so this makes no sense.
If you want no redraw, than you have to care that nobody calls repaint() and that not background/foreground redraw causes dirty regions in the component, maybe though making the component opaque (setQpaque)


#5

it works, thx a lot.