CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2010
    Posts
    7

    [RESOLVED] Help reading pixels

    Hi
    Thank you for taking the time to read my post

    I am very new to vb net so please be gentle with me

    I have recently downloaded 2008 express and found it be be very easy to use for the most part now for my problem

    I own a low end telescope 5 inch Newtonian and ever time I try to focus it it takes about 3 seconds to stop shaking so I decided to build a focuser with a stepping motor easy then I decided to interface this into my laptop with the aid of vb.net 208 again not to hard so I built an interface that either manually send a pulse to drive the motor 1 step (1.8 degrees) or half step (0.9 degrees)
    and an auto mode that with the use of a slide bar I select an amount of steps the motor will drive, the direction of the drive and weather it is full or half steps. Then I added the input from my modified webcam so I can view the image on the same form all not to hard.

    Now what I want to do is
    1. to view the image
    2. select a part of the image
    3. check the difference between the 1 pixel and the 4 pixels around it to determine if there is a great variance between then then move onto the next pixel
    4. store the greatest variance in a variable
    5. move the stepper 1 more step and repeat steps 1 through 4 until the best focus is obtained

    any suggestions would be great or ideas on an easier approch

    thanks in advance
    christos
    Last edited by christos57; March 10th, 2010 at 04:17 AM.

  2. #2
    Join Date
    Mar 2010
    Posts
    26

    Post Re: Help reading pixels

    Heres how I do It:
    Code:
    Imports System.Drawing
    Imports System.Drawing.Drawing2D
    Imports System.Windows.Forms
    Public Class Form1
        Dim g As System.Drawing.Graphics
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Me.Show()
            Me.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None
            Me.BackgroundImage = System.Drawing.Image.FromFile("C:\Test.bmp")
        End Sub
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim n As Integer, k As Integer
            Dim brush3 As Brush
            Dim mypix2 As Color
            Dim pic As Bitmap ' 
            Dim g As System.Drawing.Graphics
            g = Me.CreateGraphics
            pic = Me.BackgroundImage ' You Can of course say pic=System.Drawing.Image.FromFile("C:\Test.bmp")
            For n = 0 To 400
                For k = 0 To 400
                    mypix2 = pic.GetPixel(n, k) ' The piece of the code relevant to your Needs
                    brush3 = New SolidBrush(Color.FromArgb(mypix2.A, mypix2.R, mypix2.G, mypix2.B))
                    g.FillRectangle(brush3, 0 + n, 400 + k, 1, 1)
                    brush3.Dispose()
                Next k
            Next n
        End Sub
    End Class
    Put this into a project and place a test picture in "C:\Test.bmp"

    Put a Button on the form - the form as big as you can.

    This paints a copy of the image for pixel 0,0 to 400,400
    onto the form 400 pixels down on the y axis.

    This is of course a dumb way to duplicate
    a portion of the bitmap but I like to use little snippets like this to figure out how thing work.

    The two lines of Code you need are to create the bitmap bject and to use it's getpixel method.

    Hope this Helps
    Last edited by Cimperiali; March 8th, 2010 at 03:10 PM. Reason: Added Code tags

  3. #3
    Join Date
    Mar 2010
    Posts
    7

    Re: Help reading pixels

    WOW Thanks for the ultra quick response Bob
    I copied your snippet but had a little error as the bitmap I was using was smaller then the defined area all fixed and it works great just have to nut out the rest


    thanks again
    Christos

  4. #4
    Join Date
    Mar 2010
    Posts
    26

    Re: Help reading pixels

    No problem - Need any further help just ask

  5. #5
    Join Date
    Mar 2010
    Posts
    7

    Re: Help reading pixels

    Just a little feed back
    it is all complete and works even better than I could of imagined
    the telescope has never been in focus this well

    thank you again Bob for your help
    P.S. I am quite proud of my self with a total 4 days programming experience so far

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Help reading pixels

    That was great TurboBob!

    christos57, I'm glad you have got your thread resolved, please just remember to mark your thread as resolved, as outlined here :

    http://www.codeguru.com/forum/showthread.php?t=403073

  7. #7
    Join Date
    Mar 2010
    Posts
    26

    Re: Help reading pixels

    Quote Originally Posted by christos57 View Post
    Just a little feed back
    it is all complete and works even better than I could of imagined
    the telescope has never been in focus this well

    thank you again Bob for your help
    P.S. I am quite proud of my self with a total 4 days programming experience so far
    After just 4 Days I was still trying to put a command button on a form !!

    Best of Luck

  8. #8
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Help reading pixels

    christos, you're doing much better than what I did after 4 days, so you are actually quite good

    After 4 days I had to replace my keyboard twice, and my mouse one time - oh, and I figured out that the book I was using's cover was made of rubber - because it was still in one piece after I have thrown it a million times! LOL!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured