Esempio n. 1
0
        void HandleInsertImageActionTriggered()
        {
            var dialog = new QFileDialog(this.TopLevelWidget(),"Select Photo");

            dialog.fileMode = QFileDialog.FileMode.ExistingFile;
            if (dialog.Exec() == (int)QFileDialog.DialogCode.Accepted && dialog.SelectedFiles().Count > 0)
            {
                string fileName = dialog.SelectedFiles()[0];
                textEdit.InsertImage(fileName);
            }
        }
Esempio n. 2
0
        void on_avatarBrowseButton_clicked()
        {
            var dialog = new QFileDialog(this.TopLevelWidget(), "Select Avatar");

            dialog.fileMode = QFileDialog.FileMode.ExistingFile;
            if (dialog.Exec() == (int)DialogCode.Accepted && dialog.SelectedFiles().Count > 0)
            {
                string fileName = dialog.SelectedFiles()[0];

                try {
                    byte[] buffer = null;
                    Image  image  = Image.FromFile(fileName);
                    using (MemoryStream stream = new MemoryStream()) {
                        image.Save(stream, image.RawFormat);
                        buffer = stream.GetBuffer();
                    }
                    SetAvatar(buffer, image.RawFormat);
                } catch (Exception ex) {
                    Application.Client.ShowErrorWindow("Failed to set avatar. The file you selected may be an unsupported image type or may be damaged.", ex);
                }
            }
        }