private static void ImportIcon(XmlNode xn, PwEntry pe, PwDatabase pd) { XmlNode xnIcon = xn.Attributes.GetNamedItem("ICON"); if (xnIcon == null) { return; } string strIcon = xnIcon.Value; if (!StrUtil.IsDataUri(strIcon)) { Debug.Assert(false); return; } try { byte[] pbImage = StrUtil.DataUriToData(strIcon); if ((pbImage == null) || (pbImage.Length == 0)) { Debug.Assert(false); return; } Image img = GfxUtil.LoadImage(pbImage); if (img == null) { Debug.Assert(false); return; } byte[] pbPng; int wMax = PwCustomIcon.MaxWidth; int hMax = PwCustomIcon.MaxHeight; if ((img.Width <= wMax) && (img.Height <= hMax)) { using (MemoryStream msPng = new MemoryStream()) { img.Save(msPng, ImageFormat.Png); pbPng = msPng.ToArray(); } } else { using (Image imgSc = GfxUtil.ScaleImage(img, wMax, hMax)) { using (MemoryStream msPng = new MemoryStream()) { imgSc.Save(msPng, ImageFormat.Png); pbPng = msPng.ToArray(); } } } img.Dispose(); PwUuid pwUuid = null; int iEx = pd.GetCustomIconIndex(pbPng); if (iEx >= 0) { pwUuid = pd.CustomIcons[iEx].Uuid; } else { pwUuid = new PwUuid(true); pd.CustomIcons.Add(new PwCustomIcon(pwUuid, pbPng)); pd.UINeedsIconUpdate = true; pd.Modified = true; } pe.CustomIconUuid = pwUuid; } catch (Exception) { Debug.Assert(false); } }