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(); } }
public object Create(IconFrame frame, Func <Stream> load) { var img = new NSImage(); img.AddRepresentation(new LazyImageRep { Load = load }); return(new Bitmap(new BitmapHandler(img))); }
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)))); } }
public IconFrame GetIdealIcon() { if (idealFrame != null) { return(idealFrame); } var orderedFrames = SplitIcon(Control).OrderByDescending(r => r.PixelSize.Width * r.PixelSize.Height); idealFrame = orderedFrames.FirstOrDefault(r => r.Scale == 1) ?? orderedFrames.First(); return(idealFrame); }
IconFrame GetLargestIcon() { IconFrame curicon = null; foreach (var icon in Frames) { if (curicon == null || icon.PixelSize.Width > curicon.PixelSize.Width) { curicon = icon; } } return(curicon); }
private void Dispose(bool disposing) { if (IconFrame != null) { IconFrame.Dispose(); } if (IconInputBar != null) { IconInputBar.Dispose(); } if (LabelText != null) { LabelText.Dispose(); } }
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)))); } }
public Size GetPixelSize(IconFrame frame) { return(GetBitmap(frame).Size); }
public Bitmap GetBitmap(IconFrame frame) { return((Bitmap)frame.ControlObject); }
public object Create(IconFrame frame, Bitmap bitmap) { return(sd.Icon.FromHandle(((sd.Bitmap)bitmap.ToSD()).GetHicon())); }
public static swmi.BitmapSource ToWpf(this IconFrame image, float?scale = null, Size?fittingSize = null) { return(((Bitmap)image?.ControlObject).ToWpf(scale, fittingSize)); }
public Bitmap GetBitmap(IconFrame frame) { throw new NotImplementedException(); }
public object Create(IconFrame frame, Func <System.IO.Stream> load) { throw new NotImplementedException(); }
public static swmi.BitmapSource ToWpf(this IconFrame image, int?size = null) { return(((Bitmap)image?.ControlObject).ToWpf()); }
public Size GetPixelSize(IconFrame frame) { return(((sd.Icon)frame.ControlObject).Size.ToEto()); }
public Bitmap GetBitmap(IconFrame frame) { return(new Bitmap(new BitmapHandler(((sd.Icon)frame.ControlObject).ToBitmap()))); }
public object Create(IconFrame frame, Stream stream) { return(new sd.Icon(stream)); }
public object Create(IconFrame frame, Func <Stream> load) { return(sd.Icon.FromHandle(new sd.Bitmap(load()).GetHicon())); }
public object Create(IconFrame frame, Bitmap bitmap) { return(bitmap); }
public object Create(IconFrame frame, Func <Stream> load) { return(new Bitmap(load())); }
public object Create(IconFrame frame, Bitmap bitmap) { throw new NotImplementedException(); }
public object Create(IconFrame frame, Stream stream) { return(new Bitmap(stream)); }
public object Create(IconFrame frame, System.IO.Stream stream) { throw new NotImplementedException(); }
public Size GetPixelSize(IconFrame frame) { throw new NotImplementedException(); }