PC Review


Reply
Thread Tools Rate Thread

Capture Control in Bitmap?

 
 
=?Utf-8?B?d2F2ZW1pbGw=?=
Guest
Posts: n/a
 
      21st Sep 2005
Hello!

I would like copy my control in a bitmap and after in a jpeg.
I have an error of gdi!
This is my code

System.IntPtr intPtr = this.RichTextBox.Handle;
System.Drawing.Image img = Bitmap.FromHbitmap(intPtr);
img.Save(@"Mypath\test.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);

Have you got any idea?

Best regards,

Wavemill
 
Reply With Quote
 
 
 
 
Oliver Sturm
Guest
Posts: n/a
 
      21st Sep 2005
wavemill wrote:

>I would like copy my control in a bitmap and after in a jpeg.
>I have an error of gdi!
>This is my code
>
>System.IntPtr intPtr = this.RichTextBox.Handle;
>System.Drawing.Image img = Bitmap.FromHbitmap(intPtr);
>img.Save(@"Mypath\test.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);


That handle returned by the RichTextBox is not a HBitmap, unsurprisingly,
so this doesn't work. The FromHBitmap method works only on handles that
actually belong to a Windows bitmap.

There are two ways of solving your problem, depending on your .NET
version. In .NET 2, there's a new method on the Control, called
DrawToBitmap - this is obviously the easiest thing to use if you're on
..NET 2. In .NET 1, you'll have to reproduce the functionality of that
method yourself. I have recently done that for a blog article - see
http://www.sturmnet.org/blog/archive...-rubber-band2/ ,
right down at the bottom in the comments is the .NET implementation you
need and the sample source code tells you all about using it.


Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to capture non .net window as a bitmap John Dann Microsoft VB .NET 1 26th Jan 2009 01:20 PM
How do I capture a bitmap of my form? Tim Bücker Microsoft C# .NET 0 30th Nov 2004 03:50 PM
capture picture of desktop for bitmap Alex Bujak Microsoft Windows 2000 3 21st May 2004 02:04 PM
how to capture part of form in a bitmap dawn Microsoft C# .NET 1 30th Oct 2003 10:53 AM
Bitmap for control Ramona van Riet Microsoft C# .NET 1 22nd Jul 2003 10:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:55 PM.