public void MultiplyTransform_NullMatrix_ThrowsArgumentNullException() { using (var image = new Bitmap(10, 10)) using (var brush = new TextureBrush(image)) { AssertExtensions.Throws <ArgumentNullException>("matrix", () => brush.MultiplyTransform(null)); AssertExtensions.Throws <ArgumentNullException>("matrix", () => brush.MultiplyTransform(null, MatrixOrder.Prepend)); } }
public void MultiplyTransform_NotInvertibleMatrix_ThrowsArgumentException() { using (var image = new Bitmap(10, 10)) using (var brush = new TextureBrush(image)) using (var matrix = new Matrix(123, 24, 82, 16, 47, 30)) { AssertExtensions.Throws <ArgumentException>(null, () => brush.MultiplyTransform(matrix)); AssertExtensions.Throws <ArgumentException>(null, () => brush.MultiplyTransform(matrix, MatrixOrder.Prepend)); } }
public void MultiplyTransform_Disposed_ThrowsArgumentException() { using (var image = new Bitmap(10, 10)) using (var matrix = new Matrix()) { var brush = new TextureBrush(image); brush.Dispose(); AssertExtensions.Throws <ArgumentException>(null, () => brush.MultiplyTransform(matrix)); AssertExtensions.Throws <ArgumentException>(null, () => brush.MultiplyTransform(matrix, MatrixOrder.Prepend)); } }
public void MultiplyTransform_Matrix_SetsTransformToExpected(Matrix originalTransform, Matrix matrix, MatrixOrder matrixOrder) { try { using (var image = new Bitmap(10, 10)) using (var brush = new TextureBrush(image)) using (var expected = (Matrix)originalTransform.Clone()) { expected.Multiply(matrix, matrixOrder); brush.Transform = originalTransform; if (matrixOrder == MatrixOrder.Prepend) { TextureBrush clone = (TextureBrush)brush.Clone(); clone.MultiplyTransform(matrix); Assert.Equal(expected, clone.Transform); } brush.MultiplyTransform(matrix, matrixOrder); Assert.Equal(expected, brush.Transform); } } finally { originalTransform.Dispose(); matrix.Dispose(); } }
private void TextureBrush_Click(object sender, System.EventArgs e) { Graphics g = this.CreateGraphics(); g.Clear(this.BackColor); // Create a TextureBrush object TextureBrush txtrBrush = new TextureBrush( new Bitmap("smallRoses.gif")); // Create a transformation matrix. Matrix M = new Matrix(); // Rotate the texture image by 90 degrees. txtrBrush.RotateTransform(90, MatrixOrder.Prepend); // Translate M.Translate(50, 0); // Multiply the transformation matrix // of tBrush by translateMatrix. txtrBrush.MultiplyTransform(M); // Scale operation txtrBrush.ScaleTransform(2, 1, MatrixOrder.Prepend); // Fill a rectangle with texture brush g.FillRectangle(txtrBrush, 240, 0, 200, 200); // Reset transformation txtrBrush.ResetTransform(); // Fill rectangle after reseting transformation g.FillRectangle(txtrBrush, 0, 0, 200, 200); // Dispose txtrBrush.Dispose(); g.Dispose(); }
public void MultiplyTransform_NonInvertible() { TextureBrush t = new TextureBrush(image); Matrix noninvertible = new Matrix(123, 24, 82, 16, 47, 30); Assert.Throws <ArgumentException> (() => t.MultiplyTransform(noninvertible)); }
private static Brush NormalizeBrush(Brush brush, IRectangle layout) { if (brush is LinearGradientBrush) { LinearGradientBrush lgb = (LinearGradientBrush)brush.Clone(); lgb.MultiplyTransform( new Matrix(Math.Max(0.1f, (float)layout.Width), 0, 0, Math.Max(0.1f, (float)layout.Height), (float)layout.X, (float)layout.Y), MatrixOrder.Append); brush = lgb; } else if (brush is PathGradientBrush) { PathGradientBrush pgb = (PathGradientBrush)brush.Clone(); pgb.MultiplyTransform( new Matrix(Math.Max(0.1f, (float)layout.Width), 0, 0, Math.Max(0.1f, (float)layout.Height), (float)layout.X, (float)layout.Y), MatrixOrder.Append); brush = pgb; } else if (brush is TextureBrush) { TextureBrush tb = (TextureBrush)brush.Clone(); tb.MultiplyTransform( new Matrix(Math.Max(0.1f, (float)layout.Width), 0, 0, Math.Max(0.1f, (float)layout.Height), (float)layout.X, (float)layout.Y), MatrixOrder.Append); brush = tb; } return(brush); }
public void MultiplyTransform_NonInvertible() { TextureBrush t = new TextureBrush(image); Matrix noninvertible = new Matrix(123, 24, 82, 16, 47, 30); t.MultiplyTransform(noninvertible); }
public void MultiplyTransform_DisposedMatrix_Nop() { using (var image = new Bitmap(10, 10)) using (var brush = new TextureBrush(image)) using (var transform = new Matrix(1, 2, 3, 4, 5, 6)) { brush.Transform = transform; var matrix = new Matrix(); matrix.Dispose(); brush.MultiplyTransform(matrix); brush.MultiplyTransform(matrix, MatrixOrder.Append); Assert.Equal(transform, brush.Transform); } }
public void MultiplyTransform_InvalidOrder_Nop(MatrixOrder matrixOrder) { using (var image = new Bitmap(10, 10)) using (var brush = new TextureBrush(image)) using (var transform = new Matrix(1, 2, 3, 4, 5, 6)) using (var matrix = new Matrix()) { brush.Transform = transform; brush.MultiplyTransform(matrix, matrixOrder); Assert.Equal(transform, brush.Transform); } }
public virtual void FillShape(GraphicsPath path, Graphics drawingSpace) { if (pattern != null) { TextureBrush b = new TextureBrush(pattern); b.MultiplyTransform(transformationMatrix); drawingSpace.FillPath(b, path); } else { SolidBrush b = new SolidBrush(BackColor); drawingSpace.FillPath(b, path); } }
// </snippet1> // Snippet for: M:System.Drawing.TextureBrush.MultiplyTransform(System.Drawing.Drawing2D.Matrix) // <snippet2> public void MultiplyTransform_Example1(PaintEventArgs e) { // Create a TextureBrush object. TextureBrush tBrush = new TextureBrush(new Bitmap("texture.jpg")); // Create a transformation matrix. Matrix translateMatrix = new Matrix(); translateMatrix.Translate(50, 0); // Multiply the transformation matrix of tBrush by translateMatrix. tBrush.MultiplyTransform(translateMatrix, MatrixOrder.Prepend); // Fill a rectangle with tBrush. e.Graphics.FillRectangle(tBrush, 0, 110, 100, 100); }
public void MultiplyTransformOrder_Invalid() { TextureBrush t = new TextureBrush(image); t.MultiplyTransform(new Matrix(), (MatrixOrder)Int32.MinValue); }