using System; using System.Collections.Generic; using System.Drawing; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; 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; namespace Captcha { /// /// Логика взаимодействия для MainWindow.xaml /// public partial class MainWindow : Window { private Bitmap bitmap = new Bitmap(100, 100); private string cd = string.Empty; public MainWindow() { InitializeComponent(); cd = "553Fa"; SetBtm(100, 100); } private void SetBtm(int w, int h) { var random = new Random(); var pixels = new byte[256 * 256 * 4]; random.NextBytes(pixels); BitmapSource bitmapSource = BitmapSource.Create(256, 256, 96, 96, PixelFormats.Bgra32, null, pixels, 256 * 4); var visual = new DrawingVisual(); using (DrawingContext drawingContext = visual.RenderOpen()) { drawingContext.DrawText( new FormattedText("Hi!", CultureInfo.InvariantCulture, FlowDirection.LeftToRight, new Typeface("Segoe UI"), 132, System.Windows.Media.Brushes.Black), new System.Windows.Point(0, 0)); drawingContext.DrawImage(bitmapSource, new Rect(0, 0, 256, 256)); } var image = new DrawingImage(visual.Drawing); grf.Source = image; } } }