コード例 #1
0
        private void RemoveImage_Click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;

            int oid = Convert.ToInt32(button.DataContext);

            TrainingDataSet.ExpressionRow row = _DataSet.Expression.FindByExpressionOID(oid);

            if (row != null)
            {
                row.Thumbnail = null;
            }
        }
コード例 #2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                TableAdapterManager tam     = new TableAdapterManager();
                TrainingDataSet     dataSet = new TrainingDataSet();
                tam.ExpressionTableAdapter = new ExpressionTableAdapter();

                tam.ExpressionTableAdapter.Fill(dataSet.Expression);

                int eoid = System.Convert.ToInt32(value);

                if (!DBNull.Value.Equals(eoid))
                {
                    TrainingDataSet.ExpressionRow row = dataSet.Expression.FindByExpressionOID(eoid);

                    if (!DBNull.Value.Equals(row) && !DBNull.Value.Equals(row.Thumbnail))
                    {
                        byte[] imageData = row.Thumbnail;

                        if (imageData != null && !DBNull.Value.Equals(imageData))
                        {
                            byte[]       data = (byte[])value;
                            MemoryStream ms   = new MemoryStream(data);

                            BitmapImage image = new BitmapImage();
                            image.BeginInit();
                            image.StreamSource = ms;
                            image.EndInit();

                            return(image);
                        }
                    }
                }

                return(null);
            }
            catch (NullReferenceException)
            {
                return(null);
            }
            catch (System.Data.StrongTypingException)
            {
                return(null);
            }
        }
コード例 #3
0
        private void BrowseImage_Click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;

            // Configure save file dialog box
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.DefaultExt = ".";                                                                                                        // Default file extension
            dlg.Filter     = "Imagefiles (*.bmp, *.jpg, *.png, *.tif, *.tiff, *.tga, *.pgm)|*.bmp;*.jpg;*.png;*.tif;*.tiff;*.tga;*.pgm"; // Filter files by extension
            dlg.Title      = "Load image";

            // Show save file dialog box
            Nullable <bool> result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                System.Drawing.Bitmap emoticon = new System.Drawing.Bitmap(dlg.FileName);

                const int thumbnailWidth  = 50;
                const int thumbnailHeight = 50;

                System.Drawing.Image.GetThumbnailImageAbort tc = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
                System.Drawing.Image thumbnail = emoticon.GetThumbnailImage(thumbnailWidth, thumbnailHeight, tc, IntPtr.Zero);

                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                thumbnail.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                Console.WriteLine("Length: " + ms.ToArray().Length);

                int oid = Convert.ToInt32(button.DataContext);

                TrainingDataSet.ExpressionRow row = _DataSet.Expression.FindByExpressionOID(oid);

                if (row != null && !DBNull.Value.Equals(row))
                {
                    row.Thumbnail = ms.ToArray();
                }
            }
        }