static void saveImage(VCard vCard) { PhotoProperty photo = vCard.Photo; if (photo.ValueLocation != ValLocValue.Binary) { return; } byte[] imageBytes = photo.GetImageBytes(); Bitmap bm; try { bm = new Bitmap(new System.IO.MemoryStream(imageBytes)); } catch (Exception ex) { Utils.excMsg("Failed to create Bitmap", ex); return; } try { string fileName = outputDirName + vCard.Name.FormattedName + ".png"; bm.Save(fileName, ImageFormat.Png); Console.Write(" Saved photo as " + fileName + LF); } catch (Exception ex) { Utils.excMsg("Failed to save Bitmap", ex); } }
private byte[] ConvertVCardPhoto(PhotoProperty photoProperty, byte[] defaultImage) { if (photoProperty != null && !string.IsNullOrEmpty(photoProperty.Value)) { try { if (photoProperty.Value.ToUpper().Contains("ENCODING=BASE64")) { int typeIndex = photoProperty.Value.IndexOf("TYPE=JPEG;"); string encodedImage = (typeIndex < 0) ? photoProperty.Value : photoProperty.Value.Remove(typeIndex, "TYPE=JPEG;".Length); int typeAltIndex = encodedImage.IndexOf("TYPE=JPEG:"); encodedImage = (typeAltIndex < 0) ? encodedImage : encodedImage.Remove(typeAltIndex, "TYPE=JPEG:".Length); int encodingIndex = encodedImage.IndexOf("ENCODING=BASE64;"); encodedImage = (encodingIndex < 0) ? encodedImage : encodedImage.Remove(encodingIndex, "ENCODING=BASE64;".Length); int encodingAltIndex = encodedImage.IndexOf("ENCODING=BASE64:"); encodedImage = (encodingAltIndex < 0) ? encodedImage : encodedImage.Remove(encodingAltIndex, "ENCODING=BASE64:".Length); return(Convert.FromBase64String(encodedImage)); } else { return(Images.ImageUrlToBytes(photoProperty.Value)); } } catch (Exception e) { _logger.Error($"Failed to convert vCard photo: {e.Message}"); return(defaultImage); } } return(defaultImage); }
/// <summary> /// This is overridden to allow copying of the additional properties /// </summary> /// <param name="p">The PDI object from which the settings are to be copied</param> protected override void Clone(PDIObject p) { VCard o = (VCard)p; this.ClearProperties(); groupName = o.Group; fn = (FormattedNameProperty)o.FormattedName.Clone(); name = (NameProperty)o.Name.Clone(); title = (TitleProperty)o.Title.Clone(); role = (RoleProperty)o.Role.Clone(); mailer = (MailerProperty)o.Mailer.Clone(); url = (UrlProperty)o.Url.Clone(); org = (OrganizationProperty)o.Organization.Clone(); uid = (UniqueIdProperty)o.UniqueId.Clone(); bday = (BirthDateProperty)o.BirthDate.Clone(); rev = (LastRevisionProperty)o.LastRevision.Clone(); tz = (TimeZoneProperty)o.TimeZone.Clone(); geo = (GeographicPositionProperty)o.GeographicPosition.Clone(); key = (PublicKeyProperty)o.PublicKey.Clone(); photo = (PhotoProperty)o.Photo.Clone(); logo = (LogoProperty)o.Logo.Clone(); sound = (SoundProperty)o.Sound.Clone(); this.Notes.CloneRange(o.Notes); this.Addresses.CloneRange(o.Addresses); this.Labels.CloneRange(o.Labels); this.Telephones.CloneRange(o.Telephones); this.EMailAddresses.CloneRange(o.EMailAddresses); this.Agents.CloneRange(o.Agents); this.CustomProperties.CloneRange(o.CustomProperties); addProfile = o.AddProfile; mimeName = (MimeNameProperty)o.MimeName.Clone(); mimeSource = (MimeSourceProperty)o.MimeSource.Clone(); prodId = (ProductIdProperty)o.ProductId.Clone(); nickname = (NicknameProperty)o.Nickname.Clone(); sortString = (SortStringProperty)o.SortString.Clone(); classification = (ClassificationProperty)o.Classification.Clone(); categories = (CategoriesProperty)o.Categories.Clone(); }
/// <summary> /// The method can be called to clear all current property values from the vCard. The version is left /// unchanged. /// </summary> public void ClearProperties() { groupName = null; fn = null; name = null; title = null; role = null; mailer = null; url = null; org = null; uid = null; bday = null; rev = null; tz = null; geo = null; key = null; photo = null; logo = null; sound = null; notes = null; addrs = null; labels = null; phones = null; email = null; agents = null; customProps = null; addProfile = false; mimeName = null; mimeSource = null; prodId = null; nickname = null; sortString = null; classification = null; categories = null; }
set => base.SetValue(PhotoProperty, value);