I have the following code in my Universal App (Windows Phone):
void colourPicker_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
PicturePicker picturePicker = sender as PicturePicker;
GeneralTransform transform = picturePicker.TransformToVisual(ImageHolder);
Point controlPosition = transform.TransformPoint(new Point(0, 0));
int pointX = (int)controlPosition.X;
int pointY = (int)controlPosition.Y;
Color c = writeableBmp.GetPixel(pointX, pointY);
// WriteableBitmap newWB = writeableBmp.Crop(pointX - 21, pointY - 21, 42, 42);
// picturePicker.SetImageBrush(newWB);
SolidColorBrush brush = new SolidColorBrush(c);
picturePicker.SetColor(brush);
Canvas.SetLeft(picturePicker, Canvas.GetLeft(picturePicker) + e.Delta.Translation.X);
Canvas.SetTop(picturePicker, Canvas.GetTop(picturePicker) + e.Delta.Translation.Y);
}
I have a image, and on top of that a UserControl (very simple XAML) that the user can drag around to find the color he/she wants. Only dragging works great on ManipulationDelta, but when I try to GetPixel() everytime the ManipulationDelta event triggers the translate becomes very laggy. If I comment out the setting of the color (picturePicker.SetColor) it's still slow, so that's not the problem.
Weird enough, very similiar code worked fluid in the old version of this app in Silverlight (on the same phone).
Any thoughts on how to improve this?