zoukankan      html  css  js  c++  java
  • WPF create Flower shape

    using System;
    using System.Collections.Generic;
    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 WpfMosaic
    {
        /// <summary>
        /// Interaction logic for FlowerShape.xaml
        /// </summary>
        public class FlowerShape : Grid
        {
            /// <summary>
            /// 
            /// </summary>
            /// <param name="count"></param>
            public FlowerShape(int count)
            {
                Width = Height = 100;
                Background = new SolidColorBrush(Colors.Black);
                var strokeBrush= new SolidColorBrush(Colors.White);
                this.Children.Clear();
                var bg = new SolidColorBrush(Color.FromArgb(255, (byte)Utils.rnd.Next(0, 256), (byte)Utils.rnd.Next(0, 256), (byte)Utils.rnd.Next(0, 256)));
                var width = Utils.rnd.Next(10, 51);
                for (int i = 0; i < count; i++)
                {
                    var angle = i * (360 / count);
                    var transGroup = new TransformGroup();
                    transGroup.Children.Add(new RotateTransform() { Angle = angle });
                    this.Children.Add(new Ellipse()
                    { 
                        StrokeThickness = 1, Stroke = strokeBrush,
                        Margin = new Thickness(0, 0, 0, 50),
                        Fill = bg,
                        Width = width,
                        RenderTransformOrigin = new Point(0.5, 1)
                        ,
                        RenderTransform = transGroup
    
                    }); ; ; ;
    
                }
    
            }
    
    
    
        }
    }
    

      

     void TesCreateShapes() {
    
                canvas.Children.Clear();
                for (int i = 0; i < 100; i++)
                {
                    var shap = new FlowerShape(12){ };
                    canvas.Children.Add(shap );
                }
               canvas.UpdateLayout();
                return;
                foreach (FrameworkElement shap in canvas.Children)
                {
                    UISaveToPng(shap, @"C:UsersgwangPicturesMosaic" + DateTime.Now.ToFileTime() + ".png");
                }
                Title = "done.";
            
            }
    
    
    
    
           void UISaveToPng(FrameworkElement ui, string fileName)
            {
              
                int width = (int)ui.ActualWidth;
                int height = (int)ui.ActualHeight;
                RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, 96d, 96d, PixelFormats.Pbgra32);
                bmp.Render(ui);
                PngBitmapEncoder encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bmp));
                using (FileStream fs = new FileStream(fileName, FileMode.Create))
                {
                    encoder.Save(fs);
                    fs.Close();
                }
            }
    

      

    fffffffffffffffff
    test red font.
  • 相关阅读:
    LeetCode:1_Two_Sum | 两个元素相加等于目标元素 | Medium
    算法导论第十章 栈队列和链表
    算法导论2-9章补充几道题
    算法导论第九章中位数和顺序统计量(选择问题)
    算法导论第八章线性时间排序
    算法导论第七章快速排序
    算法导论第六章优先队列(二)
    算法导论第六章堆排序(一)
    mysql中查看视图的元数据?
    mysql中,什么是视图,视图的作用是什么?
  • 原文地址:https://www.cnblogs.com/wgscd/p/15080631.html
Copyright © 2011-2022 走看看