コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: IPTCData.cs プロジェクト: simedcn/PSFilterHost
        /// <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);
        }
コード例 #3
0
ファイル: IPTCData.cs プロジェクト: simedcn/PSFilterHost
        /// <summary>
        /// Converts the caption from unmanaged memory.
        /// </summary>
        /// <param name="data">The data.</param>
        internal static string CaptionFromMemory(IntPtr data)
        {
            if (data != IntPtr.Zero)
            {
                IPTCCaption captionHeader = new IPTCCaption(data);
                string      caption       = string.Empty;

                if (captionHeader.tag.length > 0)
                {
                    byte[] bytes = new byte[captionHeader.tag.length];

                    Marshal.Copy(new IntPtr(data.ToInt64() + IPTCCaption.SizeOf), bytes, 0, bytes.Length);

                    caption = Encoding.ASCII.GetString(bytes);
                }

                return(caption);
            }

            return(null);
        }