473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

GDI+ Drawing in C# application

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
Nov 17 '05 #1
2 5292
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?

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Espen" <es***@tiscali.no> wrote in message
news:29**************************@posting.google.c om...
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


Nov 17 '05 #2
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

es***@tiscali.no (Espen) wrote in message news:<29**************************@posting.google. com>...
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

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Wiktor Zychla | last post by:
today we've found a critical issue regarding the ListView from Windows.Forms. it was confirmed on several machines with Win2K and XP. here's the problem: create a ListView with about 50000 rows....
5
by: anonymous | last post by:
I'm writing a program that deals extensively with the printer. For the most part my application runs fine, but occasionally I run into some Exceptions. The most common exceptions I run into are...
3
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint...
6
by: James dean | last post by:
I have heard that the video drivers in GDI+ are a big performance issue. But is this only an issue with something like Games Programming i think...is this wrong?. What about a drawing application...
7
by: news | last post by:
This may be a stupid question, but if I don't ask I'll never know ;) Ok, here it goes.... I am writing an application that renders an image in one picturebox and a graph in another. The image...
2
by: Alphonse Giambrone | last post by:
I am currently reading 'Programming The Web with Visual Basic .NET' and have so far found it to be excellent. Downloaded all the code from Apress and working in chapter 4, I get the error shown...
7
by: Tarren | last post by:
Hi: I need to render text graphics using custome font. I am running into issues where PrivateFontCollection will hang sometimes when I instantiate it. PrivateFontCollection fc = new...
1
by: Pranil Kanderi | last post by:
I have a huge application with lots of custom controls. The app had a memory leak but fixed that by calling the dispose method where needed and now the user objects are very stable, when I am...
0
by: James Wong | last post by:
Hi everybody, I'm facing a serious trouble relating to GDI+ generic error. The error message is "A Generic error occured in GDI+" and the following information is stored in Excepton object:...
7
by: j4richard | last post by:
Help please, I am getting this "Unhandled Exception has occurred in your application" " A Generic error occurred in GDI+" See the end of this message for details on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.