I have run into a strange problem when using Graphics.DrawImage
.
When using e.Graphics.DrawImage(Image, Point)
in OnPaint
to paint a bitmap buffer on the control, it appears that parts of the image are omitted. The buffer is populated in a helper method which draws directly onto the Bitmap
using a Graphics
constructed from it. When the control paints, the cached bitmap is drawn on the control.
Nothing appears to be omitted on the bitmap itself, because when I saved the bitmap to disc and examined it, it was all there. (see images below)
This is what the bitmap buffer looks like:
(source: zachjohnson.net)
This what appears on the control:
(source: zachjohnson.net)
This is all I am doing in OnPaint
:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (this.bufferInvalid)
{
this.UpdateBuffer();
}
if (this.buffer != null)
{
e.Graphics.DrawImage(this.buffer, Point.Empty);
}
}