Draw dots on canvas using offset?

I have an array of Point variables. When drawing using Graphics.DrawLine they create the expected image. My problem is that 0,0 is actually the center of the image (and not the top left of my canvas as expected). My X and Y coordinates at points may contain negative numbers.

When I try to draw this on my Image , I, of course, get 1/4 of the total image, since the remainder is drawn outside my canvas. How to set up this picture on my canvas?

I know the size of the image I want to draw. I know where 0,0 (width / 2, height / 2).

I suppose I can translate every Point , but that seems difficult for that.

+4
source share
3 answers

TranslateTransform () can display the coordinates for you if you set up the transformation during drawing handlers.

Graphics.TranslateTransform @MSDN

Or, match your coordinates by adding half the width and half height of the desired viewing area to each coordinate.

In addition, you may need to scale your coordinates. You can use Graphics.ScaleTransform for this.

Graphics.ScaleTransform @MSDN

If you do not want to use this, you must divide the X coordinates by the percentage that you want to stretch in width, and divide the Y coordinates by the percentage that you want to stretch in height. This gives us 1 for 100%, 1.2 for 120%, 0.8 for 80%, etc.

+3
source

Welcome to the Windows version of Cartessian Plane. Your last statement is true. You must compensate for every point. The only real help you can give yourself is to make the bias logic a separate method to clear the main drawing code.

+1
source

When creating an array, add an offset to each x value equal to half the width, and an offset to y equal to half the height. Thus, when the glasses are drawn, they are in the expected position.

0
source

All Articles