Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using a picturebox and Copyfromscreen

Posted on 2013-01-20
5
Medium Priority
?
1,735 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1660 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

636 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