Solved

GetPixel at Mouse Position

Posted on 2013-11-27
4
894 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What are MicroServices? 4 65
EF5 How do I stop pre-compiled views? 8 47
async questions 5 46
Script to transfer files from web server to sharePoint server 3 30
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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