private static RectangleF GetSourceRect(D2DImageStrip2D imageStrip, int index) { if (index < 0 || index >= imageStrip.Count) { throw new ArgumentOutOfRangeException(nameof(index)); } int xIndex, yIndex; float w, h; switch (imageStrip.Orientation) { case ImageStripOrientation.Horizontal: w = imageStrip.UnitWidth; h = imageStrip.UnitHeight; xIndex = index % imageStrip.ArrayCount; yIndex = index / imageStrip.ArrayCount; break; case ImageStripOrientation.Vertical: w = imageStrip.UnitWidth; h = imageStrip.UnitHeight; xIndex = index / imageStrip.ArrayCount; yIndex = index % imageStrip.ArrayCount; break; default: throw new ArgumentOutOfRangeException(); } var x = xIndex * w; var y = yIndex * h; return(new RectangleF(x, y, w, h)); }
public static void DrawImageStripUnit(this RenderContext context, D2DImageStrip2D imageStrip, int index, float destX, float destY, float destWidth, float destHeight, float opacity) { if (index < 0 || index >= imageStrip.Count) { throw new ArgumentOutOfRangeException(nameof(index), index, null); } var srcRect = GetSourceRect(imageStrip, index); context.DrawBitmap(imageStrip, destX, destY, destWidth, destHeight, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, opacity); }
public static void DrawImageStripUnit(this RenderContext context, D2DImageStrip2D imageStrip, int index, float destX, float destY, InterpolationMode interpolationMode, CompositeMode compositeMode) { if (index < 0 || index >= imageStrip.Count) { throw new ArgumentOutOfRangeException(nameof(index), index, null); } var srcRect = GetSourceRect(imageStrip, index); context.DrawImage(imageStrip, destX, destY, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, interpolationMode, compositeMode); }