Creating image from control


E

elziko

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?
 
Ad

Advertisements

E

elziko

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?
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top