当前位置: 首页>>代码示例>>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;未经允许,请勿转载。