Solved

Using a picturebox and Copyfromscreen

Posted on 2013-01-20
5
1,588 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
ID: 38798681
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
ID: 38798893
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
ID: 38799135
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
ID: 38799175
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
ID: 38805127
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

19 Experts available now in Live!

Get 1:1 Help Now