當前位置: 首頁>>代碼示例>>C#>>正文


C# BmpBitmapEncoder.Save方法代碼示例

本文整理匯總了C#中System.Windows.Media.Imaging.BmpBitmapEncoder.Save方法的典型用法代碼示例。如果您正苦於以下問題:C# BmpBitmapEncoder.Save方法的具體用法?C# BmpBitmapEncoder.Save怎麽用?C# BmpBitmapEncoder.Save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Media.Imaging.BmpBitmapEncoder的用法示例。


在下文中一共展示了BmpBitmapEncoder.Save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Initialize

        public static void Initialize(dynamic window)
        {
            Bitmap icon;
            using (MemoryStream outStream = new MemoryStream())
            {
                BitmapEncoder enc = new BmpBitmapEncoder();
                enc.Frames.Add(BitmapFrame.Create(new Uri(@"pack://application:,,,/Resources/ImageViewer.ico", UriKind.Absolute)));
                enc.Save(outStream);
                icon = new Bitmap(outStream);
            }

            _notifyIcon = new NotifyIcon
            {
                Icon = System.Drawing.Icon.FromHandle(icon.GetHicon()),
                Visible = true
            };

            var cms = new ContextMenuStrip();
            var tsm = new ToolStripMenuItem {Text = @"Exit"};
            tsm.Click += (sender, e) =>
            {
                Exit();
            };
            cms.Items.Add(tsm);
            _notifyIcon.ContextMenuStrip = cms;

            Window = window;
        }
開發者ID:mohemohe,項目名稱:ImageViewer,代碼行數:28,代碼來源:NotifyIconHelper.cs

示例2: ToFile

        public static bool ToFile(BitmapSource source, string s_uri)
        {
            if (source != null)
            {
                System.IO.File.Delete(s_uri);

                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                BmpBitmapEncoder bmpenco = new BmpBitmapEncoder();
                bmpenco.Frames.Add(BitmapFrame.Create(source));
                bmpenco.Save(ms);
                ms.Flush();
                
                System.IO.Stream st = System.IO.File.Open(s_uri, System.IO.FileMode.CreateNew);
                st.Write(ms.GetBuffer(), 0, ms.ToArray().Length);
                
                st.Close();
                st.Dispose();

                ms.Dispose();
                return true;
            }
            else
            {
                return false;
            }
        }
開發者ID:noedelarosa,項目名稱:SIC,代碼行數:26,代碼來源:WorkImage.cs

示例3: RenderToBmp

 /// <summary>
 /// Renders a visual UI element to a stream in bitmap (BMP) format</summary>
 /// <param name="visual">Visual UI element to be rendered</param>
 /// <param name="stream">Stream data written to</param>
 /// <param name="scale">Rendering scale</param>
 public static void RenderToBmp(this UIElement visual, Stream stream, double scale)
 {
     BitmapFrame frame = visual.RenderToBitmapFrame(scale);
     var encoder = new BmpBitmapEncoder();
     encoder.Frames.Add(frame);
     encoder.Save(stream);
 }
開發者ID:vincenthamm,項目名稱:ATF,代碼行數:12,代碼來源:ImageUtil.cs

示例4: ConvertBack

        /// <summary>
        /// Converts ImageSource to byte[]
        /// </summary>
        /// <returns>
        /// A converted value. If the method returns null, the valid null value is used.
        /// </returns>
        /// <param name="value">The value that is produced by the binding target.</param><param name="targetType">The type to convert to.</param><param name="parameter">The converter parameter to use.</param><param name="culture">The culture to use in the converter.</param>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var renderTargetBitmap = value as RenderTargetBitmap;
            if (null != renderTargetBitmap)
            {
                var bitmapImage = new BitmapImage();
                var bitmapEncoder = new BmpBitmapEncoder();
                bitmapEncoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap));

                using (var stream = new MemoryStream())
                {
                    bitmapEncoder.Save(stream);
                    stream.Seek(0, SeekOrigin.Begin);
                    bitmapImage.BeginInit();
                    bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                    bitmapImage.StreamSource = stream;
                    bitmapImage.EndInit();
                }
                var encoder = new JpegBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bitmapImage));
                byte[] data = null;
                using (var ms = new MemoryStream())
                {
                    encoder.Save(ms);
                    data = ms.ToArray();
                }
                return data;
            }
            return null;
        }
開發者ID:vnl,項目名稱:Monies,代碼行數:37,代碼來源:ImageToBinaryConverter.cs

示例5: BMPFromBitmapSource

        public static System.Drawing.Bitmap BMPFromBitmapSource(BitmapSource source, int iCount)
        {
            //int width = 128;
            //int height = 128;
            //int stride = width;
            //byte[] pixels = new byte[height * stride];

            //// Define the image palette
            //BitmapPalette myPalette = BitmapPalettes.Halftone256;

            //// Creates a new empty image with the pre-defined palette

            //BitmapSource image = BitmapSource.Create(
            //    width,
            //    height,
            //    96,
            //    96,
            //    PixelFormats.Indexed8,
            //    myPalette,
            //    pixels,
            //    stride);

            FileStream stream = new FileStream("image" + iCount + ".BMP", FileMode.Create);
            BmpBitmapEncoder encoder = new BmpBitmapEncoder();
            //TextBlock myTextBlock = new TextBlock();
            //myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString();
            //encoder.Interlace = PngInterlaceOption.On;
            encoder.Frames.Add(BitmapFrame.Create(source));
            encoder.Save(stream);

            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(stream);
            return bitmap;
        }
開發者ID:enesyteam,項目名稱:EChess,代碼行數:33,代碼來源:BitmapHelper.cs

示例6: Save

        public static void Save(this BitmapSource image, string filePath, ImageFormat format)
        {
            BitmapEncoder encoder = null;
            
            switch(format)
            {
                case ImageFormat.Png:
                    encoder = new PngBitmapEncoder();
                    break;
                case ImageFormat.Jpeg:
                    encoder = new JpegBitmapEncoder();
                    break;
                case ImageFormat.Bmp:
                    encoder = new BmpBitmapEncoder();
                    break;
            }

            if (encoder == null) 
                return;

            encoder.Frames.Add(BitmapFrame.Create(BitmapFrame.Create(image)));

            using (var stream = new FileStream(filePath, FileMode.Create))
                encoder.Save(stream);
        }
開發者ID:kaorun55,項目名稱:OpenNI.Toolkit,代碼行數:25,代碼來源:BitmapSourceExtensions.cs

示例7: InsertMessageAction

        private void InsertMessageAction(object parameter)
        {
            string message = parameter as string;

            MemoryStream ms = new MemoryStream();
            BitmapEncoder encode = new BmpBitmapEncoder();

            encode.Frames.Add(BitmapFrame.Create(_sourceImage));
            encode.Save(ms);
            var bmpData = ms.ToArray();
            BitmapManipulator manipulator = new BitmapManipulator(bmpData);
            string encryptedMessage = Cryptography.Encrypt(message, this.Password);
            manipulator.InsertMessage(encryptedMessage);

            var imageSource = new BitmapImage();
            MemoryStream imageMS = new MemoryStream(manipulator.Bytes);

            imageSource.BeginInit();
            imageSource.StreamSource = imageMS;
            imageSource.EndInit();

            CryptedImage = imageSource;
            if (bmpData.Length != manipulator.Bytes.Length)
            {
                Debugger.Break();
            }

        }
開發者ID:soltys,項目名稱:ZUT_Stegano,代碼行數:28,代碼來源:MainWindowViewModel.cs

示例8: CreatePdfDocument

        public Document CreatePdfDocument(Chart chart, string path)
        {
            RenderTargetBitmap renderBitmap = new RenderTargetBitmap(
                (int) chart.ActualWidth,
                (int) chart.ActualHeight,
                96d,
                96d,
                PixelFormats.Pbgra32);

            renderBitmap.Render(chart);

            MemoryStream stream = new MemoryStream();
            BitmapEncoder encoder = new BmpBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
            encoder.Save(stream);

            Bitmap bitmap = new Bitmap(stream);
            System.Drawing.Image image = bitmap;

            System.Drawing.Image resizedImage = ResizeImage(image, image.Width*2, image.Height);

            Document doc = new Document(PageSize.A4);
            PdfWriter.GetInstance(doc, new FileStream(path, FileMode.OpenOrCreate));
            doc.Open();
            Image pdfImage = Image.GetInstance(resizedImage, ImageFormat.Jpeg);
            doc.Add(pdfImage);
            doc.Close();
            
            return doc;
        }
開發者ID:LexaGal,項目名稱:Plants,代碼行數:30,代碼來源:PdfDocumentCreator.cs

示例9: 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;
        }
開發者ID:sipsorcery,項目名稱:sipsorcery,代碼行數:32,代碼來源:UIHelper.cs

示例10: ExportToImage

        public static void ExportToImage(FrameworkElement surface)
        {
            Size size = new Size(surface.ActualWidth, surface.ActualHeight);
            RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96d, 96d, PixelFormats.Pbgra32);
            renderBitmap.Render(surface);

            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName = DateTime.Now.ToString("yyyy-M-d-H_m_s");
            string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\WLANFolder";
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);
            dlg.InitialDirectory = path;
            dlg.OverwritePrompt = true;
            dlg.Filter = "JPEG Image|*.jpg|Bitmap Image|*.bmp|PNG Image|*.png";
            dlg.Title = "Save an Image File";
            dlg.ShowDialog();
            dlg.RestoreDirectory = true;

            if (dlg.FileName != "")
            {
                try
                {
                    using(FileStream outStream = (System.IO.FileStream)dlg.OpenFile())
                    {
                        switch (dlg.FilterIndex)
                        {
                            case 1:
                                {
                                    JpegBitmapEncoder encoder = new JpegBitmapEncoder();
                                    encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
                                    encoder.Save(outStream);
                                }
                                break;
                            case 2:
                                {
                                    BmpBitmapEncoder encoder = new BmpBitmapEncoder();
                                    encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
                                    encoder.Save(outStream);
                                }
                                break;
                            case 3:
                                {
                                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                                    encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
                                    encoder.Save(outStream);
                                }
                                break;
                            default:
                                break;
                        }
                        System.Diagnostics.Process.Start(dlg.FileName);
                    }          
                }
                catch (ArgumentException)
                { return; }
            }
        }
開發者ID:Tripmaster-zhang,項目名稱:Hello_World,代碼行數:57,代碼來源:SaveAsImage.cs

示例11: SaveToBmp

 /// <summary>
 /// Save the BitmapImage img to the File filename as a .bmp
 /// </summary>
 /// <param name="img"></param>
 /// <param name="fileName"></param>
 public static void SaveToBmp(BitmapImage img, string fileName)
 {
     var encoder = new BmpBitmapEncoder();
     encoder.Frames.Add(BitmapFrame.Create(img));
     using (var filestream = new FileStream(fileName, FileMode.Create))
     {
         encoder.Save(filestream);
     }
 }
開發者ID:mk1234444,項目名稱:TwitchAlert,代碼行數:14,代碼來源:ImageSaver.cs

示例12: ImageWpfToGDI

        public static System.Drawing.Image ImageWpfToGDI(System.Windows.Media.ImageSource imageSource)
        {
            MemoryStream ms = new MemoryStream();
            var encoder = new System.Windows.Media.Imaging.BmpBitmapEncoder();
            encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(imageSource as System.Windows.Media.Imaging.BitmapSource));
            encoder.Save(ms);
            ms.Flush();

            return System.Drawing.Image.FromStream(ms);
        }
開發者ID:steamprodz,項目名稱:DantistApp,代碼行數:10,代碼來源:ImageHelper.cs

示例13: BitmapImage2Bitmap

 public static Bitmap BitmapImage2Bitmap(BitmapImage bitmapImage)
 {
     using (var outStream = new MemoryStream()) {
         BitmapEncoder enc = new BmpBitmapEncoder();
         enc.Frames.Add(BitmapFrame.Create(bitmapImage));
         enc.Save(outStream);
         var bitmap = new Bitmap(outStream);
         return new Bitmap(bitmap);
     }
 }
開發者ID:perfectdev,項目名稱:SkinDesigner,代碼行數:10,代碼來源:Core.cs

示例14: BitmapImage2Bitmap

 //-------------------------------------
 private Bitmap BitmapImage2Bitmap(ref BitmapImage bitmapImage)
 {
     using (MemoryStream outStream = new MemoryStream())
     {
         BitmapEncoder enc = new BmpBitmapEncoder();
         enc.Frames.Add(BitmapFrame.Create(bitmapImage));
         enc.Save(outStream);
         return new Bitmap(outStream);
     }
 }
開發者ID:CaterTsai,項目名稱:P_CCGifCreate,代碼行數:11,代碼來源:imageProcesser.cs

示例15: ToStream

        public static Stream ToStream(BitmapSource bitmap)
        {
            var memory = new MemoryStream();

            var encoder = new BmpBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(bitmap));
            encoder.Save(memory);

            return memory;
        }
開發者ID:sakapon,項目名稱:XAML-to-Image,代碼行數:10,代碼來源:BitmapUtility.cs


注:本文中的System.Windows.Media.Imaging.BmpBitmapEncoder.Save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。