Solved

Using a picturebox and Copyfromscreen

Posted on 2013-01-20
5
1,600 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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