当前位置: 首页>>代码示例>>C#>>正文


C# WriteableBitmap.ToByteArray方法代码示例

本文整理汇总了C#中System.Windows.Media.Imaging.WriteableBitmap.ToByteArray方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.ToByteArray方法的具体用法?C# WriteableBitmap.ToByteArray怎么用?C# WriteableBitmap.ToByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.Imaging.WriteableBitmap的用法示例。


在下文中一共展示了WriteableBitmap.ToByteArray方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitMainWindow

        /// <summary>
        /// <list type="bullet">
        /// <item>
        /// <description>AuroraWindow size is suitet to the user display</description>
        /// </item>
        /// <item>
        /// <description>The rgb mask and brigthness is set to 256 default</description>
        /// </item>
        /// <item>
        /// <description>The monitorImg <see cref=""/> gets initialised in proportion to the AuroraWindow </description>
        /// </item>
        /// <item>
        /// <description>The portWindow <seealso cref=""/> is initialised and the eventhandler data changed add, which is interrupted if the connection
        /// is cancelated or startet</description>
        /// </item>
        /// <item>
        /// <description>A very important point in InitMainWindow is to set the monitorImg.Source to monitor, otherwise nothing appears on the surface</description>
        /// </item>
        /// <item>
        /// <description>The RenderOptions.SetEdgeMode(monitorImg, EdgeMode.Aliased) EdgeMode property squares the pixel and guarantes clear edges on the 68 x 42 resolution</description>
        /// </item>
        /// <item>
        /// <description>The monitorTimer.Tick event has a frequence of 40 Hz</description>
        /// </item>
        /// </list>
        /// </summary>
        public void InitMainWindow()
        {
            Point screenSize = new Point(System.Windows.SystemParameters.FullPrimaryScreenWidth, System.Windows.SystemParameters.FullPrimaryScreenHeight);
            AuroraWindow.Width = screenSize.X * 0.4;
            AuroraWindow.Height = screenSize.Y * 0.9;

            redMask = 255;
            greenMask = 255;
            blueMask = 255;
            bright = 255;

            monitorImg.Width = AuroraWindow.Width * 0.85;
            monitorImg.Height = monitorImg.Width / 1.618;

            //Das SerialportWindow initialisiern
            portWindow = new PortWindow();
            portWindow.data.Changed += new ChangedEventhandler(StatusChanged);

            //Das Rechteck für die Blit funktion festlegen
            r = new Rect(0, 0, 68, 42);

            //Writeable Bitmaps initialisiern
            monitor = BitmapFactory.New(68, 42);
            drawlayer = BitmapFactory.New(68, 42);

            monitorImg.Source = monitor;

            RenderOptions.SetBitmapScalingMode(monitorImg, BitmapScalingMode.NearestNeighbor);
            RenderOptions.SetEdgeMode(monitorImg, EdgeMode.Aliased);

            monitorTimer = new DispatcherTimer(DispatcherPriority.Render);
            monitorTimer.Interval = new TimeSpan(0, 0, 0, 0, 25);
            monitorTimer.Tick += monitorTimer_Tick;
            monitorTimer.Start();

            bitmapbuffer = new Byte[monitor.ToByteArray().Length];

            CentralMonitor.IsEnabled = false;

            runningTask = RunningTask.Effect;
            filterBitmap = BitmapFactory.New(68, 42);

            //Init Objects and Options Windows
            expandingObjects = new ExpandingObjects(monitor);
            expandingObjectsWindow = new ExpandingObjectsOptionsWindow(expandingObjects);
            movingText = new MovingText(monitor);
            movingTextOptionWindow = new MovingTextOptionsWindow(movingText);
            plasma = new Plasma(monitor);
            plasmaOptionWindow = new PlasmaOptionsWindow(plasma);
            colorGradient = new ColorGradient(monitor);
            gradientOptionWindow = new GradientColorOptionsWindow(colorGradient);
            StickyWindow.RegisterExternalReferenceForm(this);

            //Bluetooth Event listening
            RgbLibrary.Bluetooth.Instance.CommandControlChange += new Bluetooth.PropertyChangeHandler(Bluetooth_Command_Listener);
        }
开发者ID:BI-LedTable,项目名称:LedTable,代码行数:82,代码来源:MainWindow.xaml.cs

示例2: ColourImages

		private void ColourImages()
		{
			BitmapImage vertical = new BitmapImage();
			vertical.BeginInit();
			vertical.UriSource = new Uri(@"images\BikeVertical.png", UriKind.Relative);
			vertical.EndInit();

			vert= new WriteableBitmap(vertical);
			byte[] vData = vert.ToByteArray();


			for (int i = 0; i < vData.Length; i= i + 4 )
			{

				if (vData[i] == 255 && vData[i + 1] == 255 && vData[i + 2] == 255)
				{
					vData[i] = ((SolidColorBrush)bikeColour).Color.B;
					vData[i + 1] = ((SolidColorBrush)bikeColour).Color.G;
					vData[i + 2] = ((SolidColorBrush)bikeColour).Color.R;
				}
				else if (vData[i] == 0xd4 && vData[i + 1] == 0xd4 && vData[i + 2] == 0xd4)
				{
					double scale = ((double)0xd4) / 0xFF;
					vData[i] = (byte)(((SolidColorBrush)bikeColour).Color.B * scale);
					vData[i + 1] = (byte)(((SolidColorBrush)bikeColour).Color.G * scale);
					vData[i + 2] = (byte)(((SolidColorBrush)bikeColour).Color.R * scale);
				}
			}

			vert.FromByteArray(vData);



			BitmapImage horizontal = new BitmapImage();
			horizontal.BeginInit();
			horizontal.UriSource = new Uri(@"images\BikeHorizontal.png", UriKind.Relative);
			horizontal.EndInit();


			hor = new WriteableBitmap(horizontal);
			byte[] hData = hor.ToByteArray();


			for (int i = 0; i < hData.Length; i = i + 4)
			{

				if (hData[i] == 0xFF && hData[i + 1] == 0xFF && hData[i + 2] == 0xFF)
				{
					hData[i] = ((SolidColorBrush)bikeColour).Color.B;
					hData[i + 1] = ((SolidColorBrush)bikeColour).Color.G;
					hData[i + 2] = ((SolidColorBrush)bikeColour).Color.R;
				}
				else if (hData[i] == 0xd4 && hData[i + 1] == 0xd4 && hData[i + 2] == 0xd4)
				{
					double scale = ((double)0xd4) / 0xFF;
					hData[i] = (byte)(((SolidColorBrush)bikeColour).Color.B*scale);
					hData[i + 1] = (byte)(((SolidColorBrush)bikeColour).Color.G * scale);
					hData[i + 2] = (byte)(((SolidColorBrush)bikeColour).Color.R * scale);
				}
			}

			hor.FromByteArray(hData);

		}
开发者ID:GregWard,项目名称:Tronsformers,代码行数:64,代码来源:TronBike.cs

示例3: Colorize

        public static WriteableBitmap Colorize(WriteableBitmap b, int red, int green, int blue, ColorArea ca)
        {
            if (red < -255 || red > 255) throw new ArgumentException("Red must be between -255 and +255");
            if (green < -255 || green > 255) throw new ArgumentException("Green must be between -255 and +255");
            if (blue < -255 || blue > 255) throw new ArgumentException("Blue must be between -255 and +255");

            int stride = b.PixelWidth * 4;  //The pixelformat for brga32 is 32 bits - so that's 4 bytes per pixel
            int bytes = Math.Abs(stride) * b.PixelHeight;

            byte[] p = b.ToByteArray();

            int i = 0;

            int nOffset = stride - b.PixelWidth * 4;

            for (int y = 0; y < b.PixelHeight; ++y)
            {
                for (int x = 0; x < b.PixelWidth; ++x)
                {
                    int pdif = (p[i + 2] + p[i + 1] + p[i]) / 3;

                    int newred = p[i + 2];
                    int newgreen = p[i + 1];
                    int newblue = p[i];

                    switch (ca)
                    {
                        case ColorArea.Shadows:
                            float multi = (1 - newred / 255);
                            newred += (int)(red * multi);

                            multi = (1 - newgreen / 255);
                            newgreen += (int)(green * multi);

                            multi = (1 - newblue / 255);
                            newblue += (int)(blue * multi);
                            break;

                        case ColorArea.Highlights:
                            float hmulti = (newred / 255);
                            newred += (int)(red * hmulti);

                            hmulti = (newgreen / 255);
                            newgreen += (int)(green * hmulti);

                            hmulti = (newblue / 255);
                            newblue += (int)(blue * hmulti);
                            break;

                        case ColorArea.Midtones:
                            float mmulti = 0;

                            mmulti = (newred > 127) ? 127f / newred : newred / 127f;
                            newred += (int)(red * mmulti);

                            mmulti = (newgreen > 127) ? 127f / newgreen : newgreen / 127f;
                            newgreen += (int)(green * mmulti);

                            mmulti = (newblue > 127) ? 127f / newblue : newblue / 127f;
                            newblue += (int)(blue * mmulti);

                            break;
                    }

                    p[i + 2] = (byte)Math.Min(255, Math.Max(newred, 0));
                    p[i + 1] = (byte)Math.Min(255, Math.Max(newgreen, 0));
                    p[i + 0] = (byte)Math.Min(255, Math.Max(newblue, 0));

                    i += 4;
                }
                i += nOffset;
            }

            WriteableBitmap finalImg = new WriteableBitmap(b.PixelWidth, b.PixelHeight);
            return finalImg.FromByteArray(p);
        }
开发者ID:rafal366,项目名称:CameraGuard,代码行数:76,代码来源:imageFilters.cs

示例4: SCurve

        public static WriteableBitmap SCurve(WriteableBitmap b)
        {
            int stride = b.PixelWidth * 4; //brga32 is 32
            int bytes = Math.Abs(stride) * b.PixelHeight;

            byte[] p = b.ToByteArray();

            int i = 0;

            int nOffset = stride - b.PixelWidth * 4;

            Point[] points = GetCoordinates();

            for (int y = 0; y < b.PixelHeight; ++y)
            {
                for (int x = 0; x < b.PixelWidth; ++x)
                {
                    int hue = p[i];     //if pi = 255 then 255, otherwise -1   (so if pi = -1,  its ! 255,  NOT max)
                    int hue1 = p[i + 1];
                    int hue2 = p[i + 2];

                    foreach (var point in points)
                    {
                        if (hue != 255 && hue1 != 255 && hue2 != 255)
                        {
                            //white pixel - no processing necessary
                            break;
                        }
                        if (point.X >= p[i + 2] && hue2 != 255)    //translate this to a function for the curve
                            hue2 = (int)point.Y;

                        if (point.X >= p[i + 1] && hue1 != 255)
                            hue1 = (int)point.Y;

                        if (point.X >= p[i] && hue != 255)
                            hue = (int)point.Y;
                    }

                    p[i + 2] = (byte)Math.Min(255, Math.Max(hue2, 0));
                    p[i + 1] = (byte)Math.Min(255, Math.Max(hue1, 0));
                    p[i + 0] = (byte)Math.Min(255, Math.Max(hue, 0));

                    i += 4;
                }
                i += nOffset;
            }

            WriteableBitmap finalImg = new WriteableBitmap(b.PixelWidth, b.PixelHeight);
            return finalImg.FromByteArray(p);

            //return true;
        }
开发者ID:rafal366,项目名称:CameraGuard,代码行数:52,代码来源:imageFilters.cs

示例5: Contrast

        public static WriteableBitmap Contrast(WriteableBitmap b, int nContrast)
        {
            if (nContrast < -100 || nContrast > 100)
            {
                throw new ArgumentException("Contrast must be between -100 and 100");
            }

            double contrast = (100.0 + nContrast) / 100.0;
            contrast *= contrast;

            int stride = b.PixelWidth * 4; //brga32 is 32
            int bytes = Math.Abs(stride) * b.PixelHeight;

            byte[] p = b.ToByteArray();

            int i = 0;

            int nOffset = stride - b.PixelWidth * 4;

            for (int y = 0; y < b.PixelHeight; ++y)
            {
                for (int x = 0; x < b.PixelWidth; ++x)
                {
                    p[i + 2] = ApplyContrast(p[i + 2], contrast);
                    p[i + 1] = ApplyContrast(p[i + 1], contrast);
                    p[i + 0] = ApplyContrast(p[i + 0], contrast);

                    i += 4;
                }
                i += nOffset;
            }

            WriteableBitmap finalImg = new WriteableBitmap(b.PixelWidth, b.PixelHeight);
            return finalImg.FromByteArray(p);
        }
开发者ID:rafal366,项目名称:CameraGuard,代码行数:35,代码来源:imageFilters.cs

示例6: OnCreateAndUploadImage

        public void OnCreateAndUploadImage(object obj)
        {
            EA.GetEvent<SetCompositionWidthHeight>().Publish(string.Empty);

            var document = HtmlPage.Document;
            var txtArea = document.GetElementById("MainContent_txtPNGBytes");

            if (txtArea != null)
            {
                try
                {
                    const double scale = 1;

                    var bmp = new WriteableBitmap(CompositionGrid, null);
                    var buffer = bmp.ToByteArray();

                    bmp = new WriteableBitmap(int.Parse(Width.ToString()), int.Parse(Height.ToString()));
                    bmp.FromByteArray(buffer);

                    var transform = new ScaleTransform();
                    transform.ScaleX = scale;
                    transform.ScaleY = scale;

                    bmp.Render(CompositionGrid, (Transform)transform);
                    bmp.Invalidate();

                    var stream = bmp.GetStream();
                    var binaryData = new Byte[stream.Length];
                    var bytesRead = stream.Read(binaryData, 0, (int)stream.Length);
                    var base64 = Convert.ToBase64String(binaryData, 0, binaryData.Length);

                    RawSize = base64.Length.ToString();
                    Message message = Composer.Messaging.Compression.Compress(base64);
                    base64 = message.Text;
                    CompressedSize = base64.Length.ToString();
                    txtArea.SetProperty("value", base64);

                    UploadDetailsVisibility = Visibility.Visible;

                    SendImage();
                }
                catch (Exception ex)
                {
                    Exceptions.HandleException(ex, "Error in: OnCreateAndUploadImage");
                }
            }
        }
开发者ID:jwh5293,项目名称:Composer,代码行数:47,代码来源:CompositionViewModel.cs

示例7: invert_Click

        private void invert_Click(object sender, EventArgs e)
        {
            ExtendedImage loadedImage;
            ExtendedImage filteredImage;
            Inverter filter;

            WriteableBitmap wb = new WriteableBitmap(image);
            loadedImage = new ExtendedImage();
            loadedImage.SetPixels(image.PixelWidth, image.PixelHeight, wb.ToByteArray());
            filter = new Inverter();
            filteredImage = new ExtendedImage(loadedImage);
            filter.Apply(filteredImage, loadedImage, new ImageTools.Rectangle(0, 0, loadedImage.PixelWidth, loadedImage.PixelHeight));
            var bitmap = filteredImage.ToBitmap();
            imageView.Source = bitmap;
        }
开发者ID:UWbadgers16,项目名称:PhotoEnhancement,代码行数:15,代码来源:FullView.xaml.cs


注:本文中的System.Windows.Media.Imaging.WriteableBitmap.ToByteArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。