DrawRectangle clipping and pixbuffer check


DrawRectangle misbehaves with respect to the following issues
  • it is easily possible to get WriteableBitmap with Width, Height not matching pixel buffer. For example when loading a bitmap from stream one has first to specify its size which can differ from that stored in the stream. Performing pixel operation in such case causes AccessViolation
  • for x, y coordinates < 0 they are set to 0 which causes an unwanted edge to be drawn
  • the same is true for coordinates exceeding the other bounds, the edges are adjusted and painted which may not be the expected behavior
Attached you can find an implementation of DrawRectangleClip which behaves correct with respect to the points mentioned above. You may as well replace the erroneous implementation with this one.


file attachments