private double CalcSectionSize(PatchSection sec, double totalVariable, double stretchableSize, ref double remainingVariable) { if (sec.Mode != RenderMode.Fixed) { double sw = Math.Round(totalVariable * (sec.Size / stretchableSize)); if (sw > remainingVariable) { sw = remainingVariable; } remainingVariable -= sw; return(sw); } else { return(sec.Size); } }
private List <PatchSection> CreateSections(IEnumerable <SKColor> pixels) { List <PatchSection> sections = new List <PatchSection>(); PatchSection section = null; int n = 0; foreach (var p in pixels) { RenderMode mode; if (p.Red == 0 && p.Blue == 0 && p.Green == 0 && p.Alpha == 255) { mode = RenderMode.Stretch; } else { mode = RenderMode.Fixed; } if (section == null || mode != section.Mode) { section = new PatchSection { Start = n, Size = 1, Mode = mode }; sections.Add(section); } else { section.Size++; } n++; } return(sections); }