473,594 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ 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.Ax Control ctrl = new AxTheControl.Ax Control();
Graphics graphics = ctrl.CreateGrap hics();
IntPtr hdc = graphics.GetHdc ();
try
{
Bitmap bitmap = Bitmap.FromHbit map(hdc);
bitmap.Save("C\ ControlImage.bm p");
}
catch( Exception exp )
{
MessageBox.Show (exp.Message,);
}
graphics.Releas eHdc(hdc);
graphics.Dispos e();
/////////////////////////////////////////////////////////////////

But is throws a GDI+ general error exception.
Does anybody knows how can I do that?
--
Thanks
Sharon
Mar 19 '07 #1
5 3586
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.CreateGrap hics();
IntPtr hdc = graphics.GetHdc ();
try
{
Bitmap bitmap = Bitmap.FromHbit map(hdc);
bitmap.Save("Co ntrolImage.bmp" );
}
catch( Exception exp )
{
MessageBox.Show (exp.Message);
}
graphics.Releas eHdc(hdc);
graphics.Dispos e();
/////////////////////////////////////////////////////////////////

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.co m
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.CreateGrap hics();
IntPtr hdc = graphics.GetHdc ();
try
{
Bitmap bitmap = Bitmap.FromHbit map(hdc);
bitmap.Save("Co ntrolImage.bmp" );
}
catch( Exception exp )
{
MessageBox.Show (exp.Message);
}
graphics.Releas eHdc(hdc);
graphics.Dispos e();
/////////////////////////////////////////////////////////////////
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
4830
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 System.Drawing.Bitmap from that value? Regards, Steve
3
417
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, EmfType.EmfOnly); grph.ReleaseHdc(ipHDC); grph.Dispose(); grph = Graphics.FromImage(mf); grph.DrawRectangle(aPen, 10, 10, 100, 120); grph.Dispose();
5
7359
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 after a while). Can somebody please tell me what I'm doing wrong? Here is a sample: Public Shared Function CreateBitmapFromArray( _ ByVal width As Integer, _ ByVal height As Integer, _ ByVal pixelFormat As Drawing.Imaging.PixelFormat, _
1
2342
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 to 5 AM and 6 PM to 7 PM server2: down betn 7 AM to 7:30 AM server3: down betn 3 AM to 5 AM and 2 Pm to 3 PM
2
8365
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 Form at runtime. 3. Then adding several controls like Button, RadioButton,CheckBox etc to it. 4. Now i want to create bitmap with all controls showing on it which are added to this form.
15
1827
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
1275
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). Using a "DataView" object I can attach a "video viewer" to about every control in a Form, using a "integer reference" to attach the viewer object to the control you want to use as a viewer. Question: is there any way to use the...
2
2796
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 fileName or a webpage that writes. But I don't want to have to write my bitmap to a file, I just want to put it into the image. Can this be done? It seams that an image control should be designed to that it could accept a bitmap (duh) but I...
11
5353
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, fGetPerformanceGrade(SalesPersonID as Long) as String to retrieve that salesperson's grade (e.g. A+, A, A-, B+, B... D). Also one other function, fGetMonthlySales(SalesPersonID as Long) as String to get their sales figure, e.g. "$87K". I want web visitors to be able to click...
0
7946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8251
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
8372
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8003
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6654
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...
0
5408
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();...
1
2385
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
1
1478
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1210
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.