Пример #1
0
        private void NewPanel(string name, string tags, System.Drawing.Bitmap imageS, Visibility visibility, bool isEnabled)
        {
            var spTemp = new StackPanel()
            {
                Tag = tags, Width = 140, Height = 110
            };
            var bTemp = new Button()
            {
                Tag = name, Width = 140, Height = 95, Content = new Image()
                {
                    Width = 160, Height = 90, Source = BitmapConversion.BitmapToBitmapSource(imageS)
                }
            };

            bTemp.PreviewMouseLeftButtonUp += BTemp_PreviewMouseLeftButtonUp;
            bTemp.MouseRightButtonUp       += BTemp_MouseRightButtonUp;
            bTemp.PreviewMouseUp           += BTemp_PreviewMouseUp;
            spTemp.Children.Add(bTemp);
            spTemp.Children.Add(new TextBlock()
            {
                Text = name, HorizontalAlignment = HorizontalAlignment.Center
            });
            mPage._itemCollection.Add(new ListBoxItem()
            {
                Content = spTemp, Visibility = visibility, IsEnabled = isEnabled
            });
        }
Пример #2
0
        private void ImageB_Drop(object sender, System.Windows.DragEventArgs e)
        {
            string[] link = (string[])e.Data.GetData(System.Windows.DataFormats.FileDrop);

            var imgTemp = new Bitmap(link[0]);

            System.Drawing.Size size = new System.Drawing.Size();

            if (imgTemp.Width == imgTemp.Height)
            {
                size = new System.Drawing.Size(300, 300);
            }
            else if (imgTemp.Width > imgTemp.Height)
            {
                size = new System.Drawing.Size(300, (int)(300 / ((float)imgTemp.Width / (float)imgTemp.Height)));
            }
            else
            {
                size = new System.Drawing.Size((int)(300 / ((float)imgTemp.Height / (float)imgTemp.Width)), 300);
            }

            using (var bmpTemp = new Bitmap(new Bitmap(link[0]), size))
            {
                wnd.imagePB.Source = BitmapConversion.BitmapToBitmapSource(bmpTemp);
                image = new Bitmap(bmpTemp);
            }
        }
Пример #3
0
        private void ImageBClick()
        {
            Stream         myStream = null;
            OpenFileDialog ofd      = new OpenFileDialog
            {
                Filter           = "Image files| *.bmp; *.png; *.jpg; *.jpeg; *.gif |All files (*.*)|*.*",
                FilterIndex      = 1,
                RestoreDirectory = true
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = ofd.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            var imgTemp = new Bitmap(ofd.FileName);
                            System.Drawing.Size size = new System.Drawing.Size();

                            if (imgTemp.Width == imgTemp.Height)
                            {
                                size = new System.Drawing.Size(300, 300);
                            }
                            else if (imgTemp.Width > imgTemp.Height)
                            {
                                size = new System.Drawing.Size(300, (int)(300 / ((float)imgTemp.Width / (float)imgTemp.Height)));
                            }
                            else
                            {
                                size = new System.Drawing.Size((int)(300 / ((float)imgTemp.Height / (float)imgTemp.Width)), 300);
                            }

                            using (var bmpTemp = new Bitmap(new Bitmap(ofd.FileName), size))
                            {
                                wnd.imagePB.Source = BitmapConversion.BitmapToBitmapSource(bmpTemp);
                                image = new Bitmap(bmpTemp);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    CustomMessageBox.Show(ex.Message, Properties.Resources.Error, MessageBoxButton.OK);
                }
            }
        }