# Draw 'Component' to Bitmap

**URL:** <https://forum.juce.com/t/draw-component-to-bitmap/10601>\
**Category:** General JUCE discussion\
**Created:** [June 13, 2013, 7:31am UTC](https://forum.juce.com/t/draw-component-to-bitmap/10601 "2013-06-13T07:31:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![themerx](https://avatars.discourse-cdn.com/v4/letter/t/a698b9/32.png) [@themerx](https://forum.juce.com/u/themerx)\
**Post date:** [June 13, 2013, 7:31am UTC](https://forum.juce.com/t/draw-component-to-bitmap/10601/1 "2013-06-13T07:31:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![andrewj](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/andrewj/32/13428_2.png) [@andrewj](https://forum.juce.com/u/andrewj)\
**Post date:** [June 13, 2013, 7:41am UTC](https://forum.juce.com/t/draw-component-to-bitmap/10601/2 "2013-06-13T07:41:55Z")

</div>

Have a read about [setBufferedToImage](http://www.rawmaterialsoftware.com/api/classComponent.html#af19bbc2186e3297ddd55c328e46c014b)

---

<div class="post-metadata">

**Author:** ![themerx](https://avatars.discourse-cdn.com/v4/letter/t/a698b9/32.png) [@themerx](https://forum.juce.com/u/themerx)\
**Post date:** [June 13, 2013, 8:14am UTC](https://forum.juce.com/t/draw-component-to-bitmap/10601/3 "2013-06-13T08:14:59Z")

</div>

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

```auto
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;
}
```

---

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [June 13, 2013, 10:33am UTC](https://forum.juce.com/t/draw-component-to-bitmap/10601/4 "2013-06-13T10:33:03Z")

</div>

`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)

---

<div class="post-metadata">

**Author:** ![themerx](https://avatars.discourse-cdn.com/v4/letter/t/a698b9/32.png) [@themerx](https://forum.juce.com/u/themerx)\
**Post date:** [June 13, 2013, 1:20pm UTC](https://forum.juce.com/t/draw-component-to-bitmap/10601/5 "2013-06-13T13:20:27Z")

</div>

it works, thx a lot.
