I am trying to draw a series of lines to a buffer that has a transparent background which will then be drawn over another window however I cannot get it to draw.
The aim of this is to only draw the image to memory once (if i'm not mistaken that's how it works?) but to be able to draw that over a window without re-drawing the lines avoiding the flicker effect.
Can anyone help?
I am currently creating a new Bitmap which can contain transparent background like so
Then drawing to that Bitmap
ManagedBackBuffer = new Bitmap(rectangleSize.Width, rectangleSize.Height, PixelFormat.Format32bppPArgb);
And then trying to draw it to a window using the follow
if (handle == default(IntPtr))
using (var g = Graphics.FromImage(ManagedBackBuffer))
using (var p = new Pen(Color.Red, 2))
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
int centreX = Screen.FromHandle(handle).Bounds.Width / 2;
int centreY = Screen.FromHandle(handle).Bounds.Height / 2;
g.DrawLine(p, new Point(centreX - 10, centreY), new Point(centreX - 4, centreY));
g.DrawLine(p, new Point(centreX + 10, centreY), new Point(centreX + 4, centreY));
g.DrawLine(p, new Point(centreX, centreY - 10), new Point(centreX, centreY - 4));
g.DrawLine(p, new Point(centreX, centreY + 10), new Point(centreX, centreY + 4));
ThreadingManager.RunWorkAsync just assigns the work to a new thread, starts it and returns it.
private void RenderImageToHandle(Image image, Point position, IntPtr handle)
using (var g = Graphics.FromHwnd(handle))
imageThread = ThreadingManager.RunWorkAsync(() =>
while (true && handle != default(IntPtr))
RenderImageToHandle(ManagedBackBuffer, imagePosition, handle);
As i debug I'm not getting any exceptions or anything it just steps over it as if its drawing it but I cannot see anything.
Does anyone know why this isnt drawing on the window?
EDIT: I created a temporary form and passed it the ManagedBackBuffer image and put it in a picturebox and it looks like the Image is blank, Does anyone know why the image is blank?
Any help appreciated. thanks.