本文整理汇总了C#中System.Windows.Media.Imaging.FormatConvertedBitmap.BeginInit方法的典型用法代码示例。如果您正苦于以下问题:C# FormatConvertedBitmap.BeginInit方法的具体用法?C# FormatConvertedBitmap.BeginInit怎么用?C# FormatConvertedBitmap.BeginInit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.FormatConvertedBitmap
的用法示例。
在下文中一共展示了FormatConvertedBitmap.BeginInit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: setPixelFormat2
public static System.Drawing.Bitmap setPixelFormat2(BitmapSource bitmapsource, System.Drawing.Imaging.PixelFormat format)
{
//convert image format
var src = new System.Windows.Media.Imaging.FormatConvertedBitmap();
src.BeginInit();
src.Source = bitmapsource;
if (format == System.Drawing.Imaging.PixelFormat.Format1bppIndexed)
{
src.DestinationFormat = System.Windows.Media.PixelFormats.BlackWhite;
}
if (format == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
{
src.DestinationFormat = System.Windows.Media.PixelFormats.Gray8;
}
if (format == System.Drawing.Imaging.PixelFormat.Format24bppRgb)
{
src.DestinationFormat = System.Windows.Media.PixelFormats.Bgr24;
}
if (format == System.Drawing.Imaging.PixelFormat.Format32bppRgb)
{
src.DestinationFormat = System.Windows.Media.PixelFormats.Bgr32;
}
src.EndInit();
//copy to bitmap
Bitmap bitmap = new Bitmap(src.PixelWidth, src.PixelHeight, format);
var data = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, format);
src.CopyPixels(System.Windows.Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
bitmap.UnlockBits(data);
return bitmap;
}
示例2: ReduceColorDepth
public MemoryStream ReduceColorDepth(Bitmap bmp)
{
var ms = new MemoryStream();
bmp.Save(ms, ImageFormat.Png);
var bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = ms;
bi.EndInit();
var newFormatedBitmapSource = new FormatConvertedBitmap();
newFormatedBitmapSource.BeginInit();
newFormatedBitmapSource.Source = bi;
var myPalette = new BitmapPalette(bi, 256);
newFormatedBitmapSource.DestinationPalette = myPalette;
//Set PixelFormats
newFormatedBitmapSource.DestinationFormat = PixelFormats.Indexed8;
newFormatedBitmapSource.EndInit();
var pngBitmapEncoder = new PngBitmapEncoder();
pngBitmapEncoder.Interlace = PngInterlaceOption.Off;
pngBitmapEncoder.Frames.Add(BitmapFrame.Create(newFormatedBitmapSource));
var memstream = new MemoryStream();
pngBitmapEncoder.Save(memstream);
memstream.Position = 0;
return memstream;
}
示例3: ConvertToOtherPixelFormat
public static BitmapImage ConvertToOtherPixelFormat(BitmapSource source, PixelFormat format)
{
var newFormatedBitmapSource = new FormatConvertedBitmap();
newFormatedBitmapSource.BeginInit();
newFormatedBitmapSource.Source = source;
newFormatedBitmapSource.DestinationFormat = format;
newFormatedBitmapSource.EndInit();
return BitmapSourceToBitmapImage(newFormatedBitmapSource.Source);
}
示例4: GetFormatConvertedBitmap
public static FormatConvertedBitmap GetFormatConvertedBitmap(SWM.PixelFormat pf, BitmapSource bs)
{
FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
newFormatedBitmapSource.BeginInit();
newFormatedBitmapSource.Source = bs;
newFormatedBitmapSource.DestinationFormat = pf;
newFormatedBitmapSource.EndInit();
return newFormatedBitmapSource;
}
示例5: BitmapToFormat
/// <summary>
/// Convert bmpSource to format declared in pixFormat.
/// </summary>
/// <param name="bmpSource"></param>
/// <param name="pixFormat"></param>
/// <returns></returns>
public static FormatConvertedBitmap BitmapToFormat(BitmapSource bmpSource,
PixelFormat pixFormat)
{
if (bmpSource == null) { return null; }
FormatConvertedBitmap fcb = new FormatConvertedBitmap();
fcb.BeginInit();
fcb.Source = bmpSource;
fcb.DestinationFormat = pixFormat;
fcb.EndInit();
return fcb;
}
示例6: ShowMyFace
public ShowMyFace()
{
Title = "Show My Face";
///******************************************************************
// 3���� ShowMyFace ����
//******************************************************************/
Uri uri = new Uri("http://www.charlespetzold.com/PetzoldTattoo.jpg");
//BitmapImage bitmap = new BitmapImage(uri);
//Image img = new Image();
//img.Source = bitmap;
//Content = img;
///******************************************************************
// p1245 BitmapImage �ڵ�
//******************************************************************/
Image rotated90 = new Image();
TransformedBitmap tb = new TransformedBitmap();
FormatConvertedBitmap fb = new FormatConvertedBitmap();
CroppedBitmap cb = new CroppedBitmap();
// Create the source to use as the tb source.
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = uri;
bi.EndInit();
//cb.BeginInit();
//cb.Source = bi;
//Int32Rect rect = new Int32Rect();
//rect.X = 220;
//rect.Y = 200;
//rect.Width = 120;
//rect.Height = 80;
//cb.SourceRect = rect;
//cb.EndInit();
fb.BeginInit();
fb.Source = bi;
fb.DestinationFormat = PixelFormats.Gray2;
fb.EndInit();
// Properties must be set between BeginInit and EndInit calls.
tb.BeginInit();
tb.Source = fb;
// Set image rotation.
tb.Transform = new RotateTransform(90);
tb.EndInit();
// Set the Image source.
rotated90.Source = tb;
Content = rotated90;
}
示例7: SetGrayscale
private static void SetGrayscale(System.Windows.Controls.Image img)
{
img.IsEnabled = false;
FormatConvertedBitmap bitmap = new FormatConvertedBitmap();
bitmap.BeginInit();
bitmap.Source = (BitmapSource)img.Source;
bitmap.DestinationFormat = PixelFormats.Gray32Float;
bitmap.EndInit();
img.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new Action(() => { img.Source = bitmap; }));
}
示例8: BmpSource2Img
public static System.Drawing.Bitmap BmpSource2Img(BitmapSource bmpsource)
{
//convert image format
var src = new System.Windows.Media.Imaging.FormatConvertedBitmap();
src.BeginInit();
src.Source = bmpsource;
src.EndInit();
//copy to bitmap
Bitmap bitmap = new Bitmap(src.PixelWidth, src.PixelHeight, System.Drawing.Imaging.PixelFormat.DontCare);
var data = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.DontCare);
src.CopyPixels(System.Windows.Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
bitmap.UnlockBits(data);
return bitmap;
}
示例9: BitmapSourceToBitmap
/// <summary>
/// Extension method
/// </summary>
/// <param name="bitmapsource"></param>
/// <returns></returns>
public static Bitmap BitmapSourceToBitmap(this BitmapSource bitmapsource) {
//convert image format
FormatConvertedBitmap src = new FormatConvertedBitmap();
src.BeginInit();
src.Source = bitmapsource;
src.DestinationFormat = System.Windows.Media.PixelFormats.Bgra32;
src.EndInit();
//copy to bitmap
Bitmap bitmap = new Bitmap(src.PixelWidth, src.PixelHeight, PixelFormat.Format32bppArgb);
BitmapData data = bitmap.LockBits(new Rectangle(System.Drawing.Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
src.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height*data.Stride, data.Stride);
bitmap.UnlockBits(data);
return bitmap;
}
示例10: BtnCon_Click
private void BtnCon_Click(object sender, RoutedEventArgs e)
{
BitmapImage myBitmapImage = new BitmapImage();
// BitmapSource objects like BitmapImage can only have their properties// changed within a BeginInit/EndInit block.
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri("pack://application:,,,/Images/xiaoxiong.jpg");
//myBitmapImage.DecodePixelWidth = 200;
myBitmapImage.EndInit();
FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
newFormatedBitmapSource.BeginInit();
newFormatedBitmapSource.Source = myBitmapImage;
// Set the new format to Gray32Float (grayscale).
newFormatedBitmapSource.DestinationFormat = PixelFormats.Gray32Float;
newFormatedBitmapSource.EndInit();
img2.Source = newFormatedBitmapSource;
}
示例11: ConvertToBgr32Format
public static FormatConvertedBitmap ConvertToBgr32Format(BitmapSource source)
{
// Convert to Pbgra32 if it's a different format
//if (source.Format == PixelFormats.Bgr32) {
// return new WriteableBitmap(source);
//}
var formattedBitmapSource = new FormatConvertedBitmap();
formattedBitmapSource.BeginInit();
formattedBitmapSource.Source = source;
formattedBitmapSource.DestinationFormat = PixelFormats.Bgr32;
formattedBitmapSource.EndInit();
//formattedBitmapSource.CopyPixels();
return formattedBitmapSource;
//WriteableBitmap wb = new WriteableBitmap(formatedBitmapSource);
////delete
//formatedBitmapSource = null;
//GC.Collect();
//return wb;
}
示例12: Convert
private static ImageSource Convert(BitmapSource input, PixelFormat format)
{
////////// Convert the BitmapSource to a new format ////////////
// Use the BitmapImage created above as the source for a new BitmapSource object
// which is set to a gray scale format using the FormatConvertedBitmap BitmapSource.
// Note: New BitmapSource does not cache. It is always pulled when required.
FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
// BitmapSource objects like FormatConvertedBitmap can only have their properties
// changed within a BeginInit/EndInit block.
newFormatedBitmapSource.BeginInit();
// Use the BitmapSource object defined above as the source for this new
// BitmapSource (chain the BitmapSource objects together).
newFormatedBitmapSource.Source = input;
// Set the new format to Gray32Float (grayscale).
newFormatedBitmapSource.DestinationFormat = format;
newFormatedBitmapSource.EndInit();
return newFormatedBitmapSource;
}
示例13: Dither
public static BitmapSource Dither(BitmapSource source, ColorFormat format)
{
if(source.Format == PixelFormats.Indexed8)
{
var rgb = new FormatConvertedBitmap();
rgb.BeginInit();
rgb.Source = source;
rgb.DestinationFormat = PixelFormats.Rgb24;
rgb.EndInit();
source = rgb;
}
var dest = new FormatConvertedBitmap();
dest.BeginInit();
dest.Source = source;
var numColors = (int)Math.Pow(2, (int) format);
var colors = ColorList.Take(numColors).ToList();
dest.DestinationPalette = new BitmapPalette(colors);
dest.DestinationFormat = PixelFormats.Indexed8;
dest.EndInit();
return dest;
}
示例14: LoadImages
private static void LoadImages(SQLiteConnection connection)
{
SQLiteCommand command;
SQLiteDataReader reader;
DataTable table;
// Load Ball Caught Images
command = new SQLiteCommand("SELECT * FROM BallImages", connection);
reader = command.ExecuteReader();
table = new DataTable("BallImages");
table.Load(reader);
foreach (DataRow row in table.Rows) {
byte id = (byte)(long)row["ID"];
BitmapImage image = LoadImage((byte[])row["Image"]);
ballCaughtImages.Add(id, image);
}
// Load Pokemon Images
command = new SQLiteCommand("SELECT * FROM PokemonImages", connection);
reader = command.ExecuteReader();
table = new DataTable("PokemonImages");
table.Load(reader);
foreach (DataRow row in table.Rows) {
ushort id = (ushort)(long)row["DexID"];
Gen3PokemonImageTypes pokemonImageTypes = new Gen3PokemonImageTypes();
pokemonImageTypes.Image = LoadImage(row["Image"] as byte[]);
pokemonImageTypes.ShinyImage = LoadImage(row["ShinyImage"] as byte[]);
pokemonImageTypes.FRLGImage = LoadImage(row["FRLGImage"] as byte[]);
pokemonImageTypes.FRLGShinyImage = LoadImage(row["FRLGShinyImage"] as byte[]);
pokemonImageTypes.BoxImage = LoadImage(row["BoxImage"] as byte[]);
pokemonImageTypes.NewBoxImage = LoadImage(row["NewBoxImage"] as byte[]);
pokemonImageTypes.NewBoxShinyImage = LoadImage(row["NewBoxShinyImage"] as byte[]);
gen3PokemonImages.Add(id, pokemonImageTypes);
if (id == 327) {
writeableSpindaNormal = new FormatConvertedBitmap();
writeableSpindaNormal.BeginInit();
writeableSpindaNormal.Source = pokemonImageTypes.Image;
writeableSpindaNormal.DestinationFormat = PixelFormats.Bgra32;
writeableSpindaNormal.EndInit();
writeableSpindaShiny = new FormatConvertedBitmap();
writeableSpindaShiny.BeginInit();
writeableSpindaShiny.Source = pokemonImageTypes.ShinyImage;
writeableSpindaShiny.DestinationFormat = PixelFormats.Bgra32;
writeableSpindaShiny.EndInit();
}
}
// Load Unown Form Images
command = new SQLiteCommand("SELECT * FROM UnownFormImages", connection);
reader = command.ExecuteReader();
table = new DataTable("UnownFormImages");
table.Load(reader);
foreach (DataRow row in table.Rows) {
byte id = (byte)(long)row["ID"];
DexFormID dexFormID = new DexFormID { DexID = 201, FormID = id };
Gen3PokemonImageTypes pokemonImageTypes = new Gen3PokemonImageTypes();
pokemonImageTypes.Image = LoadImage(row["Image"] as byte[]);
pokemonImageTypes.ShinyImage = LoadImage(row["ShinyImage"] as byte[]);
pokemonImageTypes.BoxImage = LoadImage(row["BoxImage"] as byte[]);
pokemonImageTypes.NewBoxImage = LoadImage(row["NewBoxImage"] as byte[]);
pokemonImageTypes.NewBoxShinyImage = LoadImage(row["NewBoxShinyImage"] as byte[]);
gen3PokemonFormImages.Add(dexFormID, pokemonImageTypes);
}
// Load Deoxys Form Images
command = new SQLiteCommand("SELECT * FROM DeoxysFormImages", connection);
reader = command.ExecuteReader();
table = new DataTable("DeoxysFormImages");
table.Load(reader);
foreach (DataRow row in table.Rows) {
byte id = (byte)(long)row["ID"];
DexFormID dexFormID = new DexFormID { DexID = 386, FormID = id };
Gen3PokemonImageTypes pokemonImageTypes = new Gen3PokemonImageTypes();
pokemonImageTypes.Image = LoadImage(row["Image"] as byte[]);
pokemonImageTypes.ShinyImage = LoadImage(row["ShinyImage"] as byte[]);
pokemonImageTypes.BoxImage = LoadImage(row["BoxImage"] as byte[]);
pokemonImageTypes.NewBoxImage = LoadImage(row["NewBoxImage"] as byte[]);
pokemonImageTypes.NewBoxShinyImage = LoadImage(row["NewBoxShinyImage"] as byte[]);
gen3PokemonFormImages.Add(dexFormID, pokemonImageTypes);
}
// Load Ribbon Images
command = new SQLiteCommand("SELECT * FROM RibbonImages", connection);
reader = command.ExecuteReader();
table = new DataTable("RibbonImages");
table.Load(reader);
foreach (DataRow row in table.Rows) {
string id = row["ID"] as string;
BitmapImage image = LoadImage((byte[])row["Image"]);
ribbonImages.Add(id, image);
}
// Load Met Locations
command = new SQLiteCommand("SELECT * FROM MetLocations", connection);
reader = command.ExecuteReader();
table = new DataTable("MetLocations");
table.Load(reader);
foreach (DataRow row in table.Rows) {
//.........这里部分代码省略.........
示例15: GetFormatedBitmapSource
/// <summary>
/// This method converts the output from the OpenGL render context provider to a
/// FormatConvertedBitmap in order to show it in the image.
/// </summary>
/// <param name="hBitmap">The handle of the bitmap from the OpenGL render context.</param>
/// <returns>Returns the new format converted bitmap.</returns>
private static FormatConvertedBitmap GetFormatedBitmapSource(IntPtr hBitmap)
{
// TODO: We have to remove the alpha channel - for some reason it comes out as 0.0
// meaning the drawing comes out transparent.
FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
newFormatedBitmapSource.BeginInit();
newFormatedBitmapSource.Source = BitmapConversion.HBitmapToBitmapSource(hBitmap);
newFormatedBitmapSource.DestinationFormat = PixelFormats.Rgb24;
newFormatedBitmapSource.EndInit();
return newFormatedBitmapSource;
}