473,785 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 compatibleBitma p 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.CreateGrap hics().GetHdc() ;
IntPtr hMemDC = CreateCompatibl eDC(hDC); //Call gdi32.dll
IntPtr hBitmap = CreateCompatibl eBitmap(hDC);//Call gdi32.dll
SelectObject(hM emDC,hBitmap);//Call gdi32.dll
DrawChart(hMemD C);//The chart drawing done by the COM object
Bitmap bmp = System.Drawing. Image.FromHbitm ap(hBitmap);
pictureBox1.Ima ge = bmp;

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

Thanks!

Espen
Nov 17 '05 #1
2 5321
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.FromIm age 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.goo gle.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 compatibleBitma p 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.CreateGrap hics().GetHdc() ;
IntPtr hMemDC = CreateCompatibl eDC(hDC); //Call gdi32.dll
IntPtr hBitmap = CreateCompatibl eBitmap(hDC);//Call gdi32.dll
SelectObject(hM emDC,hBitmap);//Call gdi32.dll
DrawChart(hMemD C);//The chart drawing done by the COM object
Bitmap bmp = System.Drawing. Image.FromHbitm ap(hBitmap);
pictureBox1.Ima ge = 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.n o (Espen) wrote in message news:<29******* *************** ****@posting.go ogle.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 compatibleBitma p 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.CreateGrap hics().GetHdc() ;
IntPtr hMemDC = CreateCompatibl eDC(hDC); //Call gdi32.dll
IntPtr hBitmap = CreateCompatibl eBitmap(hDC);//Call gdi32.dll
SelectObject(hM emDC,hBitmap);//Call gdi32.dll
DrawChart(hMemD C);//The chart drawing done by the COM object
Bitmap bmp = System.Drawing. Image.FromHbitm ap(hBitmap);
pictureBox1.Ima ge = 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
3900
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. now use task manager to see the GDI usage of the process. everything seems normal. now catch the ListView's scroller and start to move it downwards. you have to hold the constant speed so that the ListView is constantly repainted. look at the...
5
4140
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 NullReferenceException and InvalidOperationException : The object is currently in use elsewhere. Unfortunately this appears to be a race condition. These exceptions appear to ocurr while disposing GDI+ objects, the Graphics object seems to be the...
3
4266
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 of a subclassed DataGridTextBoxColum dos not seem like a practical way to do it. I have subclassed a DataGrid and overridden the OnPaint as such:
6
4057
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 just drawing simple one dimensional shapes(Polygons,beziers,polylines etc...) are these video drivers still useful for this?. If the video drivers are not a problem then is there any other performance problems that would be disastrous for a...
7
3224
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 is drawn by loading a jpg into a bitmap and then setting picturebox.image = mybitmap. Ive created my own class, inheriting from the picturebox and overriding the OnPaint event so I can do e.Graphics.DrawImage (this.image....). This renders...
2
22312
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 below. I am running IIS5 on WinXP Pro. Server Error in '/Chapter04' Application. ---------------------------------------------------------------------------- ---- A generic error occurred in GDI+. Description: An unhandled exception occurred...
7
4717
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 PrivateFontCollection(); The annoying part is that it hangs IIS, but does not through any error so
1
5054
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 looking at the task manager. But the GDI handles keep growing. I narrowed it down to having System.Drawing.Font in my custom controls. To test it out: I created a simple form with two buttons Add and Remove that - adds and removes a simple textbox....
0
1247
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: System.Drawing.Graphics.CheckErrorStatus(Int32 status) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, PointF...
7
10395
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 invoking just-in-time (JIT) debugging instead of this dialog box. ************** Exception Text ************** System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
0
9483
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.