/// <summary>
        /// find an enumerated DialogAudio that matches the serialized form present in a provided LocalSettings value.
        /// </summary>
        /// <param name="settingsValue"> A serialized DialogAudio object from LocalSettings data. </param>
        /// <returns> A reference to the matching DialogAudio object. Null if not found. </returns>
        public static DialogAudio GetFromSettingsValue(ApplicationDataCompositeValue settingsValue)
        {
            bool Matches <T>(string key, T value)
                where T : IEquatable <T>
            => settingsValue.Keys.Contains(key) && Equals(settingsValue[key], value);

            var dialogAudio = AllFormats.FirstOrDefault(format =>
                                                        Matches <string>(KeyForSubtype, format.Encoding.Subtype) &&
                                                        Matches <uint>(KeyForSampleRate, format.Encoding.SampleRate) &&
                                                        Matches <uint>(KeyForBitsPerSample, format.Encoding.BitsPerSample) &&
                                                        Matches <uint>(KeyForBitrate, format.Encoding.Bitrate) &&
                                                        Matches <uint>(KeyForChannelCount, format.Encoding.ChannelCount));

            return(dialogAudio);
        }
Пример #2
0
        private void doWrite()
        {
            string filename = m_selectedFileName;

            if (!collectWidth())
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            try
            {
                Rectangle physicalBounds = new Rectangle(0, 0, width, height);

                Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);

                Graphics graphics = Graphics.FromImage(bitmap);

                graphics.FillRectangle(Project.whiteBrush, physicalBounds);

                Project.mainCommand.doPrintPage(physicalBounds, graphics, false);

                // default is JPEG
                m_imageFormat    = ImageFormat.Jpeg;
                m_selectedFormat = "JPEG";
                m_defaultExt     = ".jpg";

                if (filename.ToLower().EndsWith(".bmp"))
                {
                    m_imageFormat    = ImageFormat.Bmp;
                    m_selectedFormat = "BMP";
                    m_defaultExt     = ".bmp";
                }
                else if (filename.ToLower().EndsWith(".gif"))
                {
                    m_imageFormat    = ImageFormat.Gif;
                    m_selectedFormat = "GIF";
                    m_defaultExt     = ".gif";
                }
                else if (AllFormats.isTiffFile(filename))
                {
                    m_imageFormat    = ImageFormat.Tiff;
                    m_selectedFormat = "TIFF";
                    m_defaultExt     = ".tif";
                }
                else if (filename.ToLower().EndsWith(".png"))
                {
                    m_imageFormat    = ImageFormat.Png;
                    m_selectedFormat = "PNG";
                    m_defaultExt     = ".png";
                }

                if (!filename.ToLower().EndsWith(m_defaultExt))
                {
                    filename += m_defaultExt;
                }

                filename           = new FileInfo(filename).FullName;
                fileTextBox.Text   = filename;
                m_selectedFileName = filename;

                bitmap.Save(filename, m_imageFormat);

                messageLabel.Text = "OK: saved";
            }
            catch (Exception ee)
            {
                messageLabel.Text = ee.Message;
            }
            Cursor.Current = Cursors.Default;
        }
 /// <summary>
 /// Finds the first enumerated DialogAudio object that matches the provided readable label.
 /// </summary>
 /// <param name="label"> The label to match. Case-sensitive. </param>
 /// <returns> The first match found. Null if not found. </returns>
 public static DialogAudio GetMatchFromLabel(string label) => AllFormats.FirstOrDefault(format => format.Label == label);