Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. public Form1()
  2. {
  3. InitializeComponent();
  4.  
  5. pictureBox1.Image = Bitmap.FromFile("lena.png");
  6. }
  7.  
  8. Point CurMouse;
  9.  
  10. const int SrcWin = 20; //source window size
  11. const int DstWin = 80; //destination window size
  12. const int DistMouse = 30; //distance to mouse
  13.  
  14. private void pictureBox1_Paint(object sender, PaintEventArgs e)
  15. {
  16. Graphics g = e.Graphics;
  17. g.InterpolationMode = InterpolationMode.NearestNeighbor;
  18. g.CompositingQuality = CompositingQuality.HighSpeed;
  19. g.SmoothingMode = SmoothingMode.None;
  20.  
  21. g.PixelOffsetMode = PixelOffsetMode.Half;
  22.  
  23. //zoom window (zooming image of picturebox)
  24. g.DrawImage(pictureBox1.Image, new Rectangle(CurMouse.X + DistMouse, CurMouse.Y + DistMouse, DstWin, DstWin),
  25. CurMouse.X - (SrcWin / 2), CurMouse.Y - (SrcWin / 2), SrcWin, SrcWin, GraphicsUnit.Pixel);
  26.  
  27. g.PixelOffsetMode = PixelOffsetMode.Default;
  28.  
  29. //draw text (should have inverted/good visible colors, depending on current background of zoom window)
  30. TextRenderer.DrawText(g, CurMouse.X + "," + CurMouse.Y, new Font("Arial", 12),
  31. new Point(CurMouse.X + DistMouse, CurMouse.Y + DistMouse), Color.Red);
  32. }
  33.  
  34. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  35. {
  36. CurMouse = e.Location;
  37. pictureBox1.Invalidate();
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement