国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

關于WPF WriteableBitmap類直接操作像素點的問題

瀏覽:225日期:2022-06-04 15:34:15

WPF(Windows Presentation Foundation)是微軟推出的基于Windows 的用戶界面框架,屬于.NET Framework 3.0的一部分。它提供了統一的編程模型、語言和框架,真正做到了分離界面設計人員與開發人員的工作;同時它提供了全新的多媒體交互用戶圖形界面。

還是話不多說,直接上碼:

1.新建WpfApp應用程序

2.MainWindow.xaml文件代碼如下:

<Window x:Class="WpfApp1.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:WpfApp1"mc:Ignorable="d"Title="MainWindow" Height="450" Width="800">    <Grid><Grid.RowDefinitions>    <RowDefinition Height="*"></RowDefinition>    <RowDefinition Height="10*" ></RowDefinition></Grid.RowDefinitions> <Button Name="button" Grid.Row="0" HorizontalAlignment="Center" Content="generate_bitmap" MinWidth="120"  MinHeight="30" Click="Button_Click"></Button><Grid x:Name="imgGrid" Grid.Row="1">    <Viewbox><Image x:Name="img"  Width="{Binding RelativeSource={RelativeSource Self}, Path=Source.PixelWidth}"       Height="{Binding RelativeSource={RelativeSource Self}, Path=Source.PixelHeight}"Source="{Binding CtrlImage, IsAsync=True}"      Stretch="None" />    </Viewbox></Grid>    </Grid></Window>

3.MainWindow.xaml.cs文件代碼如下:

using System;using System.Collections.Generic;using System.Globalization;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;using System.Drawing;using System.Drawing.Drawing2D; namespace WpfApp1{    /// <summary>    /// Interaction logic for MainWindow.xaml    /// </summary>    public partial class MainWindow : Window    {public MainWindow(){    InitializeComponent();}public void Button_Click(object sender, RoutedEventArgs e)    WriteableBitmap wb = new WriteableBitmap((int)imgGrid.ActualWidth, (int)imgGrid.ActualHeight, 96, 96, PixelFormats.Pbgra32, null);    wb.Lock();    Bitmap backBitmap = new Bitmap((int)imgGrid.ActualWidth, (int)imgGrid.ActualHeight, wb.BackBufferStride, System.Drawing.Imaging.PixelFormat.Format32bppArgb, wb.BackBuffer);    Int32Rect rect = new Int32Rect(0, 0, (int)imgGrid.ActualWidth, (int)imgGrid.ActualHeight);    byte[] pixels = new byte[(int)imgGrid.ActualWidth * (int)imgGrid.ActualHeight * wb.Format.BitsPerPixel / 8];    Random rand = new Random();    for (int y = 0; y < wb.PixelHeight; y++)    {for (int x = 0; x < wb.PixelWidth; x++){    int alpha = 0;    int red = 0;    int green = 0;    int blue = 0;    if ((x % 5 == 0) || (y % 7 == 0))    {red = (int)((double)y / wb.PixelHeight * 255);green = rand.Next(100, 255);blue = (int)((double)x / wb.PixelWidth * 255);alpha = 255;    }    elsered = (int)((double)x / wb.PixelWidth * 255);blue = (int)((double)y / wb.PixelHeight * 255);alpha = 50;    int pixeloffset = (x + y * wb.PixelWidth) * wb.Format.BitsPerPixel / 8;    pixels[pixeloffset] = (byte)blue;    pixels[pixeloffset + 1] = (byte)green;    pixels[pixeloffset + 2] = (byte)red;    pixels[pixeloffset + 3] = (byte)alpha;}int stride = (wb.PixelWidth * wb.Format.BitsPerPixel) / 8;wb.WritePixels(rect, pixels, stride, 0);    }    wb.Unlock();    backBitmap.Dispose();    backBitmap = null;    img.Source = wb;    }}

  效果如下:

到此這篇關于C#中WPF WriteableBitmap類直接操作像素點的文章就介紹到這了,更多相關WPF WriteableBitmap類內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持!

標簽: ASP
主站蜘蛛池模板: 免费永久国产在线视频 | 黄色毛片免费 | yellow中文字幕久久网 | 视频一区久久 | 国产视频久 | 成人三级视频 | 精品自拍视频在线观看 | 中文字幕毛片 | 999国产精品亚洲77777 | 久草视频官网 | 久久成人网18网站 | 精品国产91久久久久久久 | 一级欧美在线的视频 | 亚洲欧美高清视频 | 91久热| 亚洲一区二区三区免费观看 | 日本人成在线视频免费播放 | 欧美一级毛片aaa片 欧美一级毛片不卡免费观看 | 91久久国产视频 | 精品日韩欧美 | 国产aaa级一级毛片 国产aaa毛片 | 欧美变态一级毛片 | www.夜夜骑.com | 另类亚洲孕妇分娩网址 | a在线v| 成人国产在线视频在线观看 | 久热免费在线观看 | 美女一级片 | 看片日韩| 久久免费视频在线观看30 | 日本在线免费观看视频 | 欧美一级视频 | 免费看欧美一级特黄a毛片 免费看片aⅴ免费大片 | 日本一二线不卡在线观看 | 亚洲三级小视频 | 台湾三级毛片 | 国产精品久久久影院 | 99视频在线国产 | 99久久99久久精品免费看子伦 | 色综合久久久久久888 | 日本黄色免费大片 |