private void SetPointTransformation(object sender, RoutedEventArgs e) { System.Windows.Controls.Image MyImg = new System.Windows.Controls.Image(); IntPtr hBitmap; System.Drawing.Bitmap bitmap = CanvasTool.getBitmapFromCanvas(); int value = int.Parse(PointTransformationValue.Text.ToString()); if (Addition.IsChecked == true) { bitmap = CanvasTool.SetAddition(value, bitmap); } else if (Subtraction.IsChecked == true) { bitmap = CanvasTool.SetSubtraction(value, bitmap); } else if (Division.IsChecked == true) { bitmap = CanvasTool.SetDivision(value, bitmap); } else if (Multiplication.IsChecked == true) { bitmap = CanvasTool.SetMultiplication(value, bitmap); } hBitmap = bitmap.GetHbitmap(); MyImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); main_canvas.Children.Clear(); main_canvas.Children.Add(MyImg); }
private void main_canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { dragInProgress = false; capture = false; if (currentShape != null) { if (CanvasTool.drawType == DrawType.ellipse || CanvasTool.drawType == DrawType.rectangle) { Shape temp = null; if (CanvasTool.drawType == DrawType.ellipse) { temp = new Ellipse(); } else if (CanvasTool.drawType == DrawType.rectangle) { temp = new Rectangle(); } temp.Stroke = new SolidColorBrush(penColor); temp.Fill = Brushes.Transparent; temp.StrokeThickness = penThickness; temp.IsHitTestVisible = true; temp.Width = currentShape.Width; temp.Height = currentShape.Height; Canvas.SetLeft(temp, currentShape.Margin.Left); Canvas.SetTop(temp, currentShape.Margin.Top); CanvasTool.DrawShape(temp, true); } currentShape = null; } else if (CanvasTool.drawType == DrawType.line && currentLine != null) { Line line = new Line(); line.Stroke = new SolidColorBrush(penColor); line.StrokeThickness = penThickness; line.X1 = currentLine.X1; line.X2 = currentLine.X2; line.Y1 = currentLine.Y1; line.Y2 = currentLine.Y2; //double width = Math.Abs(line.X2 - line.X1); //double height = Math.Abs(line.Y2 - line.Y1); //line.Width = width; //line.Height = height; line.IsHitTestVisible = true; Canvas.SetLeft(line, currentLine.Margin.Left); Canvas.SetTop(line, currentLine.Margin.Right); CanvasTool.DrawShape(line, true); } currentLine = null; }
public Icon(string id, RectTransform parent, Vector3 localPos, string spritePath, Vector2 iconSize) { this.id = id; icon = CanvasTool.InstantiateImage(id, parent, spritePath, localPos, iconSize); mask = CanvasTool.InstantiateImage("mask", icon.rectTransform, Vector3.zero, iconSize); mask.color = new Color(0, 0, 0, 0.33f); mask.type = Image.Type.Filled; mask.fillMethod = Image.FillMethod.Radial360; mask.fillOrigin = 2; mask.fillClockwise = false; mask.fillAmount = 0; } // end Icon
private void btnYes_MouseDown(object sender, MouseButtonEventArgs e) { if (StackLines.Count < 1 || txtPLS.Visibility == Visibility.Visible) { if (!PicUrl.Equals("")) { MessageBox.Show("已簽名,欲重新簽名請先按x清除"); } else { MessageBox.Show("請簽名後上傳"); } return; } string text = ""; DataTable dataTable = MSCE.GetDataTable("select AllowIpRange from NowLogin"); if (dataTable.Rows.Count > 0) { text = dataTable.Rows[0]["AllowIpRange"].ToString(); } if (!text.Equals("") && !IpTool.CheckInNowWifi(text)) { string courseOrMeeting_String = Settings.Default.CourseOrMeeting_String; AutoClosingMessageBox.Show(string.Format("您不在{0}室範圍內,無法使用此功能", courseOrMeeting_String.Equals("課程") ? "教" : courseOrMeeting_String)); return; } string path = System.IO.Path.Combine(ClickOnceTool.GetFilePath(), Settings.Default.SignInFolder); path = System.IO.Path.Combine(path, MeetingID, UserID); Directory.CreateDirectory(path); string str = Guid.NewGuid().ToString(); string path2 = str + ".png"; string text2 = System.IO.Path.Combine(path, path2); Application current = Application.Current; CanvasTool.SaveCanvas(current.Windows[0], SignPad, 96, text2); MouseTool.ShowLoading(); if (UserID.Equals("guest")) { UserID_Origin = UserID; UserID = ""; } else if (UserID.Equals("dept")) { UserID_Origin = UserID; UserID = ""; } GetSigninDataUpload.AsyncPOST(MeetingID, UserID, DeptID, text2, new Action <SigninDataUpload>(_003CbtnYes_MouseDown_003Eb__1f)); }
public UISkillPanel(RectTransform parent) { transform = CanvasTool.InstantiateEmptyUI("UISkillPanel", parent, Vector3.zero).GetComponent <RectTransform>(); ISkillModle[] modleArr = SceneManager.mainCharacter.skill.GetSkillModleArray(); if (null == modleArr || modleArr.Length == 0 || modleArr.Length > localPosArr.Length) { DebugTool.LogError("UISkillPanel UISkillPanel modleArr is error!!!"); return; } // end if skillUIArr = new UISkill[modleArr.Length]; for (int i = 0; i < modleArr.Length; i++) { skillUIArr[i] = new UISkill(modleArr[i], transform, localPosArr[i], new Vector2(100, 100)); } // end for } // end UISkillPanel
private void OpenMenuItem_Click(object sender, RoutedEventArgs e) { string filename = ""; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Image files (*.ppm;*.jpeg;*.jpg)|*.ppm;*.jpeg;*.jpg"; openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); if (openFileDialog.ShowDialog() == true) { filename = openFileDialog.FileName; CanvasTool.OpenNewImageFile(filename); } currentFileLabel.Content = "Res: " + PixelMap2.BmpWidth + "x" + PixelMap2.BmpHeight + " Max Color Value: " + PixelMap2.BmpMaxVal; currentFileNameLabel.Content = System.IO.Path.GetFileName(filename); OryginalImage = null; }
public LineStrategyImpl(CanvasTool tool, InterpoalateStrategyInterface interpolateStrategy) { this.tool = tool; this.interpolateStrategy = interpolateStrategy ; canvasConfig = PropertiesSingleton.instance.canvasWorkspaceController.canvas.config; canvas = PropertiesSingleton.instance.canvasWorkspaceController.canvas; canvasCam = canvas.canvasCamera.camera; switch (tool.meshType){ case LineMeshType.SQUARE_SIDES: lineRendererMeshType = new SquareSideLineMeshTypeImpl(); break; case LineMeshType.TRIANGLE_SIDES: lineRendererMeshType = new TriangleSideLineMeshTypeImpl(); break; } }
private void SaveDimensBtn_Click(object sender, RoutedEventArgs e) { if ((CanvasTool.drawType == DrawType.rectangle || CanvasTool.drawType == DrawType.ellipse) && (HeightTextBox.Text != "" && WidthTextBox.Text != "")) { if (CanvasTool.drawType == DrawType.rectangle) { currentShape = new Rectangle(); } else if (CanvasTool.drawType == DrawType.ellipse) { currentShape = new Ellipse(); } double width = 0; double height = 0; Double.TryParse(WidthTextBox.Text.ToString(), out width); Double.TryParse(HeightTextBox.Text.ToString(), out height); Canvas.SetTop(currentShape, 8); Canvas.SetLeft(currentShape, 8); currentShape.Fill = Brushes.Transparent; currentShape.Width = width; currentShape.Height = height; currentShape.Stroke = new SolidColorBrush(penColor); currentShape.StrokeThickness = penThickness; CanvasTool.DrawShape(currentShape, false); currentShape = null; } else if (selectedShape != null && CanvasTool.drawType == DrawType.nothing) { double width = 0; double height = 0; Double.TryParse(WidthTextBox.Text.ToString(), out width); Double.TryParse(HeightTextBox.Text.ToString(), out height); selectedShape.Width = width; selectedShape.Height = height; //selectedShape.Fill = Brushes.Transparent; selectedShape.Stroke = new SolidColorBrush(penColor); selectedShape.StrokeThickness = penThickness; CanvasTool.RemoveShape(selectedShape); CanvasTool.DrawShape(selectedShape, false); selectedShape = null; } }
private void ChangeImageBrightness(object sender, RoutedEventArgs e) { if (OryginalImage != null) { System.Windows.Controls.Image MyImg = new System.Windows.Controls.Image(); IntPtr hBitmap; System.Drawing.Bitmap bitmap = CanvasTool.getBitmapFromCanvas(); //bitmap = CanvasTool.SetBrightness(BrightnessValue, bitmap); hBitmap = bitmap.GetHbitmap(); MyImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); main_canvas.Children.Clear(); main_canvas.Children.Add(MyImg); OryginalImage = null; } }
public LineStrategyImpl(CanvasTool tool, InterpoalateStrategyInterface interpolateStrategy) { this.tool = tool; this.interpolateStrategy = interpolateStrategy; canvasConfig = PropertiesSingleton.instance.canvasWorkspaceController.canvas.config; canvas = PropertiesSingleton.instance.canvasWorkspaceController.canvas; canvasCam = canvas.canvasCamera.camera; switch (tool.meshType) { case LineMeshType.SQUARE_SIDES: lineRendererMeshType = new SquareSideLineMeshTypeImpl(); break; case LineMeshType.TRIANGLE_SIDES: lineRendererMeshType = new TriangleSideLineMeshTypeImpl(); break; } }
public void StartFigure(CanvasTool tool, Color border, float borderWidth, Color background, bool hasBackground, Point start) { if (figureIsStarted) { return; } figureIsStarted = true; currentTool = tool; currentObject = new DrawingObject(); currentObject.StartingPoint = start; currentObject.BorderColor = border; currentObject.BackgroundColor = background; currentObject.BorderWidth = borderWidth; currentObject.HasBackground = hasBackground; currentObject.HasBorder = true; previousImageState = currentBitmap.Clone() as Bitmap; }
private void SetGrayscale_Click(object sender, RoutedEventArgs e) { System.Windows.Controls.Image MyImg = new System.Windows.Controls.Image(); IntPtr hBitmap; System.Drawing.Bitmap bitmap = CanvasTool.getBitmapFromCanvas(); if (((Button)e.Source).Name == "Average") { bitmap = CanvasTool.SetGrayscaleAverage(bitmap); } else { bitmap = CanvasTool.SetGrayscaleLuminosity(bitmap); } hBitmap = bitmap.GetHbitmap(); MyImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); main_canvas.Children.Clear(); main_canvas.Children.Add(MyImg); }
public UISkill(ISkillModle modle, RectTransform parent, Vector3 localPos, Vector2 iconSize) { this.modle = modle; transfrom = CanvasTool.InstantiateEmptyUI("uiskill", parent, localPos).GetComponent <RectTransform>(); icon = CanvasTool.InstantiateImage(modle.info.id, transfrom, Vector3.zero, iconSize); icon.sprite = ResourcesTool.LoadSprite(modle.info.spritepath); icon.gameObject.AddComponent <UIButton>().AddListener(CastSkill); icon.raycastTarget = true; mask = CanvasTool.InstantiateImage("mask", icon.rectTransform, Vector3.zero, iconSize); mask.sprite = icon.sprite; timeText = CanvasTool.InstantiateText("timer", transfrom, iconSize); timeText.font = Font.CreateDynamicFontFromOSFont("Arial", 32); timeText.fontSize = 32; timeText.color = Color.red; timeText.alignment = TextAnchor.MiddleCenter; mask.color = new Color(0, 0, 0, 0.5f); mask.type = Image.Type.Filled; mask.fillMethod = Image.FillMethod.Radial360; mask.fillOrigin = 2; mask.fillClockwise = false; mask.fillAmount = 0; } // end Icon
private void BrightnessValue_Changed(object sender, MouseButtonEventArgs e) { if (OryginalImage == null) { OryginalImage = canvasTool.getBitmapFromCanvas(); } int value = (int)Math.Round(BrightnessSlider.Value, 0); BrightnesValueTextBox.Content = value.ToString(); BrightnessValue = value; System.Windows.Controls.Image MyImg = new System.Windows.Controls.Image(); IntPtr hBitmap; System.Drawing.Bitmap bitmap = OryginalImage; bitmap = CanvasTool.SetBrightness(BrightnessValue, bitmap); hBitmap = bitmap.GetHbitmap(); MyImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); main_canvas.Children.Clear(); main_canvas.Children.Add(MyImg); }
public static Color32[] generateTexturePath(CanvasTool canvasTool, Color32 activeColor, List<IntVector2> points, Color32[] destinationColors, int destinationWidth, int destinationHeight) { sourceWidth = canvasTool.lineWidth; sourceHeight = canvasTool.lineHeight; sourceHalfWidth = sourceWidth / 2; sourceHalfHeight = sourceHeight / 2; previousPoint = new IntVector2(-10000,-10000); bool directPosition; for (int i = 0; i < points.Count; i++) { leftX = points[i].x - sourceHalfWidth; downY = points[i].y - sourceHalfHeight; //TODO Dictionary can be changed to delegates to optimise it here PixelCache[] cache = getDirection(points[i], previousPoint, canvasTool, out directPosition); previousPoint = points[i]; if (directPosition){ sourceI = 0; for (int ii = 0; ii < sourceHeight; ii++) { for (int jj = 0; jj < sourceWidth; jj++) { currentY = (downY + ii); if (currentY > -1 && currentY < destinationHeight){ currentX = (leftX + jj); if (currentX > -1 && currentX < destinationWidth && canvasTool.colors[sourceI].a >= destinationColors[destI].a){ destI = currentY * destinationWidth + currentX ; destinationColors[destI].r = activeColor.r; destinationColors[destI].g = activeColor.g; destinationColors[destI].b = activeColor.b; destinationColors[destI].a = canvasTool.colors[sourceI].a; } } sourceI++; } } } else { if (cache == null){ continue; } for (int c = 0; c < cache.Length; c++) { currentY = (downY + cache[c].y); if (currentY > -1 && currentY < destinationHeight){ currentX = (leftX + cache[c].x); if (currentX > -1 && currentX < destinationWidth){ destI = currentY * destinationWidth + currentX; destinationColors[destI].r = activeColor.r; destinationColors[destI].g = activeColor.g; destinationColors[destI].b = activeColor.b; destinationColors[destI].a = activeColor.a; } } } } } return destinationColors; }
private void main_canvas_MouseMove(object sender, MouseEventArgs e) { #region ChangePlace if (dragInProgress == false && selectedShape != null) { currentHitType = SetHitType(selectedShape, Mouse.GetPosition(main_canvas)); SetMouseCursor(); } else if (selectedShape != null && dragInProgress == true) { Point point = Mouse.GetPosition(main_canvas); double offset_x = point.X - LastPoint.X; double offset_y = point.Y - LastPoint.Y; double new_x = 0; double new_y = 0; double new_width = 0; double new_height = 0; double new_x2 = 0; double new_y2 = 0; // Get the current position. if (selectedShape is Rectangle || selectedShape is Ellipse) { new_x = Canvas.GetLeft(selectedShape); new_y = Canvas.GetTop(selectedShape); new_width = selectedShape.Width; new_height = selectedShape.Height; } else if (selectedShape is Line) { new_x = (selectedShape as Line).X1; new_y = (selectedShape as Line).Y1; new_x2 = (selectedShape as Line).X2; new_y2 = (selectedShape as Line).Y2; } // Update the rectangle or elipse #region Update Shape Position if (selectedShape is Rectangle || selectedShape is Ellipse) { switch (currentHitType) { case HitType.Body: new_x += offset_x; new_y += offset_y; break; case HitType.UL: new_x += offset_x; new_y += offset_y; new_width -= offset_x; new_height -= offset_y; break; case HitType.UR: new_y += offset_y; new_width += offset_x; new_height -= offset_y; break; case HitType.LR: new_width += offset_x; new_height += offset_y; break; case HitType.LL: new_x += offset_x; new_width -= offset_x; new_height += offset_y; break; case HitType.L: new_x += offset_x; new_width -= offset_x; break; case HitType.R: new_width += offset_x; break; case HitType.B: new_height += offset_y; break; case HitType.T: new_y += offset_y; new_height -= offset_y; break; } } else if (selectedShape is Line) { switch (currentHitType) { case HitType.Body: new_x += offset_x; new_y += offset_y; new_x2 += offset_x; new_y2 += offset_y; break; case HitType.L: new_x += offset_x; new_y += offset_y; break; case HitType.R: new_x2 += offset_x; new_y2 += offset_y; break; } } #endregion if ((new_width > 0) && (new_height > 0)) { if (selectedShape is Rectangle || selectedShape is Ellipse) { Canvas.SetLeft(selectedShape, new_x); Canvas.SetTop(selectedShape, new_y); selectedShape.Width = new_width; selectedShape.Height = new_height; } LastPoint = point; } if (selectedShape is Line) { (selectedShape as Line).X1 = new_x; (selectedShape as Line).Y1 = new_y; (selectedShape as Line).X2 = new_x2; (selectedShape as Line).Y2 = new_y2; LastPoint = point; } } #endregion #region Draw_NewShape mMove = e.GetPosition(this.main_canvas); addShape = false; if ((CanvasTool.drawType == DrawType.ellipse || CanvasTool.drawType == DrawType.rectangle) && capture) { if (currentShape == null) { if (CanvasTool.drawType == DrawType.ellipse) { currentShape = new Ellipse(); } else if (CanvasTool.drawType == DrawType.rectangle) { currentShape = new Rectangle(); } addShape = true; currentShape.StrokeThickness = penThickness; currentShape.Stroke = new SolidColorBrush(penColor); } if (mMove.X <= mDown.X && mMove.Y <= mDown.Y) { currentShape.Margin = new Thickness(mMove.X, mMove.Y, 0, 0); } else if (mMove.X >= mDown.X && mMove.Y <= mDown.Y) { currentShape.Margin = new Thickness(mDown.X, mMove.Y, 0, 0); } else if (mMove.X >= mDown.X && mMove.Y >= mDown.Y) { currentShape.Margin = new Thickness(mDown.X, mDown.Y, 0, 0); } else if (mMove.X <= mDown.X && mMove.Y >= mDown.Y) { currentShape.Margin = new Thickness(mMove.X, mDown.Y, 0, 0); } currentShape.Width = Math.Abs(mMove.X - mDown.X); currentShape.Height = Math.Abs(mMove.Y - mDown.Y); if (addShape) { CanvasTool.DrawCapture(currentShape); } } else if (CanvasTool.drawType == DrawType.line && capture) { if (currentLine == null) { currentLine = new Line(); addShape = true; } currentLine.X1 = mDown.X; currentLine.Y1 = mDown.Y; currentLine.X2 = mMove.X; currentLine.Y2 = mMove.Y; currentLine.StrokeThickness = penThickness; currentLine.Stroke = new SolidColorBrush(penColor); if (addShape) { CanvasTool.DrawCapture(currentLine); } } #endregion }
private void btnYes_MouseDown(object sender, MouseButtonEventArgs e) { //if (StackLines.Count < 1 || txtPLS.Visibility == Visibility.Visible) if (SignPad.Strokes.Count < 1 || txtPLS.Visibility == Visibility.Visible) { if (PicUrl.Equals("") == false) { MessageBox.Show("已簽名,欲重新簽名請先按x清除"); return; } else { MessageBox.Show("請簽名後上傳"); return; } } string AllowIpRange = ""; DataTable dt = MSCE.GetDataTable("select AllowIpRange from NowLogin"); if (dt.Rows.Count > 0) { AllowIpRange = dt.Rows[0]["AllowIpRange"].ToString(); } if (PaperLess_Emeeting.Properties.Settings.Default.HasIpRangeMode == true && AllowIpRange.Equals("") == false && IpTool.CheckInNowWifi(AllowIpRange) == false) { string CourseOrMeeting_String = PaperLess_Emeeting.Properties.Settings.Default.CourseOrMeeting_String; AutoClosingMessageBox.Show(string.Format("您不在{0}室範圍內,無法使用此功能", CourseOrMeeting_String.Equals("課程") ? "教" : CourseOrMeeting_String)); return; } // 系統暫存資料夾 //string tempPath = System.IO.Path.GetTempPath(); //Environment.GetEnvironmentVariable("TEMP"); string SignInFolder = System.IO.Path.Combine(ClickOnceTool.GetFilePath(), PaperLess_Emeeting.Properties.Settings.Default.SignInFolder); SignInFolder = System.IO.Path.Combine(SignInFolder, MeetingID, UserID); Directory.CreateDirectory(SignInFolder); string GUID = Guid.NewGuid().ToString(); string tempFileName = GUID + ".png"; string filePath = System.IO.Path.Combine(SignInFolder, tempFileName); Application app = Application.Current; //(1) Canvas CanvasTool.SaveCanvas(app.Windows[0], this.SignPad, 96, filePath); //(2) InkCanvas //double width = SignPad.ActualWidth; //double height = SignPad.ActualHeight; //RenderTargetBitmap bmpCopied = new RenderTargetBitmap((int)Math.Round(width), (int)Math.Round(height), 96, 96, PixelFormats.Default); //DrawingVisual dv = new DrawingVisual(); //using (DrawingContext dc = dv.RenderOpen()) //{ // VisualBrush vb = new VisualBrush(SignPad); // dc.DrawRectangle(vb, null, new Rect(new System.Windows.Point(), new System.Windows.Size(width, height))); //} //bmpCopied.Render(dv); //System.Drawing.Bitmap bitmap; //using (MemoryStream outStream = new MemoryStream()) //{ // // from System.Media.BitmapImage to System.Drawing.Bitmap // BitmapEncoder enc = new BmpBitmapEncoder(); // enc.Frames.Add(BitmapFrame.Create(bmpCopied)); // enc.Save(outStream); // bitmap = new System.Drawing.Bitmap(outStream); //} //EncoderParameter qualityParam =new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 85L); //// Jpeg image codec //ImageCodecInfo jpegCodec = getEncoderInfo("image/jpeg"); //if (jpegCodec == null) // return; //EncoderParameters encoderParams = new EncoderParameters(1); //encoderParams.Param[0] = qualityParam; //Bitmap btm = new Bitmap(bitmap); //bitmap.Dispose(); //btm.Save(filePath, jpegCodec, encoderParams); //btm.Dispose(); //SigninDataUpload sdu = GetSigninDataUpload.POST(MeetingID, "UserID", filePath); MouseTool.ShowLoading(); if (UserID.Equals("guest") == true) { UserID_Origin = UserID; UserID = ""; } else if (UserID.Equals("dept") == true) { UserID_Origin = UserID; UserID = ""; } GetSigninDataUpload.AsyncPOST(MeetingID, UserID, DeptID, filePath, (sdu) => { GetSigninDataUpload_DoAction(sdu); }); }
static PixelCache[] getDirection(IntVector2 currentPoint, IntVector2 previousPoint, CanvasTool canvasTool, out bool directPosition) { directPosition = false; xxx = currentPoint.x - previousPoint.x; yyy = currentPoint.y - previousPoint.y; if ((xxx * xxx + yyy * yyy) > 2) { directPosition = true; return(null); } else { return(canvasTool.fullCache[yyy + 1][xxx + 1]); } }
public static Color32[] generateTexturePath(CanvasTool canvasTool, Color32 activeColor, List <IntVector2> points, Color32[] destinationColors, int destinationWidth, int destinationHeight) { sourceWidth = canvasTool.lineWidth; sourceHeight = canvasTool.lineHeight; sourceHalfWidth = sourceWidth / 2; sourceHalfHeight = sourceHeight / 2; previousPoint = new IntVector2(-10000, -10000); bool directPosition; for (int i = 0; i < points.Count; i++) { leftX = points[i].x - sourceHalfWidth; downY = points[i].y - sourceHalfHeight; //TODO Dictionary can be changed to delegates to optimise it here PixelCache[] cache = getDirection(points[i], previousPoint, canvasTool, out directPosition); previousPoint = points[i]; if (directPosition) { sourceI = 0; for (int ii = 0; ii < sourceHeight; ii++) { for (int jj = 0; jj < sourceWidth; jj++) { currentY = (downY + ii); if (currentY > -1 && currentY < destinationHeight) { currentX = (leftX + jj); if (currentX > -1 && currentX < destinationWidth && canvasTool.colors[sourceI].a >= destinationColors[destI].a) { destI = currentY * destinationWidth + currentX; destinationColors[destI].r = activeColor.r; destinationColors[destI].g = activeColor.g; destinationColors[destI].b = activeColor.b; destinationColors[destI].a = canvasTool.colors[sourceI].a; } } sourceI++; } } } else { if (cache == null) { continue; } for (int c = 0; c < cache.Length; c++) { currentY = (downY + cache[c].y); if (currentY > -1 && currentY < destinationHeight) { currentX = (leftX + cache[c].x); if (currentX > -1 && currentX < destinationWidth) { destI = currentY * destinationWidth + currentX; destinationColors[destI].r = activeColor.r; destinationColors[destI].g = activeColor.g; destinationColors[destI].b = activeColor.b; destinationColors[destI].a = activeColor.a; } } } } } return(destinationColors); }
private void ApplayFilter(object sender, RoutedEventArgs e) { Button pickedFilter = sender as Button; System.Drawing.Bitmap bitmapCanvas = CanvasTool.getBitmapFromCanvas(); System.Drawing.Bitmap afterFilter; System.Windows.Controls.Image MyImg = new System.Windows.Controls.Image(); IntPtr hBitmap; FilterBase filter; switch (pickedFilter.Name) { case "EdgeDetection_Btn": filter = new EdgeDetectionFilter(); afterFilter = bitmapCanvas.ConvolutionFilter(filter); hBitmap = afterFilter.GetHbitmap(); MyImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); main_canvas.Children.Clear(); main_canvas.Children.Add(MyImg); break; case "GaussianBlur_Btn": filter = new Gaussian3x3BlurFilter(); afterFilter = bitmapCanvas.ConvolutionFilter(filter); hBitmap = afterFilter.GetHbitmap(); MyImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); main_canvas.Children.Clear(); main_canvas.Children.Add(MyImg); break; case "Soften_Btn": filter = new SoftenFilter(); afterFilter = bitmapCanvas.ConvolutionFilter(filter); hBitmap = afterFilter.GetHbitmap(); MyImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); main_canvas.Children.Clear(); main_canvas.Children.Add(MyImg); break; case "HighPass_Btn": filter = new HighPass3x3Filter(); afterFilter = bitmapCanvas.ConvolutionFilter(filter); hBitmap = afterFilter.GetHbitmap(); MyImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); main_canvas.Children.Clear(); main_canvas.Children.Add(MyImg); break; case "Median_Btn": afterFilter = MedianFilter.CalculateMedianFilter(bitmapCanvas, 3, 0, false); hBitmap = afterFilter.GetHbitmap(); MyImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); main_canvas.Children.Clear(); main_canvas.Children.Add(MyImg); break; default: break; } }
static PixelCache[] getDirection(IntVector2 currentPoint, IntVector2 previousPoint, CanvasTool canvasTool, out bool directPosition) { directPosition = false; xxx = currentPoint.x - previousPoint.x; yyy = currentPoint.y - previousPoint.y; if ((xxx*xxx+yyy*yyy)>2){ directPosition = true; return null; } else { return canvasTool.fullCache[yyy+1][xxx+1]; } }