【九宫切图】什么是九宫绘图

本文转载于:CSKIN论坛,地址:http://bbs.cskin.net/thread-62-1-1.html

下面贴下核心代码

public static void RenderBackground(Graphics g, Image img, Rectangle rect) {
    //填充四个角
    g.DrawImage(img, new Rectangle(rect.X, rect.Y, 5, 5), 
        new Rectangle(0, 0, 5, 5), GraphicsUnit.Pixel);
    g.DrawImage(img, new Rectangle(rect.Right - 5, rect.Y, 5, 5), 
        new Rectangle(img.Width - 5, 0, 5, 5), GraphicsUnit.Pixel);
    g.DrawImage(img, new Rectangle(rect.X, rect.Bottom - 5, 5, 5), 
        new Rectangle(0, img.Height - 5, 5, 5), GraphicsUnit.Pixel);
    g.DrawImage(img, new Rectangle(rect.Right - 5, rect.Bottom - 5, 5, 5), 
        new Rectangle(img.Width - 5, img.Height - 5, 5, 5), GraphicsUnit.Pixel);
    //四边
    g.DrawImage(img, new Rectangle(rect.X, rect.Y + 5, 5, rect.Height - 10), 
        new Rectangle(0, 5, 5, img.Height - 10), GraphicsUnit.Pixel);
    g.DrawImage(img, new Rectangle(rect.X + 5, rect.Y, rect.Width - 10, 5), 
        new Rectangle(5, 0, img.Width - 10, 5), GraphicsUnit.Pixel);
    g.DrawImage(img, new Rectangle(rect.Right - 5, rect.Y + 5, 5, rect.Height - 10), 
        new Rectangle(img.Width - 5, 5, 5, img.Height - 10), GraphicsUnit.Pixel);
    g.DrawImage(img, new Rectangle(rect.X + 5, rect.Bottom - 5, rect.Width - 10, 5), 
        new Rectangle(5, img.Height - 5, img.Width - 10, 5), GraphicsUnit.Pixel);
    //中间
    g.DrawImage(img, 
        new Rectangle(rect.X + 5, rect.Y + 5, rect.Width - 10, rect.Height - 10), 
        new Rectangle(5, 5, img.Width - 10, img.Height - 10), GraphicsUnit.Pixel);
 
}
public class TestA : Control
{
    protected override void OnPaint(PaintEventArgs e) {
        RenderHelper.RenderBackground(
            e.Graphics,
            Properties.Resources.Qbtn_Gray,//资源图
            this.ClientRectangle);
        base.OnPaint(e);
    }
}



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值