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


C# Imaging.BmpBitmapEncoder類代碼示例

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


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

示例1: getFeatures

        private double[] getFeatures()
        {
            rtb = new RenderTargetBitmap((int)InkCanvas1.ActualWidth, (int)InkCanvas1.ActualHeight,
                96d, 96d, PixelFormats.Default);

            rtb.Render(InkCanvas1);

            //save the ink to a memory stream
            BmpBitmapEncoder encoder = new BmpBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(rtb));

            byte[] bitmapBytes;
            Bitmap bmp;
            using (MemoryStream ms = new MemoryStream())
            {
                encoder.Save(ms);
                ms.Position = 0;
                bitmapBytes = ms.ToArray();

                ms.Seek(0, SeekOrigin.Begin);
                bmp = new Bitmap(ms);
            }

            bmp = resize.Apply(bmp);

            double[] features = ToFeatures(bmp);

            return features;
        }
開發者ID:CanerPatir,項目名稱:framework,代碼行數:29,代碼來源:DrawingCanvas.xaml.cs

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

示例3: GenerateImage

        public MemoryStream GenerateImage(Visual vsual, int widhth, int height, ImageFormat format)
        {
            BitmapEncoder encoder = null;

            switch (format)
            {
                case ImageFormat.JPG :
                    encoder = new JpegBitmapEncoder();
                    break;
                case ImageFormat.PNG:
                    encoder = new PngBitmapEncoder();
                    break;
                case ImageFormat.BMP:
                    encoder = new BmpBitmapEncoder();
                    break;
                case ImageFormat.GIF:
                    encoder = new GifBitmapEncoder();
                    break;
                case ImageFormat.TIF:
                    encoder = new TiffBitmapEncoder();
                    break;

            }

            if (encoder == null) return null;

            RenderTargetBitmap rtb = this.RenderVisaulToBitmap(vsual, widhth, height);
            MemoryStream file = new MemoryStream();
            encoder.Frames.Add(BitmapFrame.Create(rtb));
            encoder.Save(file);

            return file;
        }
開發者ID:enesyteam,項目名稱:EChess,代碼行數:33,代碼來源:Model.cs

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

示例5: SaveAsImage

        /// <summary>
        /// Saves the full chart to a file, including technical analysis.
        /// </summary>
        /// <param name="filename">The file to write to.</param>
        public void SaveAsImage(string filename)
        {
            if (string.IsNullOrEmpty(filename))
                throw new ArgumentNullException();

            var extension = Path.GetExtension(filename);
            if (string.IsNullOrEmpty(extension))
                throw new ArgumentNullException();

            BitmapEncoder bitmapEncoder;
            extension = extension.ToLower();
            if (extension == ".png")
                bitmapEncoder = new PngBitmapEncoder();
            else if (extension == ".jpg" || extension == ".jpeg")
                bitmapEncoder = new JpegBitmapEncoder();
            else if (extension == ".gif")
                bitmapEncoder = new GifBitmapEncoder();
            else if (extension == ".bmp")
                bitmapEncoder = new BmpBitmapEncoder();
            else throw new ArgumentException("Cannot find a BitmapEncoder for this file type.");

            var renderTargetBitmap = new RenderTargetBitmap((int)this.ActualWidth, (int)this.ActualHeight, 96, 96, PixelFormats.Pbgra32);

            foreach (var child in LogicalTreeHelper.GetChildren(this))
            {
                if (child is ChartPanel)
                    renderTargetBitmap.Render((ChartPanel)child);
            }

            bitmapEncoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap));
            using (Stream stream = File.Create(filename))
            {
                bitmapEncoder.Save(stream);
            }
        }
開發者ID:anndream,項目名稱:StockCharts-1,代碼行數:39,代碼來源:StockChartControl.cs

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

示例7: SaveBitmap

        private static void SaveBitmap(BitmapSource bitmap, string destination)
        {
            BitmapEncoder encoder;

            switch (Path.GetExtension(destination).ToUpperInvariant())
            {
                case ".BMP":
                    encoder = new BmpBitmapEncoder();
                    break;

                case ".GIF":
                    encoder = new GifBitmapEncoder();
                    break;

                case ".JPG":
                    encoder = new JpegBitmapEncoder() { QualityLevel = 100 };
                    break;

                case ".PNG":
                    encoder = new PngBitmapEncoder();
                    break;

                case ".TIF":
                    encoder = new TiffBitmapEncoder() { Compression = TiffCompressOption.Zip };
                    break;

                default:
                    throw new NotSupportedException("Not supported output extension.");
            }

            encoder.Frames.Add(BitmapFrame.Create(bitmap));
            encoder.Save(new FileStream(destination, FileMode.Create));
        }
開發者ID:EFanZh,項目名稱:EFanZh,代碼行數:33,代碼來源:Program.cs

示例8: Buid

        public override void Buid(string imageName)
        {
            if(imageName == null) return;

            Panel.Measure(new Size((int)Panel.Width, (int)Panel.Height));
            Panel.Arrange(new Rect(new Size((int)Panel.Width, (int)Panel.Height)));

            int height = (int)Panel.Height;
            int width = (int)Panel.Width;

            RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
            bmp.Render(Panel);

            string extension = Path.GetExtension(imageName)?.ToLower();

            BitmapEncoder encoder;
            if (extension == ".bmp")
                encoder = new BmpBitmapEncoder();
            else if (extension == ".png")
                encoder = new PngBitmapEncoder();
            else if (extension == ".jpg")
                encoder = new JpegBitmapEncoder();
            else
                return;

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

            using (Stream stm = File.Create(imageName))
            {
                encoder.Save(stm);
            }
        }
開發者ID:msCube,項目名稱:Gallery,代碼行數:32,代碼來源:ImageBuilder.cs

示例9: OnSaveImageClick

        // Handles save image click
        private void OnSaveImageClick(object sender, RoutedEventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "24-bit Bitmap (*.bmp)|*.bmp|JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|GIF (*.gif)|*.gif|PNG (*.png)|*.png";
            dlg.FilterIndex = 4;
            bool? dlgResult = dlg.ShowDialog(Window.GetWindow(this));
            if(dlgResult.HasValue && dlgResult.Value)
            {
                Visualizer visualizer = Visualizer;
                RenderTargetBitmap bitmap = new RenderTargetBitmap((int)previewPage.PageWidth, (int)previewPage.PageHeight, 96, 96, PixelFormats.Pbgra32);

                visualizer.RenderTo(bitmap);

                BitmapEncoder encoder = null;
                string ext = System.IO.Path.GetExtension(dlg.FileName);
                if (ext == "bmp") encoder = new BmpBitmapEncoder();
                else if ((ext == "jpg") || (ext == "jpeg")) encoder = new JpegBitmapEncoder();
                else encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bitmap));
                using (FileStream stream = new FileStream(dlg.FileName, FileMode.Create, FileAccess.Write))
                {
                    encoder.Save(stream);
                    stream.Flush();
                }
            }
        }
開發者ID:prabuddha1987,項目名稱:NuGenBioChem,代碼行數:27,代碼來源:PublishTab.xaml.cs

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

示例11: Save

 public void Save(BitmapSource bmSource)
 {
     BitmapEncoder encoder;
     switch (Path.GetExtension(_path).ToLower())
     {
         case ".jpg":
         case ".jpeg":
             encoder = new JpegBitmapEncoder();
             break;
         case ".gif":
             encoder = new GifBitmapEncoder();
             break;
         case ".bmp":
             encoder = new BmpBitmapEncoder();
             break;
         case ".tif":
         case ".tiff":
             encoder = new TiffBitmapEncoder();
             break;
         case ".png":
             encoder = new PngBitmapEncoder();
             break;
         default:
             throw new ArgumentException("Wrong path");
     }
     encoder.Frames.Add(BitmapFrame.Create(bmSource));
     Stream stm = File.Create(_path);
     encoder.Save(stm);
     stm.Dispose();
 }
開發者ID:vit2005,項目名稱:Multitier-Project,代碼行數:30,代碼來源:StandartPS.cs

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

示例13: GetBitmapEncoder

        private static BitmapEncoder GetBitmapEncoder(ImageContentType imageContentType)
        {
            BitmapEncoder bitmapEncoder;

            switch (imageContentType)
            {
                case ImageContentType.ImageBmpContentType:
                    bitmapEncoder = new BmpBitmapEncoder();
                    break;
                case ImageContentType.ImageGifContentType:
                    bitmapEncoder = new GifBitmapEncoder();
                    break;
                case ImageContentType.ImageJpegContentType:
                    bitmapEncoder = new JpegBitmapEncoder();
                    break;
                case ImageContentType.ImageTiffContentType:
                    bitmapEncoder = new TiffBitmapEncoder();
                    break;
                case ImageContentType.ImagePngContentType:
                    bitmapEncoder = new PngBitmapEncoder();
                    break;
                default:
                    bitmapEncoder = new PngBitmapEncoder();
                    break;
            }
            return bitmapEncoder;
        }
開發者ID:alexiej,項目名稱:YATE,代碼行數:27,代碼來源:WpfPayload.cs

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

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


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