当前位置: 首页>>代码示例>>C#>>正文


C# Bitmap.ToBitmapSource方法代码示例

本文整理汇总了C#中System.Drawing.Bitmap.ToBitmapSource方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.ToBitmapSource方法的具体用法?C# Bitmap.ToBitmapSource怎么用?C# Bitmap.ToBitmapSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Bitmap的用法示例。


在下文中一共展示了Bitmap.ToBitmapSource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Ini

        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;

        }
开发者ID:wangws556,项目名称:duoduo-chat,代码行数:33,代码来源:MaskWindow.cs

示例2: ToBitmapSource

 /// <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;
     }
 }
开发者ID:archrival,项目名称:UltraSonic,代码行数:13,代码来源:ImageConverter.cs

示例3: ToBitmapSource

        public static BitmapSource ToBitmapSource(this Image source)
        {
            var bitmap = new Bitmap(source);

            var bitSrc = bitmap.ToBitmapSource();

            bitmap.Dispose();

            return bitSrc;
        }
开发者ID:robertiagar,项目名称:Windows-10-Login-Background-Changer,代码行数:10,代码来源:Extenstions.cs

示例4: ToBitmapSource

        /// <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;
        }
开发者ID:pvishal,项目名称:kinpos,代码行数:16,代码来源:ImageHelpers.cs

示例5: ToImageSource

		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();
				}
			}
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:11,代码来源:BitmapExtensions.cs

示例6: TakeFullScreenShot

 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();
     }
 }
开发者ID:Henrycobaltech,项目名称:SnipX,代码行数:17,代码来源:ScreenCapture.cs

示例7: loadHash

    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;
    }
开发者ID:youaoi,项目名称:simaiAssistant,代码行数:39,代码来源:SoundWave.xaml.cs

示例8: buttonBrowse_Click

 /// <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();
     }
 }
开发者ID:JacindaChen,项目名称:TronCell,代码行数:16,代码来源:MainWindow.xaml.cs

示例9: Update

        /// <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();
            //    }
            //}
//.........这里部分代码省略.........
开发者ID:JacindaChen,项目名称:TronCell,代码行数:101,代码来源:MainWindow.xaml.cs

示例10: ToBitmapSource

 /// <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();
     }
 }
开发者ID:strager,项目名称:NoCap,代码行数:11,代码来源:ImageExtensions.cs

示例11: ShowNotesData

    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();
    }   
开发者ID:youaoi,项目名称:simaiAssistant,代码行数:11,代码来源:SoundWave.xaml.cs

示例12: CreateImage

 public static Image CreateImage(Bitmap source)
 {
     var result = new Image { Source = source.ToBitmapSource() };
     result.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);
     return result;
 }
开发者ID:mikel785,项目名称:MetaActionFramework,代码行数:6,代码来源:ImageHelper.cs

示例13: CopyFromScreenSnapshot

        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;
        }
开发者ID:wangws556,项目名称:duoduo-chat,代码行数:18,代码来源:MaskWindow.cs

示例14: Rgb565ToBmp

        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;
        }
开发者ID:fafaffy,项目名称:3DS-Toolkit,代码行数:87,代码来源:Extensions.cs

示例15: DisplayBitmap

 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();
     }
     //});
 }
开发者ID:kampiuceris,项目名称:PsHandler,代码行数:28,代码来源:Methods.cs


注:本文中的System.Drawing.Bitmap.ToBitmapSource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。