本文整理汇总了C#中System.GetHbitmap方法的典型用法代码示例。如果您正苦于以下问题:C# System.GetHbitmap方法的具体用法?C# System.GetHbitmap怎么用?C# System.GetHbitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.GetHbitmap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadBitmap
public static BitmapSource LoadBitmap(System.Drawing.Bitmap source)
{
handle = source.GetHbitmap();
bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
DeleteObject(handle);
return bitmapSource;
}
示例2: LoadBitmap
public static BitmapSource LoadBitmap(System.Drawing.Bitmap source)
{
var ip = source.GetHbitmap();
var bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(ip, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
DeleteObject(ip);
return bs;
}
示例3: Bitmap2BitmapImage
public static BitmapImage Bitmap2BitmapImage(System.Drawing.Bitmap bitmap)
{
IntPtr hBitmap = bitmap.GetHbitmap();
BitmapSource bmpSource;
BitmapImage bitmapImage = new BitmapImage();
try
{
bmpSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
hBitmap,
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
BitmapEncoder enc = new BmpBitmapEncoder();
MemoryStream memoryStream = new MemoryStream();
enc.Frames.Add(BitmapFrame.Create(bmpSource));
enc.Save(memoryStream);
memoryStream.Position = 0;
bitmapImage.BeginInit();
bitmapImage.StreamSource = memoryStream;
bitmapImage.EndInit();
}
finally
{
DeleteObject(hBitmap);
}
return bitmapImage;
}
示例4: loadBitmap
public static BitmapSource loadBitmap(System.Drawing.Bitmap source)
{
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(source.GetHbitmap(), IntPtr.Zero,
Int32Rect.Empty,
System.Windows.Media.Imaging
.BitmapSizeOptions
.FromEmptyOptions());
}
示例5: ConvertGDI_To_WPF
/// <summary>
/// Convert GDI bitmap into a WPF BitmapSource
/// </summary>
/// <param name="source"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <returns></returns>
public static BitmapSource ConvertGDI_To_WPF(System.Drawing.Bitmap bmp)
{
BitmapSource bms = null;
if (bmp != null)
{
IntPtr h_bm = bmp.GetHbitmap();
bms = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(h_bm, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
}
return bms;
}
示例6: ToImageSource
public static ImageSource ToImageSource(System.Drawing.Bitmap bitmap) {
var hbitmap = bitmap.GetHbitmap();
try {
var imageSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromWidthAndHeight(bitmap.Width, bitmap.Height));
return imageSource;
} finally {
DeleteObject(hbitmap);
}
}
示例7: BitmapToBitmapSource
public static BitmapSource BitmapToBitmapSource(System.Drawing.Bitmap bitmap)
{
intPointer = bitmap.GetHbitmap();
bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(intPointer,
IntPtr.Zero,
System.Windows.Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
DeleteObject(intPointer);
return bitmapSource;
}
示例8: ToBitmapSource
private static BitmapSource ToBitmapSource(System.Drawing.Bitmap source)
{
BitmapSource bitSrc = null;
var hBitmap = source.GetHbitmap();
bitSrc = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
hBitmap,
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
return bitSrc;
}
示例9: convertBitmapToBitmapSource
public static ImageSource convertBitmapToBitmapSource(System.Drawing.Bitmap bitmap)
{
using (bitmap)
{
System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
bitmap.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
return bitmapSource;
}
}
示例10: SetImageSource
private void SetImageSource(System.Drawing.Bitmap bmp)
{
if (bmp == null)
return;
// how to convert a bitmap to an imagesource http://blog.laranjee.com/how-to-convert-winforms-bitmap-to-wpf-imagesource/
// TODO - watch out for memory leaks using system.drawing.bitmaps in managed code, see here http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/4e213af5-d546-4cc1-a8f0-462720e5fcde
// need to call Dispose manually somewhere, or perhaps use a WPF native structure instead of bitmap?
var hbitmap = bmp.GetHbitmap();
var imageSource = Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(bmp.Width, bmp.Height));
image.Source = imageSource;
}
示例11: BitmapToImageSource
/// <summary>
/// 从Bitmap创建可供WPF Image控件使用的BitmapSource对象
/// </summary>
/// <param name="bitmap"></param>
/// <returns></returns>
public static BitmapSource BitmapToImageSource(System.Drawing.Bitmap bitmap)
{
BitmapSource destination;
IntPtr hBitmap = bitmap.GetHbitmap();
BitmapSizeOptions sizeOptions = BitmapSizeOptions.FromEmptyOptions();
destination = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, System.Windows.Int32Rect.Empty, sizeOptions);
destination.Freeze();
return destination;
}
示例12: CamProc_NewTargetPosition
void CamProc_NewTargetPosition(IntPoint Center, System.Drawing.Bitmap image)
{
IntPtr hBitMap = image.GetHbitmap();
BitmapSource bmaps = Imaging.CreateBitmapSourceFromHBitmap(hBitMap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
bmaps.Freeze();
Dispatcher.Invoke((Action)(() =>
{
if (Center.X > 0)
{
try
{
prova.Content = String.Format(" Codigo: {0}", Center.X);
item.Content = String.Format(" Nº Itens: {0}", Center.Y);
TextReader respostas = new StreamReader(@"" + Center.X + ".txt");
string R_1 = respostas.ReadLine();
string R_2 = respostas.ReadLine();
string R_3 = respostas.ReadLine();
string R_4 = respostas.ReadLine();
string R_5 = respostas.ReadLine();
string R_6 = respostas.ReadLine();
string R_7 = respostas.ReadLine();
string R_8 = respostas.ReadLine();
string R_9 = respostas.ReadLine();
string R_0 = respostas.ReadLine();
item1.Content = String.Format(" Item 01: {0}", R_1);
item2.Content = String.Format(" Item 02: {0}", R_2);
item3.Content = String.Format(" Item 03: {0}", R_3);
item4.Content = String.Format(" Item 04: {0}", R_4);
item5.Content = String.Format(" Item 05: {0}", R_5);
item6.Content = String.Format(" Item 06: {0}", R_6);
item7.Content = String.Format(" Item 07: {0}", R_7);
item8.Content = String.Format(" Item 08: {0}", R_8);
item9.Content = String.Format(" Item 09: {0}", R_9);
item10.Content = String.Format(" Item 10: {0}", R_0);
string resps = R_1 + ";" + R_2 + ";" + R_3 + ";" + R_4 + ";" + R_5 + ";" + R_6 + ";" + R_7 + ";" + R_8 + ";" + R_9 + ";" + R_0;
refer.Content = String.Format("todas: {0}", resps);
conexao((int)Center.X, resps);
respostas.Close();
}
catch { }
}
pictureBoxMain.Source = bmaps;
}), DispatcherPriority.Render, null);
DeleteObject(hBitMap);
}
示例13: loadBitmap
public static BitmapSource loadBitmap(System.Drawing.Bitmap source)
{
IntPtr ip = source.GetHbitmap();
BitmapSource bs = null;
try
{
bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(ip,
IntPtr.Zero, Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
}
finally
{
DeleteObject(ip);
}
return bs;
}
示例14: ToWPFBitmap
public static BitmapSource ToWPFBitmap(System.Drawing.Bitmap bitmap)
{
var hBitmap = bitmap.GetHbitmap();
BitmapSource source;
try
{
source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
hBitmap, IntPtr.Zero, Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
}
finally
{
DeleteObject(hBitmap);
}
return source;
}
示例15: TileSet
public TileSet(System.Drawing.Bitmap source, int tileWidth, int tileHeight)
{
_source = new WriteableBitmap(Imaging.CreateBitmapSourceFromHBitmap(
source.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty,
BitmapSizeOptions.FromWidthAndHeight(source.Width, source.Height)));
TileWidth = tileWidth;
TileHeight = tileHeight;
_tilesPerRow = (int)_source.Width / TileWidth;
_bytesPerPixel = _source.Format.BitsPerPixel / BITS_PER_BYTE;
_stride = _source.PixelWidth * _bytesPerPixel;
_originalPixels = new byte[_stride * _source.PixelHeight];
_source.CopyPixels(_originalPixels, _stride, 0);
_tiles = new List<CroppedBitmap>();
GenerateTiles();
}