Beispiel #1
0
        private async void LoadImage()
        {
            if (!_fileLoaded || _openedFile == null)
            {
                return;
            }

            if (!int.TryParse(tbOffset.Text, out var offset) &&
                !int.TryParse(tbOffset.Text.Replace("0x", ""), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out offset) ||
                !int.TryParse(tbWidth.Text, out var width) ||
                !int.TryParse(tbHeight.Text, out var height))
            {
                return;
            }

            if (offset < 0 || offset >= _openedFile.Length || width <= 0 || height <= 0)
            {
                return;
            }

            ToggleProperties(false);
            ToggleForm(false);

            var neededData = SelectedColorEncodingAdapter.CalculateLength(width, height);

            _openedFile.Position = offset;
            var imgData = new byte[Math.Min(neededData, _openedFile.Length - offset)];

            _openedFile.Read(imgData, 0, imgData.Length);

            var progress = new Progress <ProgressReport>();

            try
            {
                pbMain.Image = await SelectedColorEncodingAdapter.Decode(imgData, width, height, progress);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Exception catched.", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            tslPbWidth.Text  = pbMain.Width.ToString();
            tslPbHeight.Text = pbMain.Height.ToString();

            ToggleProperties(true);
            ToggleForm(true);
        }
        private void UpdateEncodingProperties()
        {
            _pnlEncodingProperties.Controls.Clear();

            if (SelectedColorEncodingAdapter != null)
            {
                UpdateExtendedPropertiesWith(
                    _pnlEncodingProperties,
                    50,
                    EncodingPropertyTextBox_TextChanged,
                    EncodingPropertyComboBox_SelectedIndexChanged,
                    EncodingPropertyCheckBox_CheckedChanged,
                    SelectedColorEncodingAdapter.
                    GetType().
                    GetCustomAttributes(typeof(PropertyAttribute), false).
                    Cast <PropertyAttribute>().
                    ToArray());
            }
        }