Make image grey and rectangle area colour...
Make image grey and rectangle area colour...
Make image grey and rectangle area colour...
Make image grey and rectangle area colour...
Make image grey and rectangle area colour...
Make image grey and rectangle area colour... Make image grey and rectangle area colour... Make image grey and rectangle area colour... Make image grey and rectangle area colour... Make image grey and rectangle area colour... Make image grey and rectangle area colour... Make image grey and rectangle area colour... Make image grey and rectangle area colour...
Make image grey and rectangle area colour... Make image grey and rectangle area colour...
Make image grey and rectangle area colour...
Go Back  Xtreme Visual Basic Talk > > > Make image grey and rectangle area colour...


Reply
 
Thread Tools Display Modes
  #1  
Old 01-26-2011, 07:35 AM
lidds lidds is offline
Centurion
 
Join Date: May 2004
Posts: 100
Default Make screen grey apart from window area...


I am using the following code to place a rectangle around a form / form control, however what I want to do is make my screen grey and only the form / form control area be displayed in colour.

Code:
Imports System.Diagnostics
Imports System.Drawing
Imports System.Windows.Forms

Namespace CodeReflection.ScreenCapturingDemo
	''' <summary>
	''' Summary description for WindowHighlighter.
	''' </summary>
	Public Class WindowHighlighter
		''' <summary>
		''' Highlights the specified window just like Spy++
		''' </summary>
		''' <param name="hWnd"></param>
		Public Shared Sub Highlight(hWnd As IntPtr)
			Const  penWidth As Single = 3
			Dim rc As New Win32.Rect()
			Win32.GetWindowRect(hWnd, rc)

			Dim hDC As IntPtr = Win32.GetWindowDC(hWnd)
			If hDC <> IntPtr.Zero Then
				Using pen As New Pen(Color.Black, penWidth)
					Using g As Graphics = Graphics.FromHdc(hDC)
						g.DrawRectangle(pen, 0, 0, rc.right - rc.left - CInt(Math.Truncate(penWidth)), rc.bottom - rc.top - CInt(Math.Truncate(penWidth)))
					End Using
				End Using
			End If
			Win32.ReleaseDC(hWnd, hDC)
		End Sub

		''' <summary>
		''' Forces a window to refresh, to eliminate our funky highlighted border
		''' </summary>
		''' <param name="hWnd"></param>
		Public Shared Sub Refresh(hWnd As IntPtr)
				' TRUE 
			Win32.InvalidateRect(hWnd, IntPtr.Zero, 1)
			Win32.UpdateWindow(hWnd)
			Win32.RedrawWindow(hWnd, IntPtr.Zero, IntPtr.Zero, Win32.RDW_FRAME Or Win32.RDW_INVALIDATE Or Win32.RDW_UPDATENOW Or Win32.RDW_ALLCHILDREN)
		End Sub
	End Class
End Namespace
I have googled for ages trying to find something on this, but with no luck.

To illistrate this better they are using the same functionality in snagit 10, please see below link to a page that has a video link showing this (23 sec into video)

http://www.techsmith.com/snagit/features/win/

Thanks

Simon
Reply With Quote
  #2  
Old 01-26-2011, 07:43 AM
lidds lidds is offline
Centurion
 
Join Date: May 2004
Posts: 100
Default Make image grey and rectangle area colour...

I have created a screen capture functionality in my application that captures the entire desktop and then displays this in a picturebox on a form that is maximised. The user then can define a rectangle by draging there cursor which at the moment displays a red rectangle. What I would like to do is make the image black and white and then as the user defines their rectangle display the content of the rectangle in colour.

I have googled for ages trying to find something on this, but with no luck.

To illistrate this better they are using the same functionality in snagit 10, please see below link to a page that has a video link showing this (55 sec into video)

http://www.techsmith.com/snagit/features/win/

Thanks

Simon
Reply With Quote
  #3  
Old 01-26-2011, 09:59 AM
Mkjo99 Mkjo99 is offline
Regular
 
Join Date: May 2009
Posts: 53
Default

Converting an image to black and white is not terribly difficult. You take your bitmap object and loop through all the pixels:
Code:
Private Sub btn_blacknwhite_Click(ByVal sender As Object, ByVal e As EventArgs)
        Try 
            Dim img As Bitmap = New Bitmap(pictureBox1.Image)
            Dim c As Color
            Dim i As Integer = 0
            Do While (i < img.Width)
                Dim j As Integer = 0
                Do While (j < img.Height)
                    c = img.GetPixel(i, j)
                    Dim r As Integer = 0
                    r = Convert.ToInt16(c.R)
                    Dim g As Integer = 0
                    g = Convert.ToInt16(c.G)
                    Dim b As Integer = 0
                    b = Convert.ToInt16(c.B)
                    Dim ans As Integer = ((r  _
                                + (g + b))  _
                                / 3)
                    If (ans > 128) Then
                        r = 255
                        g = 255
                        b = 255
                    Else
                        r = 0
                        g = 0
                        b = 0
                    End If
                    c = Color.FromArgb(r, g, b)
                    img.SetPixel(i, j, c)
                    j = (j + 1)
                Loop
                i = (i + 1)
            Loop
            pictureBox1.Image = img
            MessageBox.Show("SUCESSFULLY DONE")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
Problem will be that a high rez display is going to have a lot of pixels and the conversion will likely be slow.

What you could do is when you grab your screenshot, immediately create a 2nd bitmap object and copy the original to it. Then convert the 2nd copy to black and white. Now you will have a color and black and white bitmap object in memory. When you draw your rectangle on the bitmap stored in the picturebox, use the x,y coordinates to copy the same region from the 2nd bitmap stored in memory and draw it inside your rectangle.
Reply With Quote
  #4  
Old 01-27-2011, 03:48 AM
lidds lidds is offline
Centurion
 
Join Date: May 2004
Posts: 100
Default

MKjo99,

Thank you for your help. This was the kind of approach I was thinking of, however the problem I have is the code to take the area of the colour screen image and display this on the black and white image. Could you give me any guidance with the code?

Thanks

Simon
Reply With Quote
  #5  
Old 01-27-2011, 09:02 AM
Mkjo99 Mkjo99 is offline
Regular
 
Join Date: May 2009
Posts: 53
Default

lidds,

GDI makes working with graphics a fairly trivial affair. Copying a select region from one bitmap to another shouldn't take more than a few lines of code.

If I see a question come up that I can readily answer, or I have some code lying around that solves someones problem, I will post it. I just don't have any code like that at hand, and although I have worked with GDI quite a bit in the past, it has been a while. I just don't have the time right now to look through my documentation and write your code for you. I bet that if you ran some well phrased google searches, you will quickly find what you need.

If you still can't get anywhere on your own then let me know and I will see what I can do later when I have some time.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Make image grey and rectangle area colour...
Make image grey and rectangle area colour...
Make image grey and rectangle area colour... Make image grey and rectangle area colour...
Make image grey and rectangle area colour...
Make image grey and rectangle area colour...
Make image grey and rectangle area colour... Make image grey and rectangle area colour... Make image grey and rectangle area colour... Make image grey and rectangle area colour... Make image grey and rectangle area colour... Make image grey and rectangle area colour... Make image grey and rectangle area colour...
Make image grey and rectangle area colour...
Make image grey and rectangle area colour...
 
Make image grey and rectangle area colour...
Make image grey and rectangle area colour...
 
-->