Code:
/// <summary>
/// Zeichnet das Bild mit Beachtung der inneren Abstände für gestrecktes Zeichnen.
/// </summary>
/// <param name="x">Koordinate auf der X-Achse.</param>
/// <param name="y">Koordinate auf der Y-Achse.</param>
/// <param name="width">Breite des Bildes in Pixel.</param>
/// <param name="height">Höhe des Bildes in Pixel.</param>
public void DrawMarginScaled(int x, int y, int width, int height)
{
// Ausschnitte aus der Textur
int clippedX = _clipping.X + _margins.X;
int srcVertR = _clipping.X + _clipping.Width - _margins.Width;
int srcHorzB = _clipping.Y + _clipping.Height - _margins.Height;
int srcInnerW = _clipping.Width - _margins.X - _margins.Width;
int srcInnerH = _clipping.Height - _margins.Y - _margins.Height;
Rectangle srcTl = new Rectangle(_clipping.X, _clipping.Y, _margins.X, _margins.Y);
Rectangle srcTm = new Rectangle(clippedX, _clipping.Y, srcInnerW, _margins.Y);
Rectangle srcTr = new Rectangle(srcVertR, _clipping.Y, _margins.Width, _margins.Y);
Rectangle srcMl = new Rectangle(_clipping.X, _margins.Y, _margins.X, srcInnerH);
Rectangle srcMm = new Rectangle(clippedX, _margins.Y, srcInnerW, srcInnerH);
Rectangle srcMr = new Rectangle(srcVertR, _margins.Y, _margins.Width, srcInnerH);
Rectangle srcBl = new Rectangle(_clipping.X, srcHorzB, _margins.X, _margins.Height);
Rectangle srcBm = new Rectangle(clippedX, srcHorzB, srcInnerW, _margins.Height);
Rectangle srcBr = new Rectangle(srcVertR, srcHorzB, _margins.Width, _margins.Height);
// Zielbildschirmbereiche
int dstVertL = x + _margins.X;
int dstVertR = x + width - _margins.Width;
int dstHorzT = y + _margins.Y;
int dstHorzB = y + height - _margins.Height;
int dstInnerH = height - _margins.Y - _margins.Height;
int dstInnerW = width - _margins.X - _margins.Width;
Rectangle dstTl = new Rectangle(x, y, _margins.X, _margins.Y);
Rectangle dstTm = new Rectangle(dstVertL, y, dstInnerW, _margins.Y);
Rectangle dstTr = new Rectangle(dstVertR, y, _margins.Width, _margins.Y);
Rectangle dstMl = new Rectangle(x, dstHorzT, _margins.X, dstInnerH);
Rectangle dstMm = new Rectangle(dstVertL, dstHorzT, dstInnerW, dstInnerH);
Rectangle dstMr = new Rectangle(dstVertR, dstHorzT, _margins.Width, dstInnerH);
Rectangle dstBl = new Rectangle(x, dstHorzB, _margins.X, _margins.Height);
Rectangle dstBm = new Rectangle(dstVertL, dstHorzB, dstInnerW, _margins.Height);
Rectangle dstBr = new Rectangle(dstVertR, dstHorzB, _margins.Width, _margins.Height);
// Zeichnen
_game.SpriteBatch.Draw(_texture, dstTl, srcTl, _color);
_game.SpriteBatch.Draw(_texture, dstTm, srcTm, _color);
_game.SpriteBatch.Draw(_texture, dstTr, srcTr, _color);
_game.SpriteBatch.Draw(_texture, dstMl, srcMl, _color);
_game.SpriteBatch.Draw(_texture, dstMm, srcMm, _color);
_game.SpriteBatch.Draw(_texture, dstMr, srcMr, _color);
_game.SpriteBatch.Draw(_texture, dstBl, srcBl, _color);
_game.SpriteBatch.Draw(_texture, dstBm, srcBm, _color);
_game.SpriteBatch.Draw(_texture, dstBr, srcBr, _color);
}