Solved

Using a picturebox and Copyfromscreen

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

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 86

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 86

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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