473,395 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Creating image from control

I'm using BltBit to create an image from a control:

Private Function Getimage(ByVal ctlSource As Control) As Image
Dim gSource As Graphics = ctlSource.CreateGraphics
Dim imgSource As Image = New Bitmap(Me.ClientRectangle.Width,
Me.ClientRectangle.Height, gSource)
Dim gDest As Graphics = Graphics.FromImage(imgSource)
Dim dcSource As IntPtr = gSource.GetHdc
Dim dcDest As IntPtr = gDest.GetHdc
BitBlt(dcDest, 0, 0, ctlSource.ClientRectangle.Width,
ctlSource.ClientRectangle.Height, dcSource, 0, 0, 13369376)
gSource.ReleaseHdc(dcSource)
gDest.ReleaseHdc(dcDest)
Return imgSource
End Function

However, when I'm running my desktop in 16Bit colour mode the image created
does not match the colours of the control. The grey control backgorund gets
copied as a slightly pinky grey. Switching to 32Bit colour mode solves this
problem.

Is there any way I can get round this colour problem and is their any
quicker way to create an image from a control?

--

Cheers,

elziko

Nov 20 '05 #1
4 1061
Hi,

http://www.vb-helper.com/howto_net_g...dow_image.html

Ken
--------------
"elziko" <el****@NOTSPAMMINGyahoo.co.uk> wrote in message
news:ug**************@TK2MSFTNGP11.phx.gbl...
I'm using BltBit to create an image from a control:

Private Function Getimage(ByVal ctlSource As Control) As Image
Dim gSource As Graphics = ctlSource.CreateGraphics
Dim imgSource As Image = New Bitmap(Me.ClientRectangle.Width,
Me.ClientRectangle.Height, gSource)
Dim gDest As Graphics = Graphics.FromImage(imgSource)
Dim dcSource As IntPtr = gSource.GetHdc
Dim dcDest As IntPtr = gDest.GetHdc
BitBlt(dcDest, 0, 0, ctlSource.ClientRectangle.Width,
ctlSource.ClientRectangle.Height, dcSource, 0, 0, 13369376)
gSource.ReleaseHdc(dcSource)
gDest.ReleaseHdc(dcDest)
Return imgSource
End Function

However, when I'm running my desktop in 16Bit colour mode the image
created
does not match the colours of the control. The grey control backgorund
gets
copied as a slightly pinky grey. Switching to 32Bit colour mode solves
this
problem.

Is there any way I can get round this colour problem and is their any
quicker way to create an image from a control?

--

Cheers,

elziko

Nov 20 '05 #2
* "elziko" <el****@NOTSPAMMINGyahoo.co.uk> scripsit:
I'm using BltBit to create an image from a control:


Try this:

<URL:http://www.google.com/groups?selm=sQVN4qGXDHA.2000%40cpmsftngxa06.phx.gb l>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
> Try this:

Thanks, the function in the link you suggested does solve the colour problem
although it is around sixt times slower in my tests!

I think it might me better to look for the source of the colour problem in
my code rather than replacing it... any ideas?

--

Cheers,

elziko
Nov 20 '05 #4
> http://www.vb-helper.com/howto_net_g...dow_image.html

Thanks but I may have missed something (and apologies if I have); isn't this
pretty much the same as the code I have just posted?

--

Cheers,

elziko
Nov 20 '05 #5

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

Similar topics

4
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum...
2
by: Jim | last post by:
I'm a little new to the C# way of doing thisgs... Although I've done this sort of thing before in VS 6 / MFC... creatnig controls, ActiveX controls, etc. Creating controls in MFC is pretty...
2
by: Technical Group | last post by:
Friends, Can anybody help me out by sending a piece of C# code showing how to add an active directory user to a particular user group? If the group does not exist, then create it. Thanks in...
1
by: SamIAm | last post by:
Hi There I need to create either a user control or custom control to replace my image controls. I need to be able to dynamically assign a id and file name to the control before rendering it. ...
8
by: David W. Simmonds | last post by:
Is there an easy way to create a new browser window from C# and ASP.NET? I would just like to have a popup window without any menus or toolbars that would contain a high-res image. The low-res...
3
by: EnglishMan69 | last post by:
Hello All, I am using VB2005 Beta 2 in VS 2005 and am running into a small problem. I need to be able to add a picture box to the main form from within a thread. The program goes to a web...
7
by: Dave Keen | last post by:
Hi I am a relative newcomer and as usual I am stuck. My ASP.Net 2003 app has a page which shows data from a database plus an associated picture. I use an ASP image control sized to 300x300px. ...
0
by: hardieca | last post by:
Hi, I would like to create an adapter for the image web control to cure a pet peeve of mine. Currently, if I write out: <asp:Image ImageUrl="myPic.jpg" AlternateText="Some text"...
3
by: tshad | last post by:
oThumbnail.Save is giving me an error: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. theFileName = New FileInfo(strFileName) fileOut =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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,...

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.