private void SaveFile_Btn_Click(object sender, EventArgs e) { Bitmap bmp = new Bitmap(PaintBox.Width, PaintBox.Height); g = Graphics.FromImage(bmp); Rectangle r = PaintBox.RectangleToScreen(PaintBox.ClientRectangle); g.CopyFromScreen(r.Location, Point.Empty, PaintBox.Size); g.Dispose(); SaveFileDialog sv = new SaveFileDialog(); sv.Filter = "Png files|*.png|Jpeg files|*.jpeg|Bitmaps|*.bmp"; if (sv.ShowDialog() == DialogResult.OK) { if (sv.FileName.Contains(".jpeg")) { bmp.Save(sv.FileName, ImageFormat.Jpeg); } else if (sv.FileName.Contains(".png")) { bmp.Save(sv.FileName, ImageFormat.Png); } else if (sv.FileName.Contains(".bmp")) { bmp.Save(sv.FileName, ImageFormat.Bmp); } } }
private void PaintBox_MouseClick(object sender, MouseEventArgs e) { Point point = Point_Initialization(Img, e.X, e.Y); if (Flag == false) { StartX = point.X; //first click we get the 2 start points// StartY = point.Y; Flag = true; } else { EndX = point.X; // second click we get the end points (flag=false)// EndY = point.Y; switch (DrawStyle.Text) { case "קו": g.DrawLine(pencel, StartX, StartY, EndX, EndY); break; case "אליפסה": g.DrawEllipse(pencel, StartX, StartY, EndX - StartX, EndY - StartY); break; } PaintBox.Refresh(); Flag = false; } }
private void FlipY_Click(object sender, EventArgs e) { PaintBox.Image.RotateFlip(RotateFlipType.RotateNoneFlipY); Img = new Bitmap(PaintBox.Image); g = Graphics.FromImage(Img); PaintBox.Image = Img; PaintBox.Refresh(); RotatePanel.Visible = false; }
private void backColors_Click(object sender, EventArgs e) { if (ColorSelect.ShowDialog() == System.Windows.Forms.DialogResult.OK) { PaintBox.BackColor = ColorSelect.Color; g.Clear(ColorSelect.Color); PaintBox.Refresh(); } }
private void PaintBox_MouseMove(object sender, MouseEventArgs e) { if (IsMouseDwon == true) // if mouse is clicked/// { if (LastPoint != null) { g.DrawLine(pencel, LastPoint, Point_Initialization(Img, e.X, e.Y)); g.SmoothingMode = SmoothingMode.AntiAlias; PaintBox.Invalidate(); // refresh picturebox// LastPoint = Point_Initialization(Img, e.X, e.Y); //update last point position// } } }
private void PaintBox_MouseMove(object sender, MouseEventArgs e) { Xaxis = e.X; Yaxis = e.Y; YboxLocation.Text = Yaxis.ToString(); XboxLocation.Text = Xaxis.ToString(); secondPoint = e.Location; if (draw) { //g = PaintBox.CreateGraphics(); switch (CurrItem) { case Item.Rectangle: break; case Item.Ellipse: break; case Item.Eraser: g.FillEllipse(new SolidBrush(PaintBox.BackColor), e.X - x + x, e.Y - y + y, Convert.ToInt32(ToolSizeBox.Text), Convert.ToInt32(ToolSizeBox.Text)); break; case Item.Pen: g.DrawLine(new Pen(paintcolor, Convert.ToInt32(ToolSizeBox.Text)), firstPoint, secondPoint); firstPoint = secondPoint; break; case Item.Line: break; case Item.Triangle: break; case Item.RightTriangle: break; default: break; } PaintBox.Refresh(); } }
private void PictureView_TextChanged(object sender, EventArgs e) { switch (PictureView.Text) { case "Zoom": PaintBox.SizeMode = PictureBoxSizeMode.Zoom; break; case "Strech": PaintBox.SizeMode = PictureBoxSizeMode.StretchImage; break; case "Normal": PaintBox.SizeMode = PictureBoxSizeMode.Normal; break; } PaintBox.Refresh(); }
private void PaintBox_MouseUp(object sender, MouseEventArgs e) { draw = false; lx = e.X; ly = e.Y; switch (CurrItem) { case Item.Rectangle: g.DrawRectangle(new Pen(paintcolor), x, y, secondPoint.X - x, secondPoint.Y - y); break; case Item.Ellipse: g.DrawEllipse(new Pen(paintcolor), x, y, secondPoint.X - x, secondPoint.Y - y); break; case Item.Eraser: g.FillEllipse(new SolidBrush(PaintBox.BackColor), secondPoint.X - x + x, secondPoint.Y - y + y, Convert.ToInt32(ToolSizeBox.Text), Convert.ToInt32(ToolSizeBox.Text)); break; case Item.Pen: break; case Item.Line: g.DrawLine(new Pen(paintcolor), firstPoint, secondPoint); break; case Item.FloodFill: break; case Item.Triangle: Point[] points = { new Point(x, secondPoint.Y), new Point((secondPoint.X + x) / 2, y), new Point(secondPoint.X, secondPoint.Y) }; g.DrawPolygon(new Pen(paintcolor), points); break; case Item.RightTriangle: g.DrawPolygon(new Pen(paintcolor), PryamugTreug(firstPoint, secondPoint)); break; default: break; } PaintBox.Refresh(); }
private void Paintform_Resize(object sender, EventArgs e) { PaintBox.Width = this.Width - 2 * PaintBox.Left; PaintBox.Height = this.Height - 2 * PaintBox.Top; PaintBox.Refresh(); }
private void EditImageFileRightButtonClick(object sender, EventArgs e) { string newFilename; bool usePngFile; Bitmap uIImage; Bitmap bitmap; int size; OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Filter = "BMP and PNG files|*.bmp;*.png|BMP files|*.bmp|PNG files|*.png"; openDialog.CheckFileExists = true; openDialog.ReadOnlyChecked = false; openDialog.Title = "Open Image File"; openDialog.InitialDirectory = Path.GetDirectoryName(_filename); openDialog.FileName = Path.GetFileName(_filename); if (openDialog.ShowDialog() == DialogResult.OK) { bool saveToBmp = false; newFilename = openDialog.FileName; usePngFile = Settings.Instance.AllowPngImages && Path.GetExtension(openDialog.FileName).Equals(".png", StringComparison.OrdinalIgnoreCase); //UIImage will automatically convert to 32 - bit alpha image bitmap = null; uIImage = AlphaBitmap.TryAlphaBitmapFromFile(newFilename, (_flags & ImageFlags.HighContrast) != 0); try { bitmap = uIImage.Clone(new Rectangle(new Point(), uIImage.Size), uIImage.PixelFormat); //bitmap = Bitmap.FromHbitmap(uIImage.GetHbitmap()); // this code do not work, because it will not produce a ARGB bitmap if (!Addons.StartsText(_image.Owner.Directory, newFilename)) { newFilename = Path.Combine(_image.Owner.Directory, "Res"); Addons.ForceDirectories(newFilename); newFilename = Path.Combine(newFilename, Path.GetFileName(openDialog.FileName)); if (usePngFile) { File.Copy(openDialog.FileName, newFilename, true); } else { saveToBmp = true; } //newFilename = Path.ChangeExtension(newFilename, ".bmp"); //bitmap.Save(newFilename, ImageFormat.Bmp); //@ changed, don't override the same file //It seems to be a better solution when we copy the file when it is a .bmp with BM Header than bitmap.Save //If the file from openDialog is the same as newFilename we can delete the openDialog file first //or jump around the bitmap.Save //we have to do some checks if the choosen file has a BM Header //or is it possible for the WindowsRibbon, that we can use png files ? } if (!usePngFile && !Path.GetExtension(newFilename).Equals(".bmp", StringComparison.OrdinalIgnoreCase)) { saveToBmp = true; newFilename = Path.ChangeExtension(newFilename, ".bmp"); } if (saveToBmp) { AlphaBitmap.SetTransparentRGB(bitmap, Color.LightGray.ToArgb() & 0xffffff); bitmap.Save(newFilename, ImageFormat.Bmp); //@ changed, don't override the same file } EditImageFile.Text = _image.Owner.BuildRelativeFilename(newFilename); _image.Source = EditImageFile.Text; ClearBitmap(_bitmap); Graphics canvas = Graphics.FromImage(_bitmap); if (uIImage.PixelFormat != PixelFormat.Format32bppArgb) { uIImage.MakeTransparent(); } canvas.DrawImage(uIImage, new Point((64 - uIImage.Width) / 2, (64 - uIImage.Height) / 2)); canvas.Dispose(); PaintBox.Invalidate(); size = Math.Max(bitmap.Width, bitmap.Height); if ((_flags & ImageFlags.Large) != 0) { size = size / 2; } if (size <= 16) { ComboBoxMinDpi.SelectedIndex = 0; } else if (size <= 20) { ComboBoxMinDpi.SelectedIndex = 2; } else if (size <= 24) { ComboBoxMinDpi.SelectedIndex = 3; } else { ComboBoxMinDpi.SelectedIndex = 4; } } finally { uIImage.Dispose(); bitmap.Dispose(); } } }
protected override void init() { GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); boxLimitLow = new Vector3(); boxLimitLow = ballLimitLow - new Vector3(ballRadius, ballRadius, ballRadius); boxLimitHigh = new Vector3(); boxLimitHigh = ballLimitHigh + new Vector3(ballRadius, ballRadius, ballRadius); paintBox = new PaintBox(); ball = new Ball(ballRadius); ball.SetLimits(ballLimitLow, ballLimitHigh); ball.SetSocketControl(); ballSpeed = new Vector3( ballSpeedFactor + ballSpeedFactor * (float)random.NextDouble(), ballSpeedFactor + ballSpeedFactor * (float)random.NextDouble(), ballSpeedFactor + ballSpeedFactor * (float)random.NextDouble()); ball.SetSpeed(ballSpeed); ball.SetLightPosition(new Vector3(0f, 0f, -1f)); paintBox.SetLimits(boxLimitLow, boxLimitHigh, new Vector3(epsilon, epsilon, epsilon)); paintBox.Move(new Vector3(0f, 0f, -1f)); ball.MoveLimits(new Vector3(0f, 0f, -1f)); SetupDepthAndCull(); GL.Disable(EnableCap.CullFace); Textures.EnableTextures(); g_fzNear = 0.5f; g_fzFar = 100f; reshape(); paddles = new List<Paddle2>(); AddPaddle(new Vector3(-1f, -1f, -1f), new Vector3(1f, 1f, -1f)); paddles[0].SetMouseControl(); AddPaddle(new Vector3(-1f, -1f, -3f), new Vector3(1f, 1f, -3f)); paddles[BACK_PADDLE].SetNormal(new Vector3(0f, 0f, 1f)); paddles[BACK_PADDLE].UseBlock(new Vector3(0.3f, 0.3f, 0.05f)); AddPaddle(new Vector3(-1f, -1f, -3f), new Vector3(-1f, 1f, -1f)); paddles[LEFT_PADDLE].SetNormal(new Vector3(1f, 0f, 0f)); paddles[LEFT_PADDLE].UseBlock(new Vector3(0.05f, 0.3f, 0.3f)); AddPaddle(new Vector3(1f, -1f, -3f), new Vector3(1f, 1f, -1f)); paddles[RIGHT_PADDLE].SetNormal(new Vector3(-1f, 0f, 0f)); paddles[RIGHT_PADDLE].UseBlock(new Vector3(0.05f, 0.3f, 0.3f)); AddPaddle(new Vector3(-1f, 1f, -3f), new Vector3(1f, 1f, -1f)); paddles[TOP_PADDLE].SetNormal(new Vector3(0f, -1f, 0f)); paddles[TOP_PADDLE].UseBlock(new Vector3(0.3f, 0.05f, 0.3f)); AddPaddle(new Vector3(-1f, -1f, -3f), new Vector3(1f, -1f, -1f)); paddles[BOTTOM_PADDLE].SetNormal(new Vector3(0f, 1f, 0f)); paddles[BOTTOM_PADDLE].UseBlock(new Vector3(0.3f, 0.05f, 0.3f)); mousePostion = new TextClass("MousePosition", 0.4f, 0.04f, staticText); mousePostion.SetOffset(new Vector3(-0.75f, -0.75f, -0.5f)); updateProgram(); scores = new List<TextClass>(); AddScore(new Vector3(-0.6f, 0.0f, -1f), new Vector3(0f, 1f, 0f), 45f); AddScore(new Vector3(0.6f, 0.0f, -1f), new Vector3(0f, 1f, 0f), -45f); AddScore(new Vector3(0.0f, -0.45f, -1f), new Vector3(1.0f, -0f, 0f), 0f); AddScore(new Vector3(0.0f, 0.45f, -1f), new Vector3(1.0f, -0f, 0f), 0f); AddScore(new Vector3(0.0f, 0.25f, -1f), new Vector3(1.0f, -0f, 0f), 0f); AddScore(new Vector3(0.0f, -0.85f, -1f), new Vector3(1.0f, -0f, 0f), 0f); }
protected override void init() { GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); boxLimitLow = new Vector3(); boxLimitLow = ballLimitLow - new Vector3(ballRadius, ballRadius, ballRadius); boxLimitHigh = new Vector3(); boxLimitHigh = ballLimitHigh + new Vector3(ballRadius, ballRadius, ballRadius); paintBox = new PaintBox(); ball = new Ball(ballRadius); ball.SetLimits(ballLimitLow, ballLimitHigh); ballSpeed = new Vector3(0f, 0f, 0f); ball.SetSpeed(ballSpeed); ball.SetLightPosition(new Vector3(0f, 0f, -1f)); paintBox.SetLimits(boxLimitLow, boxLimitHigh, new Vector3(epsilon, epsilon, epsilon)); paintBox.Move(new Vector3(0f, 0f, -1f)); ball.MoveLimits(new Vector3(0f, 0f, -1f)); SetupDepthAndCull(); GL.Disable(EnableCap.CullFace); Textures.EnableTextures(); g_fzNear = 0.5f; g_fzFar = 100f; reshape(); paddles = new List<Paddle2>(); Paddle2 paddle = new Paddle2(); paddle.SetLimits(new Vector3(-1f, -1f, -0.5f), new Vector3(1f, 1f, -0.5f)); paddle.SetKeyboardControl(); paddles.Add(paddle); mousePostion = new TextClass("MousePosition", 0.4f, 0.04f, staticText); mousePostion.SetOffset(new Vector3(-0.75f, -0.75f, -0.5f)); updateProgram(); }
private void DeleteFile_Btn_Click(object sender, EventArgs e) { g.Clear(Color.White); PaintBox.Refresh(); }