public static System.Drawing.Bitmap ToBitmap(System.Drawing.Icon icon, Skybound.Drawing.Design.IconFormat iconFormat) { Skybound.Drawing.Design.IconFile.BITMAP bitmap; Skybound.Drawing.Design.IconFile.ICONINFO iconinfo; System.Drawing.Bitmap bitmap1 = null; if (icon != null) { if (iconFormat.ColorDepth == System.Windows.Forms.ColorDepth.Depth32Bit) { Skybound.Drawing.Design.IconFile.GetIconInfo(icon.Handle, out iconinfo); bitmap = new Skybound.Drawing.Design.IconFile.BITMAP(); Skybound.Drawing.Design.IconFile.GetObjectBitmap(iconinfo.hbmColor, System.Runtime.InteropServices.Marshal.SizeOf(typeof(Skybound.Drawing.Design.IconFile.BITMAP)), ref bitmap); int i = bitmap.bmWidthBytes * bitmap.bmHeight; int[] iArr = new int[(i / 4)]; Skybound.Drawing.Design.IconFile.GetBitmapBits(iconinfo.hbmColor, i, iArr); System.Runtime.InteropServices.GCHandle gchandle = System.Runtime.InteropServices.GCHandle.Alloc(iArr, System.Runtime.InteropServices.GCHandleType.Pinned); System.Drawing.Bitmap bitmap2 = new System.Drawing.Bitmap(bitmap.bmWidth, bitmap.bmHeight, bitmap.bmWidthBytes, System.Drawing.Imaging.PixelFormat.Format32bppArgb, System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(iArr, 0)); bitmap1 = new System.Drawing.Bitmap(bitmap2.Width, bitmap2.Height); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap1)) { graphics.DrawImage(bitmap2, 0, 0, bitmap2.Width, bitmap2.Height); } gchandle.Free(); Skybound.Drawing.Design.IconFile.DeleteObject(iconinfo.hbmMask); Skybound.Drawing.Design.IconFile.DeleteObject(iconinfo.hbmColor); } else { bitmap1 = icon.ToBitmap(); } } return(bitmap1); }
public IconFile(System.IO.Stream s) { Skybound.Drawing.Design.IconFile.ICONDIR icondir; Skybound.Drawing.Design.IconFile.ICONDIRENTRY icondirentry; using (System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(s)) { icondir = new Skybound.Drawing.Design.IconFile.ICONDIR(); icondir.Read(binaryReader); if ((icondir.idReserved != 0) || (icondir.idType != 1)) { throw new System.Exception("The specified stream did not contain a valid icon."); } icondirentry = new Skybound.Drawing.Design.IconFile.ICONDIRENTRY(); Formats = new Skybound.Drawing.Design.IconFormat[icondir.idCount]; IconData = new System.Collections.Hashtable(); IconDirEntries = new System.Collections.Hashtable(); for (int i = 0; (ushort)i < icondir.idCount; i++) { icondirentry.Read(binaryReader); Formats[i] = new Skybound.Drawing.Design.IconFormat(new System.Drawing.Size(icondirentry.bWidth, icondirentry.bHeight), GetColorDepth(icondirentry.wBitCount * icondirentry.wPlanes)); long l = s.Position; s.Position = (long)icondirentry.dwImageOffset; byte[] bArr = new byte[icondirentry.dwBytesInRes]; s.Read(bArr, 0, icondirentry.dwBytesInRes); IconData[Formats[i]] = bArr; IconDirEntries[Formats[i]] = icondirentry; s.Position = l; } } }
public System.Drawing.Icon ToIcon(System.Drawing.Size size) { Skybound.Drawing.Design.IconFormat iconFormat = FindBestFormat(size); if (iconFormat.Size == System.Drawing.Size.Empty) { return(null); } return(ToIcon(iconFormat)); }
public override bool Equals(object obj) { if (obj is Skybound.Drawing.Design.IconFormat) { Skybound.Drawing.Design.IconFormat iconFormat = (Skybound.Drawing.Design.IconFormat)obj; if (iconFormat._Size == _Size) { return(iconFormat._ColorDepth == _ColorDepth); } return(false); } return(false); }
private Skybound.Drawing.Design.IconFormat FindBestFormat(System.Drawing.Size size) { Skybound.Drawing.Design.IconFormat iconFormat1 = new Skybound.Drawing.Design.IconFormat(System.Drawing.Size.Empty, System.Windows.Forms.ColorDepth.Depth4Bit); Skybound.Drawing.Design.IconFormat[] iconFormatArr = Formats; for (int i = 0; i < iconFormatArr.Length; i++) { Skybound.Drawing.Design.IconFormat iconFormat2 = iconFormatArr[i]; if (iconFormat2.Size == size && (iconFormat2.ColorDepth >= iconFormat1.ColorDepth)) { iconFormat1 = iconFormat2; } } return(iconFormat1); }
public System.Drawing.Icon ToIcon(Skybound.Drawing.Design.IconFormat iconFormat) { Skybound.Drawing.Design.IconFile.ICONDIR icondir; byte[] bArr = (byte[])IconData[iconFormat]; System.Drawing.Icon icon = null; if (bArr != null) { System.IO.Stream stream = new System.IO.MemoryStream(); System.IO.BinaryWriter binaryWriter = new System.IO.BinaryWriter(stream); icondir = new Skybound.Drawing.Design.IconFile.ICONDIR(); icondir.idCount = 1; icondir.idType = 1; icondir.WriteToStream(binaryWriter); Skybound.Drawing.Design.IconFile.ICONDIRENTRY icondirentry = (Skybound.Drawing.Design.IconFile.ICONDIRENTRY)IconDirEntries[iconFormat]; icondirentry.dwImageOffset = System.Runtime.InteropServices.Marshal.SizeOf(typeof(Skybound.Drawing.Design.IconFile.ICONDIR)) + System.Runtime.InteropServices.Marshal.SizeOf(typeof(Skybound.Drawing.Design.IconFile.ICONDIRENTRY)); icondirentry.WriteToStream(binaryWriter); stream.Write(bArr, 0, bArr.Length); stream.Position = (long)0; icon = new System.Drawing.Icon(stream, icondirentry.bWidth, icondirentry.bHeight); } return(icon); }
public System.Drawing.Bitmap ToBitmap(Skybound.Drawing.Design.IconFormat iconFormat) { return(Skybound.Drawing.Design.IconFile.ToBitmap(ToIcon(iconFormat), iconFormat)); }
static IconFormat() { Skybound.Drawing.Design.IconFormat.Empty = new Skybound.Drawing.Design.IconFormat(); }