const int sICONDIRENTRY = 16; // sizeof(ICONDIRENTRY) public List <IconFrame> SplitIcon(sd.Icon icon) { if (frames != null) { return(frames); } if (icon == null) { throw new ArgumentNullException("icon"); } // Get multiple .ico file image. byte[] srcBuf; using (var stream = new MemoryStream()) { icon.Save(stream); stream.Flush(); srcBuf = stream.ToArray(); } var splitIcons = new List <sd.Icon>(); int count = BitConverter.ToInt16(srcBuf, 4); // ICONDIR.idCount for (int i = 0; i < count; i++) { using (var destStream = new MemoryStream()) using (var writer = new BinaryWriter(destStream)) { // Copy ICONDIR and ICONDIRENTRY. int pos = 0; writer.Write(srcBuf, pos, sICONDIR - 2); writer.Write((short)1); // ICONDIR.idCount == 1; pos += sICONDIR; pos += sICONDIRENTRY * i; writer.Write(srcBuf, pos, sICONDIRENTRY - 4); // write out icon info (minus old offset) writer.Write(sICONDIR + sICONDIRENTRY); // write offset of icon data pos += 8; // Copy picture and mask data. int imgSize = BitConverter.ToInt32(srcBuf, pos); // ICONDIRENTRY.dwBytesInRes pos += 4; int imgOffset = BitConverter.ToInt32(srcBuf, pos); // ICONDIRENTRY.dwImageOffset if (imgOffset + imgSize > srcBuf.Length) { throw new ArgumentException("ugh"); } writer.Write(srcBuf, imgOffset, imgSize); writer.Flush(); // Create new icon. destStream.Seek(0, SeekOrigin.Begin); splitIcons.Add(new sd.Icon(destStream)); } } frames = splitIcons.Select(r => IconFrame.FromControlObject(1, r)).ToList(); return(frames); }
void CreateFrames(MemoryStream input) { frames = new List <IconFrame>(); foreach (var pb in SplitIcon(input)) { frames.Add(IconFrame.FromControlObject(1, new Bitmap(new BitmapHandler(pb)))); } }
IEnumerable <IconFrame> GetFrames() { foreach (var rep in Control.Representations()) { var img = new NSImage(); img.AddRepresentation(rep); yield return(IconFrame.FromControlObject(1, new Bitmap(new BitmapHandler(img)))); } }
protected override void Initialize() { base.Initialize(); if (iconFrames == null) { // create frames iconFrames = Frames.Select(r => IconFrame.FromControlObject(1f, new Bitmap(new BitmapHandler(r)))).ToList(); } }
void SetFrames(MemoryStream ms) { var icons = SplitIcon(Control, ms); frames = new List <IconFrame>(); foreach (var icon in icons) { frames.Add(IconFrame.FromControlObject(1f, new Bitmap(new BitmapHandler(icon)))); } }
void SetFrames() { _frames = new List <IconFrame>(); foreach (var rep in Control.Representations()) { var img = new NSImage(); img.AddRepresentation(rep); _frames.Add(IconFrame.FromControlObject(1, new Bitmap(new BitmapHandler(img)))); } }
IEnumerable <IconFrame> GetFrames() { var icons = Control?.Decoder?.Frames; if (icons == null) { yield return(IconFrame.FromControlObject(1f, new Bitmap(new BitmapHandler(Control)))); yield break; } foreach (var icon in icons) { // this is needed to actually load the icon so it can then be used in other threads. // even though we freeze it, it delays the creation until something like this is called.. _ = icon.PixelWidth; yield return(IconFrame.FromControlObject(1f, new Bitmap(new BitmapHandler(icon)))); } }