473,473 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

creating a control's bitmap

Please help.

How can I in OnPaint(...) of my control create a bitmap with the image of my
control?

protected override void OnPaint(PaintEventArgs e)
{
Bitmap oBitmap = new Bitmap(Width, Height);

// copy the way the control looks into the bitmap????
}

Thanks,
VR
Nov 16 '05 #1
2 1819
Hi VR,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to create a picture of your
control and save it to disk. If there is any misunderstanding, please feel
free to let me know.

Based on my research, we can use functions in GDI32 to achieve this. Here
is an example:

Private Sub MenuItem2_Select(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MenuItem2.Select
Dim g1 As Graphics
g1 = Me.CreateGraphics()
Dim MyImage As Image
MyImage = New Bitmap(Me.Width, Me.Height, g1)
Dim a As Int32
a = Me.Height
Dim g2 As Graphics
g2 = Graphics.FromImage(MyImage)
Dim dc1 As IntPtr
dc1 = g1.GetHdc()
Dim dc2 As IntPtr
dc2 = g2.GetHdc()
BitBlt(dc2, 0, 0, Me.Width, Me.Height, dc1, -4,
Me.ClientRectangle.Height - Me.Height + 4, 13369376)
g1.ReleaseHdc(dc1)
g2.ReleaseHdc(dc2)
Dim p As Point
p.X = Me.MousePosition.X - Me.Location.X
p.Y = Me.MousePosition.Y - Me.Location.Y
Me.Cursor.Draw(g2, New Rectangle(p, Me.Cursor.Size))
MyImage.Save("c:\saved.jpg", Drawing.Imaging.ImageFormat.Jpeg)
MessageBox.Show("Finished Saving Image")
End Sub

Private Declare Auto Function BitBlt Lib "GDI32.DLL" _
(ByVal hdcDest As IntPtr, ByVal nXDest As Integer, _
ByVal nYDest As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
ByVal dwRop As Int32) As Boolean

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #2
Thanks, Kevin.

This helps a lot.
VR

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:8n**************@cpmsftngxa06.phx.gbl...
Hi VR,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to create a picture of your
control and save it to disk. If there is any misunderstanding, please feel
free to let me know.

Based on my research, we can use functions in GDI32 to achieve this. Here
is an example:

Private Sub MenuItem2_Select(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MenuItem2.Select
Dim g1 As Graphics
g1 = Me.CreateGraphics()
Dim MyImage As Image
MyImage = New Bitmap(Me.Width, Me.Height, g1)
Dim a As Int32
a = Me.Height
Dim g2 As Graphics
g2 = Graphics.FromImage(MyImage)
Dim dc1 As IntPtr
dc1 = g1.GetHdc()
Dim dc2 As IntPtr
dc2 = g2.GetHdc()
BitBlt(dc2, 0, 0, Me.Width, Me.Height, dc1, -4,
Me.ClientRectangle.Height - Me.Height + 4, 13369376)
g1.ReleaseHdc(dc1)
g2.ReleaseHdc(dc2)
Dim p As Point
p.X = Me.MousePosition.X - Me.Location.X
p.Y = Me.MousePosition.Y - Me.Location.Y
Me.Cursor.Draw(g2, New Rectangle(p, Me.Cursor.Size))
MyImage.Save("c:\saved.jpg", Drawing.Imaging.ImageFormat.Jpeg)
MessageBox.Show("Finished Saving Image")
End Sub

Private Declare Auto Function BitBlt Lib "GDI32.DLL" _
(ByVal hdcDest As IntPtr, ByVal nXDest As Integer, _
ByVal nYDest As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
ByVal dwRop As Int32) As Boolean

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #3

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

Similar topics

2
by: MiW | last post by:
Hi I'm making a kind of JavaScript-based library for creating SVG objects/elements. And I hit the wall... Every element (rect, circle etc.) can be created using *.createElement, then...
11
by: Sagaert Johan | last post by:
I have made a custom control that draws a rectangle when the mouse is down, and does nothing when the mouse is up. I set/reset a flag in MouseDown/Mouse up and use this to do the drawing in the...
1
by: James Dean | last post by:
In my program i create a 32ARGB bitmap. To actually create the bitmap seems very slow. In fairness the file size is very big. I support multiple bitmaps as well. I have to convert these bitmaps to...
5
by: Brian Cryer | last post by:
I'm developing a website and for one of the pages I need to create a number of coloured rectangles - its part of a legend and the user has control over the actual colours used which is why I want...
7
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
0
by: Ben | last post by:
Hi all, I am trying to write a little app that will generate a thumbnail image of a website. Having searched the web I have found various bits of code that appear to do the job and have written...
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
2
by: Peter Oliphant | last post by:
I want to create a new Bitmap which is a portion of an existing Bitmap. For example, if I have a Bitmap that is 100x100 in size I might want to create a new Bitmap that is equivalent to the one...
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
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,...
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...
1
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...
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,...
1
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...
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 ...

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.