/// <summary> /// Creates the IPTC-NAA caption record. /// </summary> /// <param name="value">A string containing the caption.</param> /// <param name="captionRecord">The byte array containing the caption data.</param> /// <returns><c>true</c> if the <paramref name="value"/> was converted successfully; otherwise, <c>false</c></returns> internal bool TryCreateCaptionRecord(string value, out byte[] captionRecord) { if (!createdCaptionRecord) { createdCaptionRecord = true; if (!string.IsNullOrEmpty(value)) { int captionLength = Encoding.ASCII.GetByteCount(value); if (captionLength < MaxCaptionLength) { IPTCCaption captionHeader = new IPTCCaption { version = new IPTCRecordVersion(IPTCVersion), tag = new IPTCTag(IPTCRecord.App2, App2DataSets.Caption, (ushort)captionLength) }; captionRecordBytes = new byte[IPTCCaption.SizeOf + captionLength]; captionHeader.Write(captionRecordBytes); Encoding.ASCII.GetBytes(value, 0, value.Length, captionRecordBytes, IPTCCaption.SizeOf); } } } captionRecord = captionRecordBytes; return(captionRecordBytes != null); }
/// <summary> /// Creates the IPTC-NAA caption record. /// </summary> /// <param name="value">A string containing the caption.</param> /// <param name="captionRecord">The byte array containing the caption data.</param> /// <returns><c>true</c> if the <paramref name="value"/> was converted successfully; otherwise, <c>false</c></returns> internal static bool TryCreateCaptionRecord(string value, out byte[] captionRecord) { if (!string.IsNullOrEmpty(value)) { int captionLength = Encoding.ASCII.GetByteCount(value); if (captionLength < MaxCaptionLength) { IPTCCaption captionHeader = new IPTCCaption { version = CreateVersionRecord(), tag = new IPTCTag(CaptionType, (ushort)captionLength) }; captionRecord = new byte[IPTCCaption.SizeOf + captionLength]; captionHeader.Write(captionRecord); Encoding.ASCII.GetBytes(value, 0, value.Length, captionRecord, IPTCCaption.SizeOf); return(true); } } captionRecord = null; return(false); }