code_junkie

I need my scaled image to be aliased in C#

Nov 11th, 2011
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. // A custom control holds the image
  2. this.m_ZoomPanPicBox.Image = new Bitmap(szImagePath);
  3.  
  4. class ZoomPanPicBox : ScrollableControl
  5. {
  6. Image m_image;
  7. float m_zoom = 1.0f;
  8. InterpolationMode m_interpolationMode;
  9. ...
  10. ////////////////////////////////////////////////////////
  11. public ZoomPanPicBox()
  12. {
  13. //Double buffer the control
  14. this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
  15.  
  16. this.AutoScroll=true;
  17. }
  18. ////////////////////////////////////////////////////////
  19. protected override void OnPaint(PaintEventArgs e)
  20. {
  21. //if no image, don't bother
  22. if(m_image==null)
  23. {
  24. base.OnPaintBackground(e);
  25. return;
  26. }
  27.  
  28. //Set up a zoom matrix
  29. Matrix mx = new Matrix(m_zoom,0,0,m_zoom,0,0);
  30.  
  31. //now translate the matrix into position for the scrollbars
  32. mx.Translate(this.AutoScrollPosition.X / m_zoom, this.AutoScrollPosition.Y / m_zoom);
  33.  
  34. //use the transform
  35. e.Graphics.Transform = mx;
  36.  
  37. //and the desired interpolation mode
  38. e.Graphics.InterpolationMode = m_interpolationMode;
  39.  
  40. //Draw the image ignoring the images resolution settings.
  41. e.Graphics.DrawImage(m_image,new Rectangle(0,0,this.m_image.Width,this.m_image.Height),0,0,m_image.Width, m_image.Height,GraphicsUnit.Pixel);
  42.  
  43. base.OnPaint(e);
  44. }
Add Comment
Please, Sign In to add comment