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


C# Imaging.BitmapSource類代碼示例

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


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

示例1: SaveImageCapture

        /// <summary>
        /// Scripter: YONGTOK KIM
        /// Description : Save the image to the file.
        /// </summary>

        public static string SaveImageCapture(BitmapSource bitmap)
        {
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(bitmap));
            encoder.QualityLevel = 100;


            // Configure save file dialog box
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName = "Image"; // Default file name
            dlg.DefaultExt = ".Jpg"; // Default file extension
            dlg.Filter = "Image (.jpg)|*.jpg"; // Filter files by extension

            // Show save file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Save Image
                string filename = dlg.FileName;
                FileStream fstream = new FileStream(filename, FileMode.Create);
                encoder.Save(fstream);
                fstream.Close();

                return filename;
            }

            return null;
        }
開發者ID:kyt8724,項目名稱:OperatorRegistration,代碼行數:35,代碼來源:IDSWebCamHelper.cs

示例2: GetImageByteArray

 // get raw bytes from BitmapImage using BitmapImage.CopyPixels
 private byte[] GetImageByteArray(BitmapSource bi)
 {
     var rawStride = (bi.PixelWidth * bi.Format.BitsPerPixel + 7) / 8;
     var result = new byte[rawStride * bi.PixelHeight];
     bi.CopyPixels(result, rawStride, 0);
     return result;
 }
開發者ID:TNOCS,項目名稱:csTouch,代碼行數:8,代碼來源:Screenshots.cs

示例3: ExtractBestTextCandidate

        private string ExtractBestTextCandidate(BitmapSource bitmap, ITextualDataFilter filter, Symbology symbology)
        {
            var page = Engine.Recognize(bitmap, RecognitionConfiguration.FromSingleImage(bitmap, filter, symbology));
            var zone = page.RecognizedZones.First();

            return zone.RecognitionResult.Text;
        }
開發者ID:SuperJMN,項目名稱:Glass,代碼行數:7,代碼來源:MultiEngineTest.cs

示例4: Apply

 public BitmapSource Apply(BitmapSource image)
 {
     var grayScale = ToGrayScale(image);
     var filter = new Threshold(factor);
     var bmp = filter.Apply(grayScale);
     return bmp.ToBitmapImage();
 }
開發者ID:SuperJMN,項目名稱:Glass,代碼行數:7,代碼來源:ThresholdFilter.cs

示例5: SolverOutput

        public SolverOutput(BitmapSource data, List<Solver.Colorizer> colorpalette, IEnumerable<Charge> charges)
        {
            InitializeComponent();
            _outputdata = data;
            _charges = new List<Charge>(charges);
            gridField.Background = new ImageBrush(data);

            recMapHelper.Fill = Helper.ConvertToBrush(colorpalette);

            foreach (Charge charge in _charges)
            {
                if (charge.IsActive)
                {
                    var newfPoint = new FieldPoint
                                        {
                                            Height = 6,
                                            Width = 6,
                                            HorizontalAlignment = HorizontalAlignment.Left,
                                            VerticalAlignment = VerticalAlignment.Top,
                                            Margin = new Thickness(0, 0, 0, 0),
                                            Mcharge = charge
                                        };
                    var tgroup = new TransformGroup();
                    var tt = new TranslateTransform(charge.Location.X + 14, charge.Location.Y + 14);
                    tgroup.Children.Add(tt);

                    gridField.Children.Add(newfPoint);
                    newfPoint.RenderTransform = tgroup;
                }
            }
        }
開發者ID:taesiri,項目名稱:electric-field,代碼行數:31,代碼來源:SolverOutput.xaml.cs

示例6: WriteableBitmap

 public WriteableBitmap(
     BitmapSource source
     )
     : base(true) // Use base class virtuals
 {
     InitFromBitmapSource(source);
 }
開發者ID:nlh774,項目名稱:DotNetReferenceSource,代碼行數:7,代碼來源:WriteableBitmap.cs

示例7: TransformedBitmap

        /// <summary>
        /// Construct a TransformedBitmap with the given newTransform
        /// </summary>
        /// <param name="source">BitmapSource to apply to the newTransform to</param>
        /// <param name="newTransform">Transform to apply to the bitmap</param>
        public TransformedBitmap(BitmapSource source, Transform newTransform)
            : base(true) // Use base class virtuals
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (newTransform == null)
            {
                throw new InvalidOperationException(SR.Get(SRID.Image_NoArgument, "Transform"));
            }

            if (!CheckTransform(newTransform))
            {
                throw new InvalidOperationException(SR.Get(SRID.Image_OnlyOrthogonal));
            }

            _bitmapInit.BeginInit();

            Source = source;
            Transform = newTransform;

            _bitmapInit.EndInit();
            FinalizeCreation();
        }
開發者ID:JianwenSun,項目名稱:cc,代碼行數:31,代碼來源:TransformedBitmap.cs

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

示例9: GetBitmap

        /// <summary>
        /// Chuyển đổi BitmapSource thành Bitmap
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static System.Drawing.Bitmap GetBitmap(BitmapSource source)
        {
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap
            (
              source.PixelWidth,
              source.PixelHeight,
              System.Drawing.Imaging.PixelFormat.Format32bppRgb
            );

            System.Drawing.Imaging.BitmapData data = bmp.LockBits
            (
                new System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size),
                System.Drawing.Imaging.ImageLockMode.WriteOnly,
                System.Drawing.Imaging.PixelFormat.Format32bppRgb
            );

            source.CopyPixels
            (
              Int32Rect.Empty,
              data.Scan0,
              data.Height * data.Stride,
              data.Stride
            );

            bmp.UnlockBits(data);

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

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

示例11: RecognizeScaleEachVariation

 public IEnumerable<RecognitionResult> RecognizeScaleEachVariation(BitmapSource bitmap, ZoneConfiguration config)
 {
     var bitmaps = BitmapGenerators.SelectMany(g => g.Generate(bitmap));
     var scaled = bitmaps.Select(ScaleIfEnabled);
     var recognitions = scaled.SelectMany(bmp => RecognizeCore(config, bmp));
     return recognitions;
 }
開發者ID:SuperJMN,項目名稱:Glass,代碼行數:7,代碼來源:LeadToolsZoneBasedOcrService.cs

示例12: ImageReceivedEventArgs

        public ImageReceivedEventArgs(BitmapSource image)
        {
            if (image == null)
                throw new ArgumentNullException("image");

            this.image = image;
        }
開發者ID:jlucas9,項目名稱:WVU-Lunabotics,代碼行數:7,代碼來源:JPEGReceiver.cs

示例13: Write

        public void Write(BitmapSource i, Stream s)
        {
            BitmapEncoder encoder = null;

            if (MimeType.Equals("image/jpeg"))
            {
                encoder = new JpegBitmapEncoder();
                ((JpegBitmapEncoder)encoder).QualityLevel = localSettings.Quality;
            }
            else if (MimeType.Equals("image/png"))
            {
                encoder = new PngBitmapEncoder();
            }
            else if (MimeType.Equals("image/gif"))
            {
                encoder = new GifBitmapEncoder();
                encoder.Palette = new BitmapPalette(i, 256);
            }

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

            using (MemoryStream outputStream = new MemoryStream())
            {
                encoder.Save(outputStream);
                outputStream.WriteTo(s);
            }
        }
開發者ID:stukalin,項目名稱:ImageResizer,代碼行數:27,代碼來源:WpfEncoderPlugin.cs

示例14: ColorConvertedBitmap

        /// <summary> 
        /// Construct a ColorConvertedBitmap
        /// </summary>
        /// <param name="source">Input BitmapSource to color convert</param>
        /// <param name="sourceColorContext">Source Color Context</param> 
        /// <param name="destinationColorContext">Destination Color Context</param>
        /// <param name="format">Destination Pixel format</param> 
        public ColorConvertedBitmap(BitmapSource source, ColorContext sourceColorContext, ColorContext destinationColorContext, PixelFormat format) 
            : base(true) // Use base class virtuals
        { 
            if (source == null)
            {
                throw new ArgumentNullException("source");
            } 

            if (sourceColorContext == null) 
            { 
                throw new ArgumentNullException("sourceColorContext");
            } 

            if (destinationColorContext == null)
            {
                throw new ArgumentNullException("destinationColorContext"); 
            }
 
            _bitmapInit.BeginInit(); 

            Source = source; 
            SourceColorContext = sourceColorContext;
            DestinationColorContext = destinationColorContext;
            DestinationFormat = format;
 
            _bitmapInit.EndInit();
            FinalizeCreation(); 
        } 
開發者ID:sjyanxin,項目名稱:WPFSource,代碼行數:35,代碼來源:ColorConvertedBitmap.cs

示例15: SaveBitmapSource2File

        public static void SaveBitmapSource2File(string filename, BitmapSource image5)
        {
            try
            {
                if (filename == null)
                {
                    _logger.Warn("SaveBitmapSource2File: filename is null");
                    return;
                }
                if (image5 == null)
                {
                    _logger.Error(string.Format("Survey UI: Trying to saved a null image source from file {0}", filename));
                    return;
                }

                if (filename != string.Empty)
                {
                    using (FileStream stream5 = new FileStream(filename, FileMode.Create))
                    {
                        PngBitmapEncoder encoder5 = new PngBitmapEncoder();
                        encoder5.Frames.Add(BitmapFrame.Create(image5));
                        encoder5.Save(stream5);
                        stream5.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("SaveBitmapSource2File", ex);
            }
        }
開發者ID:BoonieBear,項目名稱:TinyMetro,代碼行數:31,代碼來源:ImageUtils.cs


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