• Drawing Images and Text


    using System;
    using UIKit;
    using Foundation;
    using CoreGraphics;
    namespace GraphicsAnimation
    {
    public class DrawnImageView : UIView
    {
    public DrawnImageView ()
    {
    BackgroundColor = UIColor.White;
    }
    public override void Draw(CGRect rect)
    {
    base.Draw (rect);
    using(var g=UIGraphics.GetCurrentContext())
    {
    g.ScaleCTM (1,-1);//画出来的图像默认是倒立的
    g.TranslateCTM (0,-Bounds.Height);
    g.DrawImage (rect,UIImage.FromFile("MyImage.png").CGImage);
    float fontSize = 35f;
    g.TranslateCTM (0,fontSize);
    g.SetLineWidth (1.0f);
    g.SetStrokeColor (UIColor.Yellow.CGColor);
    g.SetFillColor (UIColor.Red.CGColor);
    //g.SetShadow (new SizeF (5, 5), 0, UIColor.Blue.CGColor);
    g.SetShadow(new CGSize(5,5),0,UIColor.Blue.CGColor);
    g.SetTextDrawingMode (CGTextDrawingMode.FillStroke);
    g.SelectFont ("Helvetica", fontSize, CGTextEncoding.MacRoman);

    // show the text
    g.ShowText ("Hello Core Graphics");

    }
    }
    }
    }

    ————————————————

     #region View lifecycle

    public override void ViewDidLoad ()
    {
    base.ViewDidLoad ();


    DrawnImageView drawnImageView = new DrawnImageView { Frame=UIScreen.MainScreen.Bounds};
    View.AddSubview (drawnImageView);
    }
    运行结果:
  • 相关阅读:
    ls: cannot open directory .: Permission denied
    postman报错:Could not get any response
    IO流的继承关系
    吸顶效果
    linux报错:ls command not found
    内存寻址能力与CPU的位宽有关系吗?
    CPU与内存
    SQL语言的分类
    32位CPU和64位CPU 区别
    linux添加环境变量
  • 原文地址:https://www.cnblogs.com/bubugao/p/4483285.html
Copyright © 2020-2023  润新知