private void Polygon_PointerPressed(object sender, PointerRoutedEventArgs e) { if (_textboxFocusing || _animating) { return; } _trianglePressing = true; Point currentPoint = e.GetCurrentPoint(this.ImageGrid).Position; // Rotation current position "Hue" degrees Point rotatedPoint = Math2.RotatePoint(currentPoint, triangleCenter, Hue); // Let trianglePoint1 become origin Point newPoint = new Point( Math.Abs(rotatedPoint.X - trianglePoint1.X), Math.Abs(rotatedPoint.Y - trianglePoint1.Y)); Math2.ComputeSV(newPoint, triangleSide, out Saturation, out Value); //Compute SeletcedColorEllipse position Point targetPoint = new Point( currentPoint.X - seletcedColorEllipse_r, currentPoint.Y - seletcedColorEllipse_r); EnterHSV(Hue, Saturation, Value, targetPoint, true); }
private unsafe void ChangeTriangleColorPixel(double hue) { HSVColor hsv = new HSVColor(hue, 1.0, 1.0); using (BitmapBuffer buffer = triangleSoftwareBitmap.LockBuffer(BitmapBufferAccessMode.Write)) { using (var reference = buffer.CreateReference()) { byte *dataInBytes; uint capacity; ((IMemoryBufferByteAccess)reference).GetBuffer(out dataInBytes, out capacity); // Fill-in the BGRA plane BitmapPlaneDescription bufferLayout = buffer.GetPlaneDescription(0); double imgWidth = bufferLayout.Width; double imgHeight = bufferLayout.Height; for (int row = 0; row < imgHeight; row++) { for (int col = 0; col < imgWidth; col++) { Point pt = new Point(col, bufferLayout.Height - row); Math2.ComputeSV(pt, imgWidth, out hsv.S, out hsv.V); Color color = hsv.GetRGB(); int pixelIndex = bufferLayout.Stride * row + 4 * col; if (dataInBytes[pixelIndex + 3] != 0) { dataInBytes[pixelIndex + 0] = (byte)color.B; dataInBytes[pixelIndex + 1] = (byte)color.G; dataInBytes[pixelIndex + 2] = (byte)color.R; } } } } } }
private void Polygon_PointerMoved(object sender, PointerRoutedEventArgs e) { if (_trianglePressing && !_textboxFocusing) { Point currentPoint = e.GetCurrentPoint(this.ImageGrid).Position; // Rotation current position "Hue" degrees Point rotatedPoint = Math2.RotatePoint(currentPoint, triangleCenter, Hue); // Let trianglePoint1 become origin Point newPoint = new Point( Math.Abs(rotatedPoint.X - trianglePoint1.X), Math.Abs(rotatedPoint.Y - trianglePoint1.Y) ); Math2.ComputeSV(newPoint, triangleSide, out Saturation, out Value); CurrentColor = Math2.HSVToRGB(Hue, Saturation, Value); // Compute SeletcedColorEllipse if (_pointerMovedStory) { Point targetPoint = new Point( currentPoint.X - seletcedColorEllipse_r, currentPoint.Y - seletcedColorEllipse_r ); ColorPickerStoryboardStart(_preAngle, targetPoint); } else { CompositeTransform ct = SeletcedColorEllipseCompositeTransform; ct.TranslateX = currentPoint.X - seletcedColorEllipse_r; ct.TranslateY = currentPoint.Y - seletcedColorEllipse_r; _preCirclePoint = new Point(ct.TranslateX, ct.TranslateY); } } }