473,473 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to create a bitmap out of a control?

Hello,

I'm using a control (black box control) in my form (an ActiveX/Com control).
and I need to take the control as an image.
The controls is showing some kind of graph, and I want to create a bitmap
file out of this control, so the bitmap will show what the control is showing.

I tried this:
/////////////////////////////////////////////////////////////////
AxTheControl.AxControl ctrl = new AxTheControl.AxControl();
Graphics graphics = ctrl.CreateGraphics();
IntPtr hdc = graphics.GetHdc();
try
{
Bitmap bitmap = Bitmap.FromHbitmap(hdc);
bitmap.Save("C\ControlImage.bmp");
}
catch( Exception exp )
{
MessageBox.Show(exp.Message,);
}
graphics.ReleaseHdc(hdc);
graphics.Dispose();
/////////////////////////////////////////////////////////////////

But is throws a GDI+ general error exception.
Does anybody knows how can I do that?
--
Thanks
Sharon
Mar 19 '07 #1
5 3579
Hello,

I'm using a control (black box control) in my form (an ActiveX/Com control).
and I need to take the control as an image.
The controls is showing some kind of graph, and I want to create a bitmap
file out of this control, so the bitmap will show what the control is showing.

I tried this:
/////////////////////////////////////////////////////////////////
AxControl ctrl = new AxControl();
Graphics graphics = ctrl.CreateGraphics();
IntPtr hdc = graphics.GetHdc();
try
{
Bitmap bitmap = Bitmap.FromHbitmap(hdc);
bitmap.Save("ControlImage.bmp");
}
catch( Exception exp )
{
MessageBox.Show(exp.Message);
}
graphics.ReleaseHdc(hdc);
graphics.Dispose();
/////////////////////////////////////////////////////////////////

But is throws a GDI+ general error exception.
Does anybody knows how can I do that?
--
Thanks
Sharon
Mar 19 '07 #2
Sharon,

You will want to call the DrawToBitmap method on the control, and it
will draw the controls contents to the Bitmap that you specify.

It's not working now because you are passing a device context to the
FromHBitmap method, which is a different type of handle all together.

Hope this helps.

- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
Hello,

I'm using a control (black box control) in my form (an ActiveX/Com
control).
and I need to take the control as an image.
The controls is showing some kind of graph, and I want to create a
bitmap
file out of this control, so the bitmap will show what the control is
showing.
I tried this:
/////////////////////////////////////////////////////////////////
AxControl ctrl = new AxControl();
Graphics graphics = ctrl.CreateGraphics();
IntPtr hdc = graphics.GetHdc();
try
{
Bitmap bitmap = Bitmap.FromHbitmap(hdc);
bitmap.Save("ControlImage.bmp");
}
catch( Exception exp )
{
MessageBox.Show(exp.Message);
}
graphics.ReleaseHdc(hdc);
graphics.Dispose();
/////////////////////////////////////////////////////////////////
But is throws a GDI+ general error exception.

Does anybody knows how can I do that?

Mar 19 '07 #3
Ok, Thanks, now I see where I'm wrong in my code.

The control I'm using does not have the DrawToBitmap method, and at the MSDN
help is says: "The DrawToBitmap method is not supported for ActiveX controls.
"

Is there any other way to that?
--
Thanks
Sharon
Mar 19 '07 #4
I think you can use interop and BitBlt to do this. See this FAQ entry.

http://www.syncfusion.com/faq/window...earch/870.aspx

=================
Clay Burch
Syncfusion, Inc.

Mar 19 '07 #5
Thanks Clay,
It works perfectly.

------
Thanks
Sharon
Mar 20 '07 #6

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

Similar topics

5
by: Steve Amey | last post by:
Hi all I have an ARGB value for a Colour (Eg. -65536. The value was retrieved by using the Color.ToArgb method), is there any way that I can create a System.Drawing.Image or a...
3
by: Richard Skopal | last post by:
In .NET Windows forms I can create a metafile using this code: Graphics grph = aControl.CreateGraphics(); IntPtr ipHDC = grph.GetHdc(); Metafile mf = new Metafile(aImgFilePath, ipHDC,...
5
by: Lance | last post by:
I need to create a Drawing.Bitmap from an array of integer values. My current technique creates a bitmap that eventually becomes corrupt (i.e., the bitmap's pixels change to a different color...
1
by: rushikesh.joshi | last post by:
Hi All, I want some charting functionality in my ASP.NET application. I want to show a multiple bar on my web page. It's based on down time of different servers. like server1: down betn 4 AM...
2
by: Melisa | last post by:
Hi, How can i create bitmap of a window form with all its child controls without showing this form? 1. I am trying to create bitmap image of a window form. 2. I am creating a new instance of...
15
by: Hamed | last post by:
Have I posted the message to wrong newsgroup? Or Does the question is so much strage? Would someone please kindly direct me to a true newsgroup or resource? Best Regards Hamed
0
by: Victor Reboucas | last post by:
Hi, I'm a VB.Net developer and cannot find a way to create a bipmap from a pointer... My application does video rendering using Windows media encoder (that's out of the content of this message)....
2
by: Tina | last post by:
I have a System.Drawing.Bitmap myImage; I also have a webcontrols.Image on my web page. I want to put the bitmap into the image but the image can only get it's bitmap from ImageURL which can be a...
11
by: Mark B | last post by:
I want to display a pre-designed graphical 'performance badge' on certain webpages (round, about 2cm diameter) next to a salesperson's details. I have a function,...
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
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...
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
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...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.