1

I have some drawing code for an editor I am working on. It draws a few lines and an image buffer. After adding a zoom features and calling ScaleTransform I get an OverflowException thrown in my paint method.

Is something being scaled outside the bounds? My scaling factor is 2.0 and I have even tried 1.0 and making sure all the window sizes / buffers are large enough.

Kristopher Ives
  • 5,838
  • 7
  • 42
  • 67

1 Answers1

0

The Graphics.Transform property is not reset to the identity matrix. You have to do this yourself at the beginning of your paint method:

g.Tranfsorm = new Matrix();
g.ScaleTransform(2.0, 2.0);

Otherwise after a few exponents it will overflow (at 60 frames per second as in my application this would seem instantaneous)

Kristopher Ives
  • 5,838
  • 7
  • 42
  • 67
  • Hmm, no, the underlying problem is that you use CreateGraphics() instead of using the Paint event. So you'll have to take care of properly restoring it after you're done. Use its Save() and Restore() methods instead. It is very rarely correct to use CreateGraphics but at 60 fps its okay. – Hans Passant Apr 25 '14 at 08:28
  • You're wrong because I don't use `CreateGraphics` :) – Kristopher Ives Apr 25 '14 at 22:22