GDI+ Drawing in C# application

  • Thread starter Thread starter Espen
  • Start date Start date
E

Espen

Hi

I have a C# application that should display a chart, the chart drawing
is done by a COM object. I have tried to use dllimport with gdi32.dll
and created compatibleDC and compatibleBitmap with the hdc from the
graphics object. The COM object is trying to draw on the compatibleDC
and I try to create a bitmap from the hdc when the c++ drawing is
finished. The image is not displaying anything, it is just black.

How is it possible to display a bitmap created from a hdc in a c#
application when the drawing is done from a C++ COM object?

Here is my sample code:

IntPtr hDC = this.CreateGraphics().GetHdc();
IntPtr hMemDC = CreateCompatibleDC(hDC); //Call gdi32.dll
IntPtr hBitmap = CreateCompatibleBitmap(hDC);//Call gdi32.dll
SelectObject(hMemDC,hBitmap);//Call gdi32.dll
DrawChart(hMemDC);//The chart drawing done by the COM object
Bitmap bmp = System.Drawing.Image.FromHbitmap(hBitmap);
pictureBox1.Image = bmp;

Can anybody please tell me what I'm doing wrong?

Thanks!

Espen
 
Hi,

What if you just create a System.Drawing.Bitmap class with an appropriate
pixel format, then create a Graphics instance with the static
Graphics.FromImage method and then use the GetHdc() method on the created
Graphics instance to pass the HDC to the COM object?
 
Hi

Thanks for the reply.

I tried your suggestion but the result was the same, the image is just
blue. My drawrect from the COM component is not showing.

Espen
 
Back
Top