I want to draw a manipulated graphic into another:
// I have two graphics:
var gHead = Graphics.FromImage(h);
var gBackground = Graphics.FromImage(b);
// Transform the first one
var matrix = new Matrix();
matrix.Rotate(30);
gHead.Transform = matrix;
// Write the first in the second
gBackground.DrawImage(h, 200, 0, 170, 170);
Output is the background img with the head img – but the head img is not rotated.
What am I missing?
The
Transformproperty of a graphics object is exactly that, a property. It does not take any action but only tells the graphics object how it should draw images.So what you want to do is set the
Transformproperty on the graphics object that you are drawing onto – in this case it should be applied to yourgBackgroundobject, like so…then when you come round to calling the
DrawImagemethod on thegBackgroundobject, it will take into account theTransformproperty that you have applied.Keep in mind that this property change will persist through all subsequent
DrawImagecalls so you may need to reset it or change the value before doing any more drawing (if you even need to)To be extra clear, your final code should look like this…