Пример #1
0
		public async Task Icon ()
		{
			var size = new Size (64);
			var canvas = Platforms.Current.CreateImageCanvas (size, scale: 2);
			canvas.SaveState ();
			canvas.Scale (size);
			canvas.Translate (1 / 8.0, 0);

			var p = new Path ();
			p.MoveTo (0, 1,false);
			p.LineTo (0, 0, false);
			p.LineTo (0.5, 1, false);
			p.LineTo (0.5, 0,false);

			var colors = new [] {
				"#DCDCDD",
				"#C5C3C6",
				"#46494C",
				"#4C5C68",
				"#68A5E2",
			};
			foreach (var c in colors) {
				p.Pen = new Pen (c, 1 / 4.0);
				p.Draw (canvas);
				canvas.Translate (1 / 16.0, 0);
			}
      await SaveImage (canvas, "Icon.png");
		}
Пример #2
0
 public Drawing(Size size, DrawingFunc func)
 {
     if (func == null)
     {
         throw new ArgumentNullException("func");
     }
     this.size = size;
     this.func = func;
 }
Пример #3
0
        public IImageCanvas CreateImageCanvas(Size size, double scale = 1.0, bool transparency = true)
        {
            var pixelWidth  = (int)Math.Ceiling(size.Width * scale);
            var pixelHeight = (int)Math.Ceiling(size.Height * scale);
            var format      = transparency ? PixelFormat.Format32bppPArgb : PixelFormat.Format24bppRgb;
            var bitmap      = new Bitmap(pixelWidth, pixelHeight, format);

            return(new BitmapCanvas(bitmap, scale));
        }
Пример #4
0
 public IImageCanvas CreateImageCanvas(Size size, double scale = 1.0, bool transparency = true)
 {
     var pixelWidth = (int) Math.Ceiling(size.Width*scale);
       var pixelHeight = (int) Math.Ceiling(size.Height*scale);
       var bitmap = Bitmap.CreateBitmap(pixelWidth, pixelHeight, Bitmap.Config.Argb8888);
       if (!transparency)
       {
     bitmap.EraseColor(Colors.Black.Argb);
       }
       return new BitmapCanvas(bitmap, scale);
 }
Пример #5
0
 public IImageCanvas CreateImageCanvas(Size size, double scale = 1.0, bool transparency = true)
 {
     var pixelWidth = (int)Math.Ceiling (size.Width * scale);
     var pixelHeight = (int)Math.Ceiling (size.Height * scale);
     var bitmapInfo = transparency ? CGImageAlphaInfo.PremultipliedFirst : CGImageAlphaInfo.NoneSkipFirst;
     var bitsPerComp = 8;
     var bytesPerRow = transparency ? 4 * pixelWidth : 4 * pixelWidth;
     var colorSpace = CGColorSpace.CreateDeviceRGB ();
     var bitmap = new CGBitmapContext (IntPtr.Zero, pixelWidth, pixelHeight, bitsPerComp, bytesPerRow, colorSpace, bitmapInfo);
     return new CGBitmapContextCanvas (bitmap, scale);
 }
Пример #6
0
 public static IImage CreateImage(this IPlatform platform, Func<int, int, Color> colorFunc, Size size,
     double scale = 1.0)
 {
     var w = (int) Math.Ceiling(size.Width);
     var h = (int) Math.Ceiling(size.Height);
     var colors = new Color[w*h];
     for (var y = 0; y < h; y++)
     {
         var o = y*w;
         for (var x = 0; x < w; x++)
         {
             colors[o + x] = colorFunc(x, y);
         }
     }
     return platform.CreateImage(colors, w, scale);
 }
Пример #7
0
 public CGImageImage(CGImage image, double scale)
 {
     if (image == null)
         throw new ArgumentNullException ("image");
     this.image = image;
     this.scale = scale;
     this.size = new Size (image.Width / scale, image.Height / scale);
 }
Пример #8
0
 public static void DrawRectangle(this ICanvas canvas, Point position, Size size, Pen pen = null, BaseBrush brush = null)
 {
     canvas.DrawRectangle(new Rect(position, size), pen, brush);
 }
Пример #9
0
 public static void Translate(this ICanvas canvas, Size translation)
 {
     canvas.Transform(Transform.Translate(translation));
 }
Пример #10
0
 public Rect(Point position, Size size)
     : this(position.X, position.Y, size.Width, size.Height)
 {
 }
Пример #11
0
 public void DrawImage(IImage image, Rect frame, double alpha = 1.0)
 {
     var ii = image as BitmapImage;
       if (ii != null)
       {
     var paint = GetImagePaint(alpha);
     var isize = new Size(ii.Bitmap.Width, ii.Bitmap.Height);
     var scale = frame.Size/isize;
     var m = new Matrix();
     m.PreTranslate((float) frame.X, (float) frame.Y);
     m.PreScale((float) scale.Width, (float) scale.Height);
     graphics.DrawBitmap(ii.Bitmap, m, paint);
       }
 }
Пример #12
0
 public IImageCanvas CreateImageCanvas(Size size, double scale = 1.0, bool transparency = true)
 {
     return new NullImageSurface();
 }
Пример #13
0
 public static void FillEllipse(this ICanvas canvas, Point position, Size size, Color color)
 {
     canvas.DrawEllipse(new Rect(position, size), null, new SolidBrush(color));
 }
Пример #14
0
 public static void FillEllipse(this ICanvas canvas, Point position, Size size, BaseBrush brush)
 {
     canvas.DrawEllipse(new Rect(position, size), null, brush);
 }
Пример #15
0
        private void Read(XDocument doc)
        {
            var svg = doc.Root;
              var ns = svg.Name.Namespace;

              //
              // Find the defs (gradients)
              //
              foreach (var d in svg.Descendants())
              {
            var idA = d.Attribute("id");
            if (idA != null)
            {
              defs[ReadString(idA).Trim()] = d;
            }
              }

              //
              // Get the dimensions
              //
              var widthA = svg.Attribute("width");
              var heightA = svg.Attribute("height");
              var width = _valuesParser.ReadNumber(widthA);
              var height = _valuesParser.ReadNumber(heightA);
              var size = new Size(width, height);

              var viewBox = new Rect(size);
              var viewBoxA = svg.Attribute("viewBox") ?? svg.Attribute("viewPort");
              if (viewBoxA != null)
              {
            viewBox = ReadRectangle(viewBoxA.Value);
              }

              if (widthA != null && widthA.Value.Contains("%"))
              {
            size.Width *= viewBox.Width;
              }
              if (heightA != null && heightA.Value.Contains("%"))
              {
            size.Height *= viewBox.Height;
              }

              //
              // Add the elements
              //
              Graphic = new Graphic(size, viewBox);

              AddElements(Graphic.Children, svg.Elements(), null, null);
        }
Пример #16
0
        public WICBitmapCanvas(Size size, double scale = 1.0, bool transparency = true, Direct2DFactories factories = null)
            : this(// DIPs = pixels / (DPI/96.0)
				new WIC.Bitmap ((factories ?? Direct2DFactories.Shared).WICFactory, (int)(Math.Ceiling (size.Width * scale)), (int)(Math.Ceiling (size.Height * scale)), transparency ? WIC.PixelFormat.Format32bppPBGRA : WIC.PixelFormat.Format32bppBGR, WIC.BitmapCreateCacheOption.CacheOnLoad),
				new D2D1.RenderTargetProperties (D2D1.RenderTargetType.Default, new D2D1.PixelFormat (DXGI.Format.Unknown, D2D1.AlphaMode.Unknown), (float)(96.0 * scale), (float)(96.0 * scale), D2D1.RenderTargetUsage.None, D2D1.FeatureLevel.Level_DEFAULT))
        {
        }
Пример #17
0
 public void Inflate(Size padding)
 {
     Inflate(padding.Width, padding.Height);
 }
Пример #18
0
 public Rect(Size size)
     : this(0, 0, size.Width, size.Height)
 {
 }
Пример #19
0
 public static CGSize GetCGSize(Size size)
 {
     return new CGSize ((nfloat)size.Width, (nfloat)size.Height);
 }
Пример #20
0
 public GraphicCanvas(Size size)
 {
     Graphic = new Graphic(size);
 }
Пример #21
0
 public static void Scale(this ICanvas canvas, Size scale, Point point)
 {
     if (scale.Width != 1 || scale.Height != 1)
     {
         canvas.Translate(point);
         canvas.Scale(scale);
         canvas.Translate(-point);
     }
 }
Пример #22
0
 public IImageCanvas CreateImageCanvas(Size size, double scale = 1.0, bool transparency = true)
 {
     return new WICBitmapCanvas (size, scale, transparency);
 }
Пример #23
0
 public static void StrokeEllipse(this ICanvas canvas, Point position, Size size, Color color, double width = 1.0)
 {
     canvas.DrawEllipse(new Rect(position, size), new Pen(color, width), null);
 }
Пример #24
0
 public static void Scale(this ICanvas canvas, Size scale)
 {
     if (scale.Width != 1 || scale.Height != 1)
     {
         canvas.Transform(Transform.Scale(scale));
     }
 }
Пример #25
0
 public WICBitmapCanvas(WIC.Bitmap bmp, D2D1.RenderTargetProperties properties, Direct2DFactories factories = null)
     : base(new D2D1.WicRenderTarget ((factories ?? Direct2DFactories.Shared).D2DFactory, bmp, properties), factories)
 {
     this.Bmp = bmp;
     this.scale = properties.DpiX / 96.0;
     var bmpSize = bmp.Size;
     this.size = new Size (bmpSize.Width / scale, bmpSize.Height / scale);
 }