Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

c# problem

Options
  • 14-06-2012 10:59am
    #1
    Registered Users Posts: 3,615 ✭✭✭


    Hi, wondering if anyone can help me with this. When the mouse is clicked somewhere in an image, the x and y pixel coordinates are displayed in two textboxes. What I want to do is display a corresponding value from the pixeldata array in a third textbox.


    So I need something like textbox3.text = Convert.ToString(pixeldata[clickedPoint.X + clickedPoint.Y*320]);

    But I cant access the clickedpoint values outside of the mousebuttonevent. (or vice versa with the pixeldata array)

    My programming knowledge is fairly basic and I've been learning as I go along with this project.
    void DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
            {
                DepthImageFrame imageFrame = e.OpenDepthImageFrame();
                if (imageFrame != null)
                {
                    short[] pixelData = new short[imageFrame.PixelDataLength];
                    imageFrame.CopyPixelDataTo(pixelData);
                    int temp = 0;
                    int i = 0;
                    for (int y = 0; y < 240; y += s)
                        for (int x = 0; x < 320; x += s)
                        {
                            temp = ((ushort)pixelData[x + y * 320]) >> 3;
                            ((TranslateTransform3D)points[i].Transform).OffsetZ = temp;
                            i++;
                                              
    
                        }                
                }        
                           
            }
    
     private void canvas1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
    
                var clickedPoint = e.GetPosition((Canvas)sender);
                String xcoord = Convert.ToString(clickedPoint.X);
                String ycoord = Convert.ToString(clickedPoint.Y);
                textBox1.Text = (xcoord);
                textBox2.Text = (ycoord);
                            
            }
    


Comments

  • Registered Users Posts: 2,781 ✭✭✭amen


    You can add the code for the third box in the function existingcanvas1_PreviewMouseLeftButtonDown

    [PHP]
    private void canvas1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {

    var clickedPoint = e.GetPosition((Canvas)sender);
    String xcoord = Convert.ToString(clickedPoint.X);
    String ycoord = Convert.ToString(clickedPoint.Y);
    textBox1.Text = (xcoord);
    textBox2.Text = (ycoord);
    textBox3.Text = Convert.ToString(pixeldata[clickedPoint.X + clickedPoint.Y*320]);

    }

    [/PHP]


  • Registered Users Posts: 3,615 ✭✭✭Mr.Plough


    But I can't access the pixeldata array outside of the depthframeready event


  • Closed Accounts Posts: 5,857 ✭✭✭professore


    Not a C# expert but

    short[] pixelData needs to be declared as a member variable of the form class. Then you can set it inside the event and still have it available outside.


Advertisement