コード例 #1
0
ファイル: MaskWindow.cs プロジェクト: wangws556/duoduo-chat
        private void Ini()
        {
            
            //ini normal properties
            //Topmost = true;
            WindowStyle = WindowStyle.None;
            ResizeMode = ResizeMode.NoResize;
            ShowInTaskbar = false;

            //set bounds to cover all screens
            var rect = SystemInformation.VirtualScreen;
            Left = rect.X;
            Top = rect.Y;
            Width = rect.Width;
            Height = rect.Height;

            //set background 
            screenSnapshot = HelperMethods.GetScreenSnapshot();
            if (screenSnapshot != null)
            {
                var bmp = screenSnapshot.ToBitmapSource();
                bmp.Freeze();
                Background = new ImageBrush(bmp);
            }

            //ini canvas
            innerCanvas = new MaskCanvas
            {
                MaskWindowOwner = this
            };
            Content = innerCanvas;

        }
コード例 #2
0
 /// <summary>
 /// Converts a <see cref="System.Drawing.Image"/> into a WPF <see cref="BitmapSource"/>.
 /// </summary>
 /// <param name="source">The source image.</param>
 /// <returns>A BitmapSource</returns>
 public static BitmapSource ToBitmapSource(this Image source)
 {
     using (Bitmap bitmap = new Bitmap(source))
     {
         BitmapSource bitSrc = bitmap.ToBitmapSource();
         return bitSrc;
     }
 }
コード例 #3
0
        public static BitmapSource ToBitmapSource(this Image source)
        {
            var bitmap = new Bitmap(source);

            var bitSrc = bitmap.ToBitmapSource();

            bitmap.Dispose();

            return bitSrc;
        }
コード例 #4
0
		public static ImageSource ToImageSource(this System.Windows.Forms.Cursor cursor)
		{
			int width = cursor.Size.Width;
			int height = cursor.Size.Height;
			using (System.Drawing.Bitmap b = new System.Drawing.Bitmap(width, height)) {
				using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b)) {
					cursor.Draw(g, new System.Drawing.Rectangle(0, 0, width, height));
					return b.ToBitmapSource();
				}
			}
		}
コード例 #5
0
ファイル: ImageHelpers.cs プロジェクト: pvishal/kinpos
        /// <summary>
        /// Converts a <see cref="System.Drawing.Image"/> into a WPF <see cref="BitmapSource"/>.
        /// </summary>
        /// <param name="source">The source image.</param>
        /// <returns>A BitmapSource</returns>
        public static BitmapSource ToBitmapSource(this System.Drawing.Image source)
        {
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(source);

            var bitSrc = bitmap.ToBitmapSource();

            bitmap.Dispose();
            bitmap = null;

            return bitSrc;
        }
コード例 #6
0
        /// <summary>
        /// Converts a <see cref="System.Drawing.Image"/> into a WPF <see cref="BitmapSource"/>.
        /// </summary>
        /// <param name="source">The source image.</param>
        /// <returns>A BitmapSource</returns>
        public static BitmapSource ToBitmapSource(this System.Drawing.Image source)
        {
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(source);

            var bitSrc = bitmap.ToBitmapSource();

            bitmap.Dispose();
            bitmap = null;

            return(bitSrc);
        }
コード例 #7
0
        public static ImageSource ToImageSource(this System.Windows.Forms.Cursor cursor)
        {
            int width  = cursor.Size.Width;
            int height = cursor.Size.Height;

            using (System.Drawing.Bitmap b = new System.Drawing.Bitmap(width, height)) {
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b)) {
                    cursor.Draw(g, new System.Drawing.Rectangle(0, 0, width, height));
                    return(b.ToBitmapSource());
                }
            }
        }
コード例 #8
0
ファイル: ScreenCapture.cs プロジェクト: Henrycobaltech/SnipX
 public static ImageSource TakeFullScreenShot()
 {
     var screenWidth = (int)SystemParameters.PrimaryScreenWidth;
     var screenHeight = (int)SystemParameters.PrimaryScreenHeight;
     using (var img = new Bitmap(screenWidth, screenHeight))
     {
         using (var g = Graphics.FromImage(img))
         {
             g.CopyFromScreen(
                 new System.Drawing.Point(0, 0),
                 new System.Drawing.Point(0, 0),
                 new System.Drawing.Size(screenWidth, screenHeight)
                 );
         }
         return img.ToBitmapSource();
     }
 }
コード例 #9
0
    public async void loadHash(string path)
    {
      center.Visibility = System.Windows.Visibility.Collapsed;
      await Task.Delay(1);
      
		  var mp3 = new ToyMP3(path);
      
		  var frame   = new ToyTools.ToyMP3Frame();
		  var decoder = new ToyTools.ToyMP3Decoder();

      var list = new List<short>();

      loading.Content = "Parseing...";
      await Task.Delay(1);

		  try
      {
			  while (mp3.SeekMP3Frame(frame))
			  {
				  decoder.DecodeFrame(frame);
          list.AddRange(decoder.Pcm);
			  }
      }
      catch (Exception) { }

      wave = PickFloat(list.ToArray()).ToArray();
      var bmp = new Bitmap((int)Math.Ceiling((double)wave.Length / 100), 100);

      loading.Content = "Drawing...";
      await Task.Delay(1);

      AudioVisualizationService.DrawWave(wave, bmp);
      image.Source = bmp.ToBitmapSource();

      loading.Visibility = System.Windows.Visibility.Collapsed;
      center.Visibility = System.Windows.Visibility.Visible;

      return;
    }
コード例 #10
0
    public async void ShowNotesData(double offset, string source)
    {
      if (wave == null) return;

      var bmp = new Bitmap((int)Math.Ceiling((double)wave.Length / 100), 100);
      await Task.Delay(1);

      var data = Maidata.ParseData(offset, source);
      AudioVisualizationService.DrawNotes(data, 30.0, bmp);
      norts.Source = bmp.ToBitmapSource();
    }   
コード例 #11
0
 public static Image CreateImage(Bitmap source)
 {
     var result = new Image { Source = source.ToBitmapSource() };
     result.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);
     return result;
 }
コード例 #12
0
        /// <summary>
        /// Update
        /// </summary>
        public void Update()
        {
            if (!_startProcessing) return;

            Stopwatch stopwatchAll = Stopwatch.StartNew();
            Stopwatch stopwatch = new Stopwatch();
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(_clooImageByteOriginal.Width, _clooImageByteOriginal.Height, PixelFormat.Format24bppRgb);

            // normalize
            lock (_queue)
            {
                stopwatch.Reset();
                stopwatch.Start();
                lock (_queue)
                {
                    _kernels.ByteToFloat(_queue, _clooImageByteOriginal, _clooImageFloatTemp1);
                    _kernels.Normalize(_queue, _clooImageFloatTemp1, _clooImageFloatOriginal);
                    _queue.Finish();
                    label2.Content = stopwatch.ElapsedMilliseconds + " ms - normalize";
                    _clooImageFloatOriginal.ToBitmap(_queue, bitmap);
                }
                image2.Source = bitmap.ToBitmapSource();
            }

            // blur
            {
                stopwatch.Reset();
                stopwatch.Start();

                lock (_queue)
                {
                    _kernels.BoxBlur(_queue, _clooImageFloatOriginal, _clooImageFloatTemp2, _sampler, 1);
                    _kernels.FloatToByte(_queue, _clooImageFloatTemp2, _clooImageByteResult);
                    _queue.Finish();
                    label3.Content = stopwatch.ElapsedMilliseconds + " ms - box blur";
                    _clooImageByteResult.ToBitmap(_queue, bitmap);
                }
                image3.Source = bitmap.ToBitmapSource();
            }

            // grayscale
            {
                stopwatch.Reset();
                stopwatch.Start();
                lock (_queue)
                {
                    _kernels.GrayScale(_queue, _clooImageByteOriginal, _clooImageFloatGrayOriginal);
                    _queue.Finish();
                    label4.Content = stopwatch.ElapsedMilliseconds + " ms - grayscale";
                    image4.Source = _clooImageFloatGrayOriginal.ToBitmap(_queue).ToBitmapSource();
                }
            }

            // histogram 256
            {
                lock (_queue)
                {
                    stopwatch.Reset();
                    stopwatch.Start();
                    _kernels.FloatToByte(_queue, _clooImageFloatGrayOriginal, _clooImageByteResultA);
                    _kernels.Histogram256(_queue, _clooImageByteResultA, _histogram);
                    _queue.Finish();
                    label5.Content = stopwatch.ElapsedMilliseconds + " ms - histogram";
                    _histogram.ReadFromDevice(_queue);
                }
                image5.Source = _histogram.HostBuffer.HistogramBufferToBitmap(256, 0, 128, 0, 0, 256).ToBitmapSource();
            }

            // sobel
            {
                stopwatch.Reset();
                stopwatch.Start();
                lock (_queue)
                {
                    _kernels.Sobel(_queue, _clooImageFloatGrayOriginal, _clooImageFloatATemp1, _sampler);
                    _kernels.FloatToByte(_queue, _clooImageFloatATemp1, _clooImageByteResultA);
                    _queue.Finish();
                    label6.Content = stopwatch.ElapsedMilliseconds + " ms - sobel";
                    image6.Source = _clooImageByteResultA.ToBitmap(_queue).ToBitmapSource();
                }
            }

            //// integral image
            //{
            //    stopwatch.Reset();
            //    stopwatch.Start();
            //    lock (_queue)
            //    {
            //        _kernels.Integral(_queue, _clooImageFloatGrayOriginal, _clooImageFloatIntegral);
            //        _queue.Finish();
            //        label7.Content = stopwatch.ElapsedMilliseconds + " ms - integral image";
            //        _clooImageFloatIntegral.ReadFromDevice(_queue);
            //        float maxValue = _clooImageFloatIntegral.HostBuffer.GetMaxValue();
            //        _kernels.MultiplyValue(_queue, _clooImageFloatIntegral, 255 / maxValue);
            //        image7.Source = _clooImageFloatIntegral.ToBitmap(_queue).ToBitmapSource();
            //    }
            //}

            // histogram backprojection
            {
                stopwatch.Reset();
                stopwatch.Start();
                lock (_queue)
                {
                    Rectangle rectSource = new Rectangle(0, 0, 100, 120);
                    Rectangle rectFrame = new Rectangle(0, 0, 640, 480);

                    _kernels.HistogramN(_queue, _clooImageByteOriginal, _histogram, 6, rectSource.Left, rectSource.Top, rectSource.Width, rectSource.Height);
                    _kernels.HistogramN(_queue, _clooImageByteOriginal, _histogram2, 6, rectFrame.Left, rectFrame.Top, rectFrame.Width, rectFrame.Height);
                    _kernels.HistogramBackprojection(_queue, _clooImageByteOriginal, _clooImageFloatATemp1, _histogram, _histogram2, 4);
                    _queue.Finish();
                    _clooImageFloatATemp1.ReadFromDevice(_queue);
                    float maxValue = _clooImageFloatATemp1.HostBuffer.Max();
                    _kernels.MultiplyValue(_queue, _clooImageFloatATemp1, 1 / maxValue);
                    label7.Content = stopwatch.ElapsedMilliseconds + " ms - histogram backprojection";
                    image7.Source = _clooImageFloatATemp1.ToBitmap(_queue).ToBitmapSource();
                }
            }

            // Viola & Jones
            {
                stopwatch.Reset();
                stopwatch.Start();
                lock (_queue)
                {
                    _kernels.Integral(_queue, _clooImageByteGrayOriginal, _clooImageUIntIntegral);
                    _kernels.IntegralSquare(_queue, _clooImageByteGrayOriginal, _clooImageUIntIntegralSquare);
                    _haarObjectDetector.IntegralImage = _clooImageUIntIntegral;
                    _haarObjectDetector.Integral2Image = _clooImageUIntIntegralSquare;

                    long milliseconds = stopwatch.ElapsedMilliseconds;
                    int facesCount = _haarObjectDetector.ProcessFrame();
                    milliseconds = stopwatch.ElapsedMilliseconds;

                    Dispatcher.Invoke(new Action(() =>
                    {
                        using (var bmp = _clooImageFloatGrayOriginal.ToBitmap(_queue))
                        {
                            using (Graphics g = Graphics.FromImage(bmp))
                            {
                                using (Pen pen = new Pen(Color.Red, 3))
                                {
                                    for (int i = 0; i < facesCount; i++)
                                        g.DrawRectangle(pen, _haarObjectDetector.ResultRectangles.HostBuffer[i]);
                                }
                            }
                            image8.Source = bmp.ToBitmapSource();
                            label8.Content = stopwatch.ElapsedMilliseconds + " ms - Viola & Jones";
                        }
                    }));
                }
            }

            // total
            Title = _title + " - " + stopwatchAll.ElapsedMilliseconds + " ms";
        }
コード例 #13
0
ファイル: Methods.cs プロジェクト: kampiuceris/PsHandler
 public static void DisplayBitmap(Bitmap bitmap, bool dialog = false)
 {
     //UiInvoke(() =>
     //{
     System.Windows.Controls.Image image = new System.Windows.Controls.Image
     {
         Source = bitmap.ToBitmapSource(),
         Width = bitmap.Width,
         Height = bitmap.Height
     };
     Window window = new Window
     {
         SizeToContent = SizeToContent.WidthAndHeight,
         UseLayoutRounding = true,
         Content = image,
         ResizeMode = ResizeMode.NoResize,
         Background = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 255, 0))
     };
     if (dialog)
     {
         window.ShowDialog();
     }
     else
     {
         window.Show();
     }
     //});
 }
コード例 #14
0
        public void QuickPreviewStart()
        {
            if (_threadQuickPreview == null || !_quickPreviewIsRunning)
            {
                QuickPreviewStop();
                _quickPreviewIsRunning = true;

                _threadQuickPreview = new Thread(() =>
                {
                    try
                    {
                        IntPtr handle      = WinApi.GetForegroundWindow();
                        string windowTitle = WinApi.GetWindowTitle(handle);
                        string windowClass = WinApi.GetClassName(handle);

                        if (!(windowClass.Equals("PokerStarsTableFrameClass") && WinApi.IsWindowVisible(handle) &&
                              !Methods.IsMinimized(handle) && !string.IsNullOrEmpty(windowTitle)))
                        {
                            handle = IntPtr.Zero;
                        }

                        Methods.UiInvoke(() =>
                        {
                            _windowQuickPreview = new Window
                            {
                                Title             = "Quick Preview",
                                SizeToContent     = SizeToContent.WidthAndHeight,
                                Topmost           = true,
                                WindowStyle       = WindowStyle.None,
                                UseLayoutRounding = true,
                                ResizeMode        = ResizeMode.NoResize,
                                Background        = Brushes.Black,
                                Width             = 5,
                                Height            = 5,
                                ShowInTaskbar     = false,
                                Focusable         = false,
                                Visibility        = Visibility.Visible
                            };
                            _imageQuickPreview                     = new Image();
                            _windowQuickPreview.Content            = _imageQuickPreview;
                            _windowQuickPreview.SourceInitialized += (sender, args) =>
                            {
                                var interopHelper = new WindowInteropHelper(_windowQuickPreview);
                                int exStyle       = (int)WinApi.GetWindowLong(interopHelper.Handle, WinApi.GWL_EXSTYLE);
                                WinApi.SetWindowLong(interopHelper.Handle, WinApi.GWL_EXSTYLE, exStyle | WinApi.WS_EX_NOACTIVATE);
                            };
                            _windowQuickPreview.Show();
                        });

                        while (true)
                        {
                            if (handle != IntPtr.Zero)
                            {
                                System.Drawing.Bitmap bitmapWindowClient = ScreenCapture.GetBitmapWindowClient(handle);
                                if (bitmapWindowClient != null)
                                {
                                    Methods.UiInvoke(() =>
                                    {
                                        _imageQuickPreview.Width  = bitmapWindowClient.Width;
                                        _imageQuickPreview.Height = bitmapWindowClient.Height;
                                        _imageQuickPreview.Source = bitmapWindowClient.ToBitmapSource();
                                        System.Drawing.Rectangle clientRectangle = WinApi.GetClientRectangle(handle);
                                        _windowQuickPreview.Left = clientRectangle.Left;
                                        _windowQuickPreview.Top  = clientRectangle.Top;
                                    });
                                }
                            }

                            Thread.Sleep(25);
                        }
                    }
#if (DEBUG)
                    catch (ThreadInterruptedException)
                    {
                    }
#else
                    catch (Exception e)
                    {
                        if (!(e is ThreadInterruptedException))
                        {
                            Methods.DisplayException(e, App.WindowMain, WindowStartupLocation.CenterOwner);
                        }
                    }
#endif
                    finally
                    {
                        Methods.UiInvoke(() => { _windowQuickPreview.Close(); });
                        _quickPreviewIsRunning = false;
                    }
                });
                _threadQuickPreview.Start();
            }
        }
コード例 #15
0
ファイル: Converter.cs プロジェクト: seniorOtaka/ndoctor
        /// <summary>
        /// Converts a <see cref="System.Drawing.Image"/> into a WPF <see cref="BitmapSource"/>.
        /// </summary>
        /// <param name="source">The source image.</param>
        /// <returns>A BitmapSource</returns>
        public static BitmapSource ToBitmapSource(this Image source)
        {
            if (source == null) return null;

            using (Bitmap bitmap = new Bitmap(source))
            {
                return bitmap.ToBitmapSource();
            }
        }
コード例 #16
0
ファイル: Extensions.cs プロジェクト: fafaffy/3DS-Toolkit
        public static Bitmap Rgb565ToBmp(this byte[] bmpBytes, int w, int h)
        {
            var bmp = new Bitmap(w, h, PixelFormat.Format16bppRgb565);
            var bdata = bmp.LockBits(new Rectangle(new Point(), bmp.Size),
                System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format16bppRgb565);
            Marshal.Copy(bmpBytes, 0, bdata.Scan0, bmpBytes.Length - 1);
            bmp.UnlockBits(bdata);
            // ^ Scrambled bmp
            // Time to unscramble it
            Clipboard.SetImage(bmp.ToBitmapSource());
            return bmp;
            var newBmp = new Bitmap(w, h, PixelFormat.Format16bppRgb565);

            // Coordinates to keep track of where the new point is
            int newX = 0, newY = 0;
            // The icons are on a 8x8 region, so split them up by region
            for (int region = 0; region < (w/8)*(h/8); region++)
            {
                int offsetX = 0, offsetY = 0;

                // From 1 to 8... (4 x 2)
                for (var i = 0; i < 8; i++)
                {
                    var temp = region;
                    while (temp > 8)
                    {
                        temp -= 8;
                        offsetY += 16;
                    }

                    switch (i)
                    {
                        case 1:
                            offsetX += 8;
                            break;
                        case 2:
                            offsetY += 8;
                            break;
                        case 3:
                            offsetX += 8;
                            offsetY += 8;
                            break;
                        case 4:
                            offsetX += 16;
                            break;
                        case 5:
                            offsetX += 24;
                            break;
                        case 6:
                            offsetX += 16;
                            offsetY += 8;
                            break;
                        case 7:
                            offsetX += 24;
                            offsetY += 8;
                            break;
                    }

                    if (offsetX + 8 > w) continue;

                    if (newX == w)
                    {
                        newX = 0;
                        newY++;
                    }

                    for (int x = 0; x < 8; x++)
                    {
                        for (int y = 0; y < 8; y++)
                        {
                            try
                            {

                                newBmp.SetPixel(newX + x, newY + y,
                                    bmp.GetPixel(offsetX + x, offsetY + y));
                            }
                            catch
                            {
                                return newBmp;

                            }
                        }
                    }
                }
            }
            return newBmp;
        }
コード例 #17
0
ファイル: ImageExtensions.cs プロジェクト: strager/NoCap
 /// <summary>
 /// Converts a <see cref="System.Drawing.Image"/> into a WPF <see cref="BitmapSource"/>.
 /// </summary>
 /// <param name="source">The source image.</param>
 /// <returns>A BitmapSource</returns>
 public static BitmapSource ToBitmapSource(this Image source)
 {
     using (var bitmap = new Bitmap(source)) {
         return bitmap.ToBitmapSource();
     }
 }
コード例 #18
0
ファイル: MaskWindow.cs プロジェクト: wangws556/duoduo-chat
        internal BitmapSource CopyFromScreenSnapshot(Rect region)
        {
            var sourceRect = region.ToRectangle();
            var destRect = new Rectangle(0, 0, sourceRect.Width, sourceRect.Height);

            if (screenSnapshot != null)
            {
                var bitmap = new Bitmap(sourceRect.Width, sourceRect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    g.DrawImage(screenSnapshot, destRect, sourceRect, GraphicsUnit.Pixel);
                }

                return bitmap.ToBitmapSource();
            }

            return null;
        }
コード例 #19
0
 /// <summary>
 /// Browse for different image
 /// </summary>
 /// <param name="sender">sender</param>
 /// <param name="e">event details</param>
 private void buttonBrowse_Click(object sender, RoutedEventArgs e)
 {
     OpenFileDialog openFileDialog = new OpenFileDialog();
     openFileDialog.Filter = "All Files (*.*)|*.*";
     if (openFileDialog.ShowDialog() == true)
     {
         _bitmapImage1 = new System.Drawing.Bitmap(openFileDialog.FileName);
         image1.Source = _bitmapImage1.ToBitmapSource();
         initializeDevice();
     }
 }
コード例 #20
0
ファイル: BitmapExtensions.cs プロジェクト: interopxyz/Macaw
 public static Si.WriteableBitmap ToWriteableBitmap(this Sd.Bitmap input)
 {
     return(new Si.WriteableBitmap(input.ToBitmapSource()));
 }