Solved

GetPixel at Mouse Position

Posted on 2013-11-27
4
913 Views
Last Modified: 2014-11-12
I'm trying to find the color of the pixel under the mouse pointer in vb.net (Windows Phone 8)

I think the way forward is to create a WriteableBitmap of the image on the page and use .GetPixel(GetPosition(mImage).X, GetPosition(mImage).y)

Problem is that the image on the page is set to fill the page.  How can I translate the position in the stretched image to that of the unstreched image ?
0
Comment
Question by:Dodsworth
[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
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39683593
Here is an example, that uses a Border class, the MouseMove event, and e.GetPosition to get the mouse position as a Point.

Track Mouse Position in WPF UIElement
http://www.codeproject.com/Tips/243314/Track-Mouse-Position-in-WPF-UIElement

There is a CodePlex project, called WriteableBitmapEx, that provides extension methods for the WriteableBitmap class to make it easier to work with that class:

WriteableBitmapEx
http://writeablebitmapex.codeplex.com/
0
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 39689485
hi.. this code is in C# please convert into vb

private bool TrackHorizontally = false;
        this.border.MouseMove += new MouseEventHandler(border_MouseMove);
        void border_MouseMove(object sender, MouseEventArgs e)
        {
 
            var cBegin = Colors.Green;
            var cEnd = Colors.Yellow;
            GradientStop gs1, gs2;
            var brush = new LinearGradientBrush();
            var gs0 = new GradientStop(cBegin, 0);
            var gs3 = new GradientStop(cEnd, 1.0);
 
            Point p = e.GetPosition(this.border);
            var factor = TrackHorizontally ? p.Y / this.border.Height : p.X / this.border.Width;
 
            if (TrackHorizontally)
            {
                brush.StartPoint = new Point(0.5, 0);
                brush.EndPoint = new Point(0.5, 1);
 
                gs1 = new GradientStop(cBegin, factor);
                gs2 = new GradientStop(cEnd, factor);
            }
            else
            {
                brush.StartPoint = new Point(0, 0.5);
                brush.EndPoint = new Point(1, 0.5);
 
                gs1 = new GradientStop(cBegin, factor);
                gs2 = new GradientStop(cEnd, factor);
            }
 
            brush.GradientStops = new GradientStopCollection { gs0, gs1, gs2, gs3 };
 
            this.border.Background = brush;
        }
    }
0
 
LVL 1

Author Comment

by:Dodsworth
ID: 39702920
I know how to get the mouse position and pixel color.. just not how to scale the on screen image to the in memory image.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 39703029
OK, I missed a very crucial part of your question:

"How can I translate the position in the stretched image to that of the unstretched image ?"

Off the top of my head, I would say that you need to determine a conversion factor...

Example:

Image 1 = 800 x 600
Image 2 = 400 x 300

Image 2 is half the height and width of Image 1.  That means that for every pixel in Image 2, there are twice as many pixels as Image 1.  

Conversion factor from #2 to #1 equals 2
Conversion factor from #1 to #2  equals .5
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

724 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