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


C# FormatConvertedBitmap.BeginInit方法代码示例

本文整理汇总了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;
        }
开发者ID:IntelisoftDev,项目名称:NgScanApp,代码行数:32,代码来源:ImageProc.cs

示例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;
        }
开发者ID:duckworth,项目名称:DynamicImageDemo,代码行数:32,代码来源:WPFPngColorReducer.cs

示例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);
 }
开发者ID:kib357,项目名称:Ester2,代码行数:9,代码来源:WorkWithImages.cs

示例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;
        }
开发者ID:huangjia2107,项目名称:MyControls,代码行数:10,代码来源:GraphicAlgorithm.cs

示例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;
        }
开发者ID:kockaart,项目名称:AirGuitarHero-master,代码行数:18,代码来源:ImageHelpers.cs

示例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;
        }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:53,代码来源:ShowMyFace.cs

示例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; }));
        }
开发者ID:nick121212,项目名称:xima_desktop3,代码行数:12,代码来源:ImageAttached.cs

示例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;
        }
开发者ID:IntelisoftDev,项目名称:NgScanApp,代码行数:16,代码来源:ImageProc.cs

示例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;
        }
开发者ID:nlabiris,项目名称:ImageEdit_WPF,代码行数:21,代码来源:ConvertionMethods.cs

示例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;
        }
开发者ID:powernick,项目名称:CodeLib,代码行数:20,代码来源:TestImage.xaml.cs

示例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;
        }
开发者ID:kockaart,项目名称:AirGuitarHero-master,代码行数:20,代码来源:ImageHelpers.cs

示例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;
        }
开发者ID:CadeLaRen,项目名称:digiCamControl,代码行数:23,代码来源:ColorUtility.cs

示例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;
        }
开发者ID:ungood,项目名称:OmegaNET,代码行数:24,代码来源:BitmapHelper.cs

示例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) {
//.........这里部分代码省略.........
开发者ID:trigger-death,项目名称:TriggersPC,代码行数:101,代码来源:PokemonDatabase.cs

示例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;
        }
开发者ID:cvanherk,项目名称:3d-engine,代码行数:19,代码来源:OpenGLControl.xaml.cs


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