我的通用应用程序(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);
}
我有一个图像,并且在用户可以拖动以找到他/她想要的颜色的UserControl(非常简单的XAML)之上。只有拖动才能在ManipulationDelta上运行得很好,但是当我每次尝试使用GetPixel()时,ManipulationDelta事件都会触发翻译变得非常迟缓。如果我注释掉颜色的设置(picturePicker.SetColor),它仍然很慢,所以这不是问题。
奇怪的是,非常类似的代码在Silverlight的旧版本(在同一部手机上)中流畅地工作。
有关如何改善这一点的想法吗?