protected static Bitmap ExtractBitmapFromIcon(string iconPath, int desiredWidth = 150, int desiredHeight = 150) { Bitmap bitmap = null; var i = new System.Drawing.IconLib.MultiIcon(); var si = i.Add("icon"); using (var stream = new FileStream(iconPath, FileMode.Open)) { si.Load(stream); } int maxWidth = 0; int maxIdx = -1; int idx = 0; foreach (var imag in si) { // imag.IconImageFormat = IconImageFormat.PNG; if (imag.Size.Width >= desiredWidth && imag.Size.Height >= desiredHeight && imag.IconImageFormat == IconImageFormat.PNG) { return(imag.Transparent); } if (imag.Size.Width > maxWidth && imag.IconImageFormat == IconImageFormat.PNG) { maxIdx = idx; maxWidth = imag.Size.Width; } ++idx; } if (maxIdx > -1) { bitmap = si[maxIdx].Transparent; } return(bitmap); }
public void Load(Stream stream) { IconFormat iconFormat = new IconFormat(); if (!iconFormat.IsRecognizedFormat(stream)) { throw new InvalidFileException(); } MultiIcon multiIcon = iconFormat.Load(stream); if (multiIcon.Count < 1) { return; } this.CopyFrom(multiIcon[0]); }
private void CopyFrom(MultiIcon multiIcon) { mSelectedIndex = multiIcon.mSelectedIndex; Clear(); AddRange(multiIcon); }
private void UpdateYachtImage(int yachtId) { Bitmap background = new Bitmap(yachtList[yachtId].IconSize, yachtList[yachtId].IconSize, PixelFormat.Format32bppArgb); Image yachtImage = imageListYacht.Images["Yacht"]; PointF yachtOffset = new PointF((background.Width - yachtImage.Width) / 2, (background.Height - yachtImage.Height) / 2); using (Graphics gimage = Graphics.FromImage(background)) { gimage.TranslateTransform(background.Width / 2, background.Height / 2); //if (checkBoxNorthUp.Checked) //{ gimage.RotateTransform(yachtList[yachtId].Heading); //} //else //{ // gimage.RotateTransform(yachtList[yachtId].Heading); //} gimage.TranslateTransform(-background.Width / 2, -background.Height / 2); gimage.DrawImage(yachtImage, yachtOffset.X, yachtOffset.Y); } Image sail = imageListYacht.Images["Sail"]; PointF sailOffset = new PointF((background.Width - sail.Width) / 2, (background.Height - sail.Height) / 2); using (Graphics gimage = Graphics.FromImage(background)) { gimage.TranslateTransform(background.Width / 2, background.Height / 2); //if (checkBoxNorthUp.Checked) //{ gimage.RotateTransform(yachtList[yachtId].SailDirection); //} //else //{ // gimage.RotateTransform((yachtList[yachtId].SailDirection - yachtList[yachtId].Heading + 360) % 360); //} gimage.TranslateTransform(-background.Width / 2, -background.Height / 2); gimage.DrawImage(sail, sailOffset.X, sailOffset.Y); } Image wind = imageListYacht.Images["Wind"]; PointF windOffset = new PointF((background.Width - wind.Width) / 2, (background.Height - wind.Height) / 2); using (Graphics gimage = Graphics.FromImage(background)) { gimage.TranslateTransform(background.Width / 2, background.Height / 2); //if (checkBoxNorthUp.Checked) //{ gimage.RotateTransform(yachtList[yachtId].WindAngle); //} //else //{ // gimage.RotateTransform((yachtList[yachtId].WindAngle - yachtList[yachtId].Heading + 360) % 360); //} gimage.TranslateTransform(-background.Width / 2, -background.Height / 2); gimage.DrawImage(wind, windOffset.X, windOffset.Y); } try { MultiIcon multiIcon = new System.Drawing.IconLib.MultiIcon(); SingleIcon sIcon = multiIcon.Add("Icon1"); sIcon.CreateFrom(background, IconOutputFormat.Vista); if (yachtList[yachtId].FalconViewIconHandle != -1) { int result = fvLayer.DeleteObject(fvLayerHandle, yachtList[yachtId].FalconViewIconHandle); fvLayer.Refresh(fvLayerHandle); } //yachtList[yachtId].NorthUp = checkBoxNorthUp.Checked; if (!File.Exists(yachtList[yachtId].IconFileName)) { //File.Delete(yachtList[yachtId].IconFileName); sIcon.Save(yachtList[yachtId].IconFileName); } } catch { } if (File.Exists(yachtList[yachtId].IconFileName)) { yachtList[yachtId].FalconViewIconHandle = fvLayer.AddIcon(fvLayerHandle, yachtList[yachtId].IconFileName, yachtList[yachtId].Location.Latitude.TotalDegrees, yachtList[yachtId].Location.Longitude.TotalDegrees, yachtList[yachtId].Text); } fvLayer.Refresh(fvLayerHandle); }