locked
Problem with WritableBitmap and negative coordinates RRS feed

  • Question

  • I am working on a Logo interpreter and have gotten to the point where I'm ready to accept user input.  This presents a problem with a solution I had earlier with WritableBitmap and as I am writing also my ScrollViewer.

    My implentation is as follows:

    Everytime the turtle draws a line, when the line is complete I create a writeable bitmap from the line and the existing image in the background.  That new bitmap replaces the background image.  I originally had a series of Paths, but as numbers got large that became a bad solution.

    Originally I had a problem whereby any area of negative x and/or y coordinates would not get drawn.  My solution was to translate my drawing by what I new would be the eventually minimum coordinates.  So if the most minimum x coord was -100 and the most minumum y coord was -200 then the drawing would start at (100, 200).

    This works well as far as I know the drawing in advance, but if I accept user input I will not be able to use this.

    One solution that I tried was using TranslateTransform in the WriteableBitmap constructor.  This behaved funny.  If I had the proper x and y values at the time it would only create an image the size of the drawing in the postive area, so that if the bounds were (-100, -200) and (500, 400) it would create an image 500 x 400 leaving out the leftmost and bottommost parts.  This seems like a bug.

    I also realized that this will mess up the scrollviewer.  I use the width and height of the eventually drawing to set the size of my control so that the scrollviewer will work properly.  I'm not so familiar with this control so maybe there is something easy trick.

    What I do know is the size of the drawing at every step in the execution.  I could redesign the program so that every step I draw a line I then translate the line and the image so that it is always in bounds (this only has to be done for when I go below the minimum bounds).  This seems somewhat inelegant and I don't know what problems I'd be in store for.  Plus I could really see this screwing up the scroll viewer functionality.

    uggh.  Anybody have any ideas?

     

    Saturday, November 21, 2009 5:18 PM

Answers

  • I figured out this problem.  I had to set the canvas's width and height before I drew the line.  Even if I drew a line and then changed the canvas size the portion drew before the size change would not get rendered.

    Thursday, November 26, 2009 11:00 AM