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


C# Imaging.WriteableBitmap類代碼示例

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


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

示例1: Create

        public static Uri Create(string filename, string text, SolidColorBrush backgroundColor, double textSize, Size size)
        {
            var background = new Rectangle();
            background.Width = size.Width;
            background.Height = size.Height;
            background.Fill = backgroundColor;

            var textBlock = new TextBlock();
            textBlock.Width = 500;
            textBlock.Height = 500;
            textBlock.TextWrapping = TextWrapping.Wrap;
            textBlock.Text = text;
            textBlock.FontSize = textSize;
            textBlock.Foreground = new SolidColorBrush(Colors.White);
            textBlock.FontFamily = new FontFamily("Segoe WP");

            var tileImage = "/Shared/ShellContent/" + filename;
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                var bitmap = new WriteableBitmap((int)size.Width, (int)size.Height);
                bitmap.Render(background, new TranslateTransform());
                bitmap.Render(textBlock, new TranslateTransform() { X = 39, Y = 88 });
                var stream = store.CreateFile(tileImage);
                bitmap.Invalidate();
                bitmap.SaveJpeg(stream, (int)size.Width, (int)size.Height, 0, 99);
                stream.Close();
            }
            return new Uri("ms-appdata:///local" + tileImage, UriKind.Absolute);
        }
開發者ID:halllo,項目名稱:DailyQuote,代碼行數:29,代碼來源:LockScreenImage.cs

示例2: Render

        private void Render(DrawingContext drawingContext)
        {
            if (_width > 0 && _height > 0)
            {
                if (_bitmap == null || _bitmap.Width != _width || _bitmap.Height != _height)
                {
                    _bitmap = new WriteableBitmap(_width, _height, 96, 96, PixelFormats.Pbgra32, null);
                }

                _bitmap.Lock();
                using (var surface = SKSurface.Create(_width, _height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, _bitmap.BackBuffer, _bitmap.BackBufferStride))
                {
                    var canvas = surface.Canvas;
                    canvas.Scale((float)_dpiX, (float)_dpiY);
                    canvas.Clear();
                    using (new SKAutoCanvasRestore(canvas, true))
                    {
                        Presenter.Render(canvas, Renderer, Container, _offsetX, _offsetY);
                    }
                }
                _bitmap.AddDirtyRect(new Int32Rect(0, 0, _width, _height));
                _bitmap.Unlock();

                drawingContext.DrawImage(_bitmap, new Rect(0, 0, _actualWidth, _actualHeight));
            }
        }
開發者ID:Core2D,項目名稱:Core2D,代碼行數:26,代碼來源:SkiaView.cs

示例3: SaveTileBackgroundImage

        private static void SaveTileBackgroundImage(TileViewModel model)
        {
            string xamlCode;

            using (var tileStream = Application.GetResourceStream(new Uri("/WP7LiveTileDemo;component/Controls/CustomTile.xaml", UriKind.Relative)).Stream)
            {
                using (var reader = new StreamReader(tileStream))
                {
                    xamlCode = reader.ReadToEnd();
                }
            }

            var control = (Control)XamlReader.Load(xamlCode);
            control.DataContext = model;

            var bitmap = new WriteableBitmap(173, 173);

            bitmap.Render(control, new TranslateTransform());

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var stream = store.CreateFile(TileBackgroundPath))
                {
                    bitmap.Invalidate();
                    bitmap.SaveJpeg(stream, 173, 173, 0, 100);
                    stream.Close();
                }
            }
        }
開發者ID:danclarke,項目名稱:WP7LiveTileDemo,代碼行數:29,代碼來源:TileUtil.cs

示例4: RenderTargetImageSource

 /// <summary>
 /// Creates a new RenderTargetImageSource.
 /// </summary>
 /// <param name="graphics">The GraphicsDevice to use.</param>
 /// <param name="width">The width of the image source.</param>
 /// <param name="height">The height of the image source.</param>
 public RenderTargetImageSource(GraphicsDevice graphics, int width, int height)
 {
     // create the render target and buffer to hold the data
     renderTarget = new RenderTarget2D(graphics, width, height, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);
     buffer = new byte[width * height * 4];
     writeableBitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgra32, null);
 }
開發者ID:LoveDuckie,項目名稱:MerjTek.WpfIntegration,代碼行數:13,代碼來源:RenderTargetImageSource.cs

示例5: CaptureImageCompletedEventArgs

        public CaptureImageCompletedEventArgs (WriteableBitmap image)
            : base (null, false, null)
        {
            // Note: When this is implemented a native peer will have to be created.
            Console.WriteLine ("NIEX: System.Windows.Media.CaptureImageCompletedEventArgs:.ctor");
            throw new NotImplementedException ();
        }
開發者ID:dfr0,項目名稱:moon,代碼行數:7,代碼來源:CaptureImageCompletedEventArgs.cs

示例6: ToBitmap

        /// <summary>
        /// Converts a color frame to a System.Media.Imaging.BitmapSource.
        /// </summary>
        /// <param name="frame">The specified color frame.</param>
        /// <returns>The specified frame in a System.Media.Imaging.BitmapSource representation of the color frame.</returns>
        public static BitmapSource ToBitmap(this ColorFrame frame)
        {
            if (_bitmap == null)
            {
                _width = frame.FrameDescription.Width;
                _height = frame.FrameDescription.Height;
                _pixels = new byte[_width * _height * Constants.BYTES_PER_PIXEL];
                _bitmap = new WriteableBitmap(_width, _height, Constants.DPI, Constants.DPI, Constants.FORMAT, null);
            }

            if (frame.RawColorImageFormat == ColorImageFormat.Bgra)
            {
                frame.CopyRawFrameDataToArray(_pixels);
            }
            else
            {
                frame.CopyConvertedFrameDataToArray(_pixels, ColorImageFormat.Bgra);
            }

            _bitmap.Lock();

            Marshal.Copy(_pixels, 0, _bitmap.BackBuffer, _pixels.Length);
            _bitmap.AddDirtyRect(new Int32Rect(0, 0, _width, _height));

            _bitmap.Unlock();

            return _bitmap;
        }
開發者ID:TrashTonyLin,項目名稱:Two-Kinect-Measurement,代碼行數:33,代碼來源:ColorExtensions.cs

示例7: plotButton_click

        private void plotButton_click(object sender, RoutedEventArgs e)
        {
            if (graphBitmap == null)
            {
                graphBitmap = new WriteableBitmap(pixelWidth, pixelHeight, dpiX, dpiY, PixelFormats.Gray8, null);
            }
            Action doPlotButtonWorkAction = new Action(doPlotButtonWork);
            doPlotButtonWorkAction.BeginInvoke(null, null);
            #region 注釋掉的內容
            //int byetePerPixel = (graphBitmap.Format.BitsPerPixel + 7) / 8;
            //int stride = byetePerPixel * graphBitmap.PixelWidth;
            //int dataSize = stride * graphBitmap.PixelHeight;
            //byte[] data = new byte[dataSize];

            //Stopwatch watch = new Stopwatch();

            ////generateGraphData(data);
            ////新建線程
            //Task first = Task.Factory.StartNew(()=>generateGraphData(data,0,pixelWidth/8));
            //Task second = Task.Factory.StartNew(() => generateGraphData(data, pixelWidth / 8, pixelWidth / 4));
            //Task first1 = Task.Factory.StartNew(() => generateGraphData(data, pixelWidth / 4, pixelWidth / 2));
            //Task second1 = Task.Factory.StartNew(() => generateGraphData(data, pixelWidth / 2, pixelWidth));
            //Task.WaitAll(first, second,first1,second1);
            //duration.Content = string.Format("Duration (ms):{0}", watch.ElapsedMilliseconds);
            //graphBitmap.WritePixels(new Int32Rect(0, 0, graphBitmap.PixelWidth, graphBitmap.PixelHeight), data, stride, 0);
            //graphImage.Source = graphBitmap;
            #endregion
        }
開發者ID:red201432,項目名稱:CSharpLearn,代碼行數:28,代碼來源:MainWindow.xaml.cs

示例8: DecodeJpeg

        public static WriteableBitmap DecodeJpeg(Stream srcStream)
        {
            // Decode JPEG
            var decoder = new FluxJpeg.Core.Decoder.JpegDecoder(srcStream);
            var jpegDecoded = decoder.Decode();
            var img = jpegDecoded.Image;
            img.ChangeColorSpace(ColorSpace.RGB);

            // Init Buffer
            int w = img.Width;
            int h = img.Height;
            var result = new WriteableBitmap(w, h);
            int[] p = result.Pixels;
            byte[][,] pixelsFromJpeg = img.Raster;

            // Copy FluxJpeg buffer into WriteableBitmap
            int i = 0;
            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    p[i++] = (0xFF << 24) // A
                                | (pixelsFromJpeg[0][x, y] << 16) // R
                                | (pixelsFromJpeg[1][x, y] << 8)  // G
                                | pixelsFromJpeg[2][x, y];       // B
                }
            }

            return result;
        }
開發者ID:Vinna,項目名稱:DeepInSummer,代碼行數:30,代碼來源:JpegHelper.cs

示例9: Update

        public void Update(ImageFrameReadyEventArgs e)
        {
            if (depthFrame32 == null)
            {
                depthFrame32 = new byte[e.ImageFrame.Image.Width * e.ImageFrame.Image.Height * 4];
            }

            ConvertDepthFrame(e.ImageFrame.Image.Bits);

            if (DepthBitmap == null)
            {
                DepthBitmap = new WriteableBitmap(e.ImageFrame.Image.Width, e.ImageFrame.Image.Height, 96, 96, PixelFormats.Bgra32, null);
            }

            DepthBitmap.Lock();

            int stride = DepthBitmap.PixelWidth * DepthBitmap.Format.BitsPerPixel / 8;
            Int32Rect dirtyRect = new Int32Rect(0, 0, DepthBitmap.PixelWidth, DepthBitmap.PixelHeight);
            DepthBitmap.WritePixels(dirtyRect, depthFrame32, stride, 0);

            DepthBitmap.AddDirtyRect(dirtyRect);
            DepthBitmap.Unlock();

            RaisePropertyChanged(()=>DepthBitmap);
        }
開發者ID:klosejiang,項目名稱:Magic-Hands,代碼行數:25,代碼來源:DepthStreamManager.cs

示例10: DoCapture

        public byte[] DoCapture()
        {
            FrameworkElement toSnap = null;
            
            if (!AutomationIdIsEmpty)
                toSnap = GetFrameworkElement(false);

            if (toSnap == null)
                toSnap = AutomationElementFinder.GetRootVisual();

            if (toSnap == null)
                return null;

            // Save to bitmap
            var bmp = new WriteableBitmap((int)toSnap.ActualWidth, (int)toSnap.ActualHeight);
            bmp.Render(toSnap, null);
            bmp.Invalidate();

            // Get memoryStream from bitmap
            using (var memoryStream = new MemoryStream())
            {
                bmp.SaveJpeg(memoryStream, bmp.PixelWidth, bmp.PixelHeight, 0, 95);
                memoryStream.Seek(0, SeekOrigin.Begin);
                return memoryStream.GetBuffer();
            }
        }
開發者ID:Expensify,項目名稱:WindowsPhoneTestFramework,代碼行數:26,代碼來源:TakePictureCommand.cs

示例11: GeneratePicture

        async void GeneratePicture()
        {
            if (rendering) return;


            ProgressIndicator prog = new ProgressIndicator();
            prog.IsIndeterminate = true;
            prog.Text = "Rendering";
            prog.IsVisible = true;
            SystemTray.SetProgressIndicator(this, prog);



            var bmp = new WriteableBitmap(480, 800);
            try
            {
                rendering = true;

             
              
                using (var renderer = new WriteableBitmapRenderer(manager, bmp, OutputOption.PreserveAspectRatio))
                {
                    display.Source = await renderer.RenderAsync();
                }

                SystemTray.SetProgressIndicator(this, null);
                rendering = false;
            }
            finally
            {
               
            }


        }
開發者ID:Nokia-Developer-Community-Projects,項目名稱:wp8-sample,代碼行數:35,代碼來源:MainPage.xaml.cs

示例12: UpdateTiledImage

        void UpdateTiledImage() {
            if(sourceBitmap == null)
                return;

            var width = (int)Math.Ceiling(ActualWidth);
            var height = (int)Math.Ceiling(ActualHeight);

            // only regenerate the image if the width/height has grown
            if(width < lastWidth && height < lastHeight)
                return;
            lastWidth = width;
            lastHeight = height;

            var final = new WriteableBitmap(width, height);

            for(var x = 0; x < final.PixelWidth; x++) {
                for(var y = 0; y < final.PixelHeight; y++) {
                    var tiledX = (x % sourceBitmap.PixelWidth);
                    var tiledY = (y % sourceBitmap.PixelHeight);
                    final.Pixels[y * final.PixelWidth + x] = sourceBitmap.Pixels[tiledY * sourceBitmap.PixelWidth + tiledX];
                }
            }

            tiledImage.Source = final;
        }
開發者ID:CrazyBBer,項目名稱:Caliburn.Micro.Learn,代碼行數:25,代碼來源:TiledBackground.cs

示例13: RecordedVideoFrame

        public RecordedVideoFrame(ColorImageFrame colorFrame)
        {
            if (colorFrame != null)
            {
                byte[] bits = new byte[colorFrame.PixelDataLength];
                colorFrame.CopyPixelDataTo(bits);

                int BytesPerPixel = colorFrame.BytesPerPixel;
                int Width = colorFrame.Width;
                int Height = colorFrame.Height;

                var bmp = new WriteableBitmap(Width, Height, 96, 96, PixelFormats.Bgr32, null);
                bmp.WritePixels(new System.Windows.Int32Rect(0, 0, Width, Height), bits, Width * BytesPerPixel, 0);
                JpegBitmapEncoder jpeg = new JpegBitmapEncoder();
                jpeg.Frames.Add(BitmapFrame.Create(bmp));
                var SaveStream = new MemoryStream();
                jpeg.Save(SaveStream);
                SaveStream.Flush();
                JpegData = SaveStream.ToArray();
            }
            else
            {
                return;
            }
        }
開發者ID:pi11e,項目名稱:KinectHTML5,代碼行數:25,代碼來源:RecordedVideoFrame.cs

示例14: GetPngStream

        Stream GetPngStream(WriteableBitmap bmp)
        {
            // Use Joe Stegman's PNG Encoder
            // http://bit.ly/77mDsv
            EditableImage imageData = new EditableImage(bmp.PixelWidth, bmp.PixelHeight);

            for (int y = 0; y < bmp.PixelHeight; ++y)
            {
                for (int x = 0; x < bmp.PixelWidth; ++x)
                {

                    int pixel = bmp.Pixels[bmp.PixelWidth * y + x];

                    imageData.SetPixel(x, y,
                                (byte)((pixel >> 16) & 0xFF),
                                (byte)((pixel >> 8) & 0xFF),
                                (byte)(pixel & 0xFF),
                                (byte)((pixel >> 24) & 0xFF)
                                );

                }
            }

            return imageData.GetStream();
        }
開發者ID:EdmilsonFernandes,項目名稱:edm-azuli-condominio,代碼行數:25,代碼來源:MainPage.xaml.cs

示例15: GetRequestStreamCallback

        void GetRequestStreamCallback(IAsyncResult callbackResult)
        {
            HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState;
            // End the stream request operation
            Stream postStream = myRequest.EndGetRequestStream(callbackResult);
            var settings = IsolatedStorageSettings.ApplicationSettings;
            String token ="";
            if (settings.Contains("tokken"))
            {
                token = settings["tokken"].ToString();
            }
            // Create the post data
            string postData = "tokken=" + token + "&attrId=30";

               MemoryStream ms = new MemoryStream();
            WriteableBitmap btmMap = new WriteableBitmap(photo.PixelWidth,photo.PixelHeight);

            // write an image into the stream
            Extensions.SaveJpeg(btmMap, ms,
            photo.PixelWidth, photo.PixelHeight, 0, 100);

            //this.WriteEntry(postStream, "image",ms.ToArray());
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            // Add the post data to the web request
            postStream.Write(byteArray, 0, byteArray.Length);
            postStream.Close();

            // Start the web request
            myRequest.BeginGetResponse(new AsyncCallback(GetResponsetStreamCallback), myRequest);
        }
開發者ID:marcin-owoc,項目名稱:TouristGuide,代碼行數:31,代碼來源:CapturingPhoto.xaml.cs


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