一种基于重载的高效c#上图片添加文字图形图片的方法

在做图片监控显示的时候,需要在图片上添加文字,如果用graphics类绘制图片上的字体,实现图像上添加自定义标记,这种方法经验证是可行的,并且在visual c#2005 编程技巧大全上有提到,但是,这种方法处理图片的速度超级慢。一面介绍一种一种基于重载的高效c#上图片添加文字图形图片的方法。


using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace show
{
    /// <summary>
    /// Summary description for TransparentLabel2.
    /// </summary>
    public class PicBOX : System.Windows.Forms.PictureBox
    {
        //Fields
        private Point _Location = new Point(0, 0);//字体位置
        public string wrw;
        public bool isOld;

  
        //Properties
        public Point TextLocation
        {
            get
            {
                return this._Location;
            }
            set
            {
                this._Location = value;
            }
        }
        [Browsable(true)]
        new public string Text
        {
            get { return base.Text; }
            set { base.Text = value; }
        }
        [Browsable(true)]
        new public Font Font
        {
            get { return base.Font; }
            set { base.Font = value; }
        }
        //
        public PicBOX()
        {
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            SizeF m_size = e.Graphics.MeasureString(this.Text, this.Font);
            e.Graphics.DrawString(this.Text, this.Font, Brushes.Yellow, new RectangleF(this._Location, m_size));//加上字体
            
                Image img = Image.FromFile("alarm2.jpg");
                e.Graphics.DrawImage(img, new Point(this.Width-img.Width,0));
//加上图片
} }}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值