本文整理汇总了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;
}
示例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;
}
}
示例3: ToBitmapSource
public static BitmapSource ToBitmapSource(this Image source)
{
var bitmap = new Bitmap(source);
var bitSrc = bitmap.ToBitmapSource();
bitmap.Dispose();
return bitSrc;
}
示例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;
}
示例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();
}
}
}
示例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();
}
}
示例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;
}
示例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();
}
}
示例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();
// }
//}
//.........这里部分代码省略.........
示例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();
}
}
示例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();
}
示例12: CreateImage
public static Image CreateImage(Bitmap source)
{
var result = new Image { Source = source.ToBitmapSource() };
result.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);
return result;
}
示例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;
}
示例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;
}
示例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();
}
//});
}