Solved

GetPixel at Mouse Position

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Coding for the first time 9 62
ModalPopup  question 22 38
how to remove error in database 6 28
Need help with a query 14 36
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

735 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