public Scale ( float scaleX, float scaleY ) : void | ||
scaleX | float | |
scaleY | float | |
return | void |
Rectangle rect = new Rectangle(10, 10, 50, 50); Matrix matrix = new Matrix(); matrix.Scale(2, 2); matrix.TransformPoints(rect);
Image image = Image.FromFile("image.jpg"); Rectangle targetRect = new Rectangle(0, 0, 100, 100); Matrix matrix = new Matrix(); matrix.Scale((float)targetRect.Width / image.Width, (float)targetRect.Height / image.Height);In this example, we load an image from a file using the Image.FromFile method. We then create a new rectangle object with dimensions 100x100, which represents the target size we want for the image. We then create a new matrix object and call the Scale method on it, passing in the scaling factors for the x and y axes. The scaling factors are calculated by dividing the target rectangle dimensions by the original image dimensions. This results in the necessary scaling to fit the image within the target rectangle.