Here's the relevant class:
using System;using System.Runtime.InteropServices;public class GDI{ [DllImport("gdi32.dll",EntryPoint="MoveToEx")] public static extern IntPtr MoveToEx(IntPtr HDC,int X,int Y,IntPtr Point); [DllImport("gdi32.dll",EntryPoint="LineTo")] public static extern IntPtr LineTo(IntPtr HDC,int X,int Y); [DllImport("gdi32.dll",EntryPoint="SetROP2")] public static extern int SetROP2(IntPtr HDC,int Mode); public static int R2_NOT=6; public static int R2_COPYPEN=13;}
Here's the code in the pictureBox_paint:
private void pictureBox_Paint(object sender,PaintEventArgs e){ // top secret tile drawing code snipped IntPtr HDC=e.Graphics.GetHdc(); GDI.SetROP2(HDC,GDI.R2_NOT); GDI.MoveToEx(HDC,10,10,new IntPtr()); GDI.LineTo(HDC,100,100); GDI.SetROP2(HDC,GDI.R2_COPYPEN); e.Graphics.ReleaseHdc();}
And the result:
If you look really closely, in the top left corner of the map is a diagonal line that has been drawn with a inverse raster operation.
Happy happy happy.
I'm wondering, if I figured out how to access BitBlt in C#, if it would be any faster than Graphics.DrawImage() in C#? Thoughts?
[LATER] Interestingly, no it doesn't. I've just been comparing the .NET and C++ versions of my Map application, stress testing by scrolling a big screen being filled with 8x8 rectangles and a CreateHatchBrush() brush.
Even when the C# version imports all the Win32 API GDI calls and basically uses exactly the same functions as the C++ version, the C++ version is still substantially quicker.
Shame but never mind. The C# version is prettier and easier to develop. Swings and roundabouts, I guess. I just don't understand the reason for the difference since I thought that the .NET code was JIT compiled into native machine language when it was run and so would be basically as efficient as the C++ code.
Anyway. At least .NET shortens the development cycle :[