JSN ImageShow - Joomla 1.5 extension (component, module) by JoomlaShine.com
Home arrow Blog arrow WPF: System.Drawing.Bitmap to BitmapSource (and viceversa)
WPF: System.Drawing.Bitmap to BitmapSource (and viceversa) Stampa E-mail
Scritto da Gene   
sabato 07 marzo 2009

Here is a code snipplet containing two useful functions that let you convert bitmap images from System.Drawing.Bitmap to System.Windows.Media.Imaging.BitmapSource.

Open this item to view the source code. (by clicking on "Leggi Tutto..." link) =)

private System.Drawing.Bitmap _bitmapFromSource(BitmapSource bitmapsource)
{
	System.Drawing.Bitmap bitmap;
	using (MemoryStream outStream = new MemoryStream())
	{
		// from System.Media.BitmapImage to System.Drawing.Bitmap
		BitmapEncoder enc = new BmpBitmapEncoder();
		enc.Frames.Add(BitmapFrame.Create(bitmapsource));
		enc.Save(outStream);
		bitmap = new System.Drawing.Bitmap(outStream);
	}
	return bitmap;
}

private BitmapSource _bitmapToSource(System.Drawing.Bitmap bitmap)
{
	BitmapSource destination;
	IntPtr hBitmap = bitmap.GetHbitmap();
	BitmapSizeOptions sizeOptions = BitmapSizeOptions.FromEmptyOptions();
	destination = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, sizeOptions);
	destination.Freeze();
	return destination;
}
Commenti
Nuovo Cerca RSS
Timmy   |91.202.44.xxx |2010-03-04 15:39:29
???????? ?????????? ?????????
Commenta
Nome:
Email:
 
Website:
Titolo:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Ultimo aggiornamento ( sabato 07 marzo 2009 )
 
< Prec.   Pros. >
Free Joomla Templates