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


C# FormatConvertedBitmap.EndInit方法代码示例

本文整理汇总了C#中System.Windows.Media.Imaging.FormatConvertedBitmap.EndInit方法的典型用法代码示例。如果您正苦于以下问题:C# FormatConvertedBitmap.EndInit方法的具体用法?C# FormatConvertedBitmap.EndInit怎么用?C# FormatConvertedBitmap.EndInit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.Imaging.FormatConvertedBitmap的用法示例。


在下文中一共展示了FormatConvertedBitmap.EndInit方法的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: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例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: 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

示例12: 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

示例13: ConvertToBitmap

        /// <summary>
        /// Converts BitmapSource to Bitmap.
        /// </summary>
        /// <param name="sourceWpf">BitmapSource</param>
        /// <returns>Bitmap</returns>
        private static Bitmap ConvertToBitmap(BitmapSource sourceWpf)
        {
            BitmapSource bmpWpf = sourceWpf;

            // PixelFormat settings/conversion
            System.Drawing.Imaging.PixelFormat formatBmp = System.Drawing.Imaging.PixelFormat.Format32bppArgb;
            if (sourceWpf.Format == PixelFormats.Bgr24)
            {
                formatBmp = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
            }
            else if (sourceWpf.Format == System.Windows.Media.PixelFormats.Pbgra32)
            {
                formatBmp = System.Drawing.Imaging.PixelFormat.Format32bppPArgb;
            }
            else if (sourceWpf.Format != System.Windows.Media.PixelFormats.Bgra32)
            {
                // Convert BitmapSource
                FormatConvertedBitmap convertWpf = new FormatConvertedBitmap();
                convertWpf.BeginInit();
                convertWpf.Source = sourceWpf;
                convertWpf.DestinationFormat = PixelFormats.Bgra32;
                convertWpf.EndInit();
                bmpWpf = convertWpf;
            }

            // Copy/Convert to Bitmap
            Bitmap bmp = new Bitmap(bmpWpf.PixelWidth, bmpWpf.PixelHeight, formatBmp);
            Rectangle rect = new Rectangle(Point.Empty, bmp.Size);
            BitmapData data = bmp.LockBits(rect, ImageLockMode.WriteOnly, formatBmp);
            bmpWpf.CopyPixels(System.Windows.Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
            bmp.UnlockBits(data);

            return bmp;
        }
开发者ID:Cocotteseb,项目名称:imagelistview,代码行数:39,代码来源:ThumbnailExtractor.cs

示例14: Tick

        private void Tick(object sender, EventArgs eventArgs)
        {
            lock (GL)
            {
                _sw.Restart();
                GL.MakeCurrent();

                OnUpdate(GL);
                OnRender(GL);

                GL.Blit(IntPtr.Zero);

                var provider = GL.RenderContextProvider as FBORenderContextProvider;
                if (provider == null) return;
                var newFormatedBitmapSource = new FormatConvertedBitmap();
                newFormatedBitmapSource.BeginInit();

                newFormatedBitmapSource.Source = BitmapConversion.HBitmapToBitmapSource(provider.InternalDIBSection.HBitmap);
                newFormatedBitmapSource.DestinationFormat = PixelFormats.Rgb24;
                newFormatedBitmapSource.EndInit();

                image.Source = newFormatedBitmapSource;

                _sw.Stop();
                FPS = 1000.0 / _sw.Elapsed.TotalMilliseconds;
            }
        }
开发者ID:rho24,项目名称:OpenCAD,代码行数:27,代码来源:CADControl.xaml.cs

示例15: timer_Tick

        /// <summary>
        /// Handles the Tick event of the timer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void timer_Tick(object sender, EventArgs e)
        {
            //  Lock on OpenGL.
            lock (gl)
            {
                //  Start the stopwatch so that we can time the rendering.
                stopwatch.Restart();

                //  Make GL current.
                gl.MakeCurrent();

                //	If there is a draw handler, then call it.
                var handler = OpenGLDraw;
                if (handler != null)
                    handler(this, eventArgsFast);
                else
                    gl.Clear(SharpGL.OpenGL.GL_COLOR_BUFFER_BIT);

                //  Draw the FPS.
                if (DrawFPS)
                {
                    gl.DrawText(5, 5, 1.0f, 0.0f, 0.0f, "Courier New", 12.0f, string.Format("Draw Time: {0:0.0000} ms ~ {1:0.0} FPS", frameTime, 1000.0 / frameTime));
                    gl.Flush();
                }

                //  Render.
                gl.Blit(IntPtr.Zero);

                switch (RenderContextType)
                {
                    case SharpGL.RenderContextType.DIBSection:
                        {
                            SharpGL.RenderContextProviders.DIBSectionRenderContextProvider provider = gl.RenderContextProvider as SharpGL.RenderContextProviders.DIBSectionRenderContextProvider;

                            //  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(provider.DIBSection.HBitmap);
                            newFormatedBitmapSource.DestinationFormat = PixelFormats.Rgb24;
                            newFormatedBitmapSource.EndInit();

                            //  Copy the pixels over.
                            image.Source = newFormatedBitmapSource;
                        }
                        break;
                    case SharpGL.RenderContextType.NativeWindow:
                        break;
                    case SharpGL.RenderContextType.HiddenWindow:
                        break;
                    case SharpGL.RenderContextType.FBO:
                        {
                            SharpGL.RenderContextProviders.FBORenderContextProvider provider = gl.RenderContextProvider as SharpGL.RenderContextProviders.FBORenderContextProvider;

                            //  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(provider.InternalDIBSection.HBitmap);
                            newFormatedBitmapSource.DestinationFormat = PixelFormats.Rgb24;
                            newFormatedBitmapSource.EndInit();

                            //  Copy the pixels over.
                            image.Source = newFormatedBitmapSource;
                        }
                        break;
                    default:
                        break;
                }

                //  Stop the stopwatch.
                stopwatch.Stop();

                //  Store the frame time.
                frameTime = stopwatch.Elapsed.TotalMilliseconds;
            }
        }
开发者ID:EdwardSalter,项目名称:NCubeSolver,代码行数:82,代码来源:FixedOpenGLControl.xaml.cs


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