Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

c# problem

  • 14-06-2012 10:59AM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 3,615 ✭✭✭Mr.Plough


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


  • Closed Accounts Posts: 5,849 ✭✭✭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