Solved

Using a picturebox and Copyfromscreen

Posted on 2013-01-20
5
1,573 Views
Last Modified: 2013-01-22
Im having a mare with this.  I am trying to align a form with a picturebox and the screen below it.  In short i want to clip the screen image that appears in the picture box.  I know the only way to do this is use the copyfromscreen and to create  an image that is then loaded in the picturebox using a timer or i suppose a form mouse move event.  
Problem i am having is aligning the image that appears within the picture box (images scroll one way to the other).  I have been playing with this for a while however what i cant do is align what i see through the picturebox and screen below (when i have managed it , its always offset. Here is my script:

gfx.CopyFromScreen(New Point(Me.Location.X + PictureBox1.Location.X - 4, Me.Location.Y + PictureBox1.Location.Y - 30), New Point(0, 0), pic.Size)
                PictureBox1.Image = pic

Open in new window



Can someone point out where im going wrong?
0
Comment
Question by:Kevmeister1
  • 3
  • 2
5 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
Can you give a better "big picture"?

What is being clipped?  Why is it being re-drawn over and over with a timer?  There might be a completely different approach that is better suited...

Some screenshots with annotations might be helpful.
0
 

Author Comment

by:Kevmeister1
Comment Utility
I have a web cam image streaming in a picturebox on one form and want to move a second form with another picture box over it (using the transparency option on the form  and aligning the back colour of the picturebox on the second form) looking through to the web cam video directly below. I am trying to use OCR (emgu) to read text/numbers from the web cam video image and convernt to text (this bit works fine).

The way this works is by clipping the screen image using the  copyfromscreen function and loading it into the picturebox on the second form.  What im having probs with is being able correctly clip the image and load in my picture box real time.  In other words the image in the picture box on the second form mirrors the part of  the screen it covers at any one time.  Im using a timer so it clips the image at an inteval of 100 to give the effect you are physically looking through the form to what is on the screen below.  I do hope i make sense......
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
Kinda following.

If your second picturebox is OVER the first, then how can you copy from the screen to get the first picturebox?  Wouldn't you just be grabbing whatever is in the second picturebox since it is on top?...
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 415 total points
Comment Utility
Nevermind, just watched your YouTube video...

Why do you need to set an image into the PictureBox at all?

You already have the Image stored in "pic", AND you can see the image because the form is transparent there.

I would get rid of the Timer altogether.  You can do everything right in the button click as well.  Use RectangleToScreen() to figure out the correct screen coords for your PictureBox.  

Something like:
Imports EMgu.CV
Imports EMgu.Util
Imports EMgu.CV.OCR
Imports EMgu.CV.Structure

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Using pic As New Bitmap(PictureBox1.Width, PictureBox1.Height)
            Dim rc As Rectangle = PictureBox1.RectangleToScreen(PictureBox1.ClientRectangle)
            Using gfx As Graphics = Graphics.FromImage(pic)
                gfx.CopyFromScreen(rc.Location, New Point(0, 0), rc.Size)
            End Using
            OCRz.Recognize(New Image(Of Bgr, Byte)(pic))
            RichTextBox1.Text = OCRz.GetText
        End Using
    End Sub

End Class

Open in new window

0
 

Author Closing Comment

by:Kevmeister1
Comment Utility
As always excellent advice and help.  This is really appreciated.  I had got it working but just wanted it to work as in the video you refer to. Thanks again
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now