Quartz 2D 基础

Quartz 2D 基础

|  No Comments  |  No TrackBacks
原文地址: http://iphone.ipsw.info/2009/12/quartz-2d.html

CGImageCreateWithImageInRect 使用

如何画矩形

CGRect backRect = CGRectMake(1010508);

CGContextSetRGBFillColor(context, 1.01.01.01.0);

CGContextFillRect(context, backRect);


下面的代码是选择坐标系

CGContextTranslateCTM(context, 0.0self.frame.size.height);

CGContextScaleCTM(context, 1.0, -1.0);

CGContextShowTextAtPoint 不能draw中文,中文等UTF8 需要用

NSString drawAtPoint 这个方法

看看效果
屏幕快照 2009-12-09 上午02.48.31.png

- (void)drawRect:(CGRect)rect {

    // Drawing code

CGRect myrect;

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSaveGState(context);

//CGContextSetAllowsAntialiasing(context,true);

CGContextTranslateCTM(context, 0.0self.frame.size.height);

CGContextScaleCTM(context, 1.0, -1.0);

for (NSNumber *number in data) {

int x = [number intValue] * CGImageGetWidth(cards)/5;

if (x >320-CGImageGetWidth(cards)/5) {

myrect=CGRectMake(x-(320-CGImageGetWidth(cards)/5) , CGImageGetHeight(cards),CGImageGetWidth(cards)/5CGImageGetHeight(cards));

else {

myrect=CGRectMake(x-20*[number intValue] ,0 , CGImageGetWidth(cards)/5,CGImageGetHeight(cards));


}


CGImageRef tmp = CGImageCreateWithImageInRect(cards,CGRectMake([number intValue] * (CGImageGetWidth(cards)/5), 0CGImageGetWidth(cards)/5CGImageGetHeight(cards) ));

CGImageRef digit = CGImageCreateWithImageInRect(digits,CGRectMake([number intValue] *CGImageGetWidth(digits)/13CGImageGetHeight(digits)/2CGImageGetWidth(digits)/13,CGImageGetHeight(digits)/2 ));

CGContextDrawImage(context,myrect,tmp);

CGRect digrect = CGRectMake(myrect.origin.x + 2CGImageGetHeight(cards) -CGImageGetHeight(digits)/2 -3,CGImageGetWidth(digits)/13CGImageGetHeight(digits)/2);

NSLog(@"%f",myrect.origin.x );

CGContextDrawImage(context,digrect,digit);

CGImageRef chip = CGImageCreateWithImageInRect(chips,CGRectMake(3*CGImageGetWidth(chips)/40CGImageGetWidth(chips)/4CGImageGetHeight(chips)));

for (int i=0; i<10; i++) {

CGContextDrawImage(context,CGRectMake(0CGImageGetHeight(cards)+6*i,0.6*CGImageGetWidth(chips)/40.6*CGImageGetHeight(chips)),chip);

CGContextDrawImage(context,CGRectMake(0.6*CGImageGetWidth(chips)/4,CGImageGetHeight(cards)+6*i, 0.6*CGImageGetWidth(chips)/40.6*CGImageGetHeight(chips)),chip);

}

CGContextSelectFont(context, "Helvetica"20

kCGEncodingMacRoman);

CGContextSetTextDrawingMode(context, kCGTextFill);

CGContextSetRGBFillColor (context, 010.5); // 6

//CGContextSetRGBStrokeColor (context, 0, 0, 1, 1);

CGContextShowTextAtPoint(context,0,2*CGImageGetHeight(cards)+6*10,"$234",4);

CGContextShowTextAtPoint(context,0,2*CGImageGetHeight(cards)+6*10+20,"Will",4);

//CFRelease(tmp);

//CFRelease(digit);


}

if (newRound == NO) {

CGRect backRect = CGRectMake(1010508);

CGContextSetRGBFillColor(context, 1.01.01.01.0);

CGContextFillRect(context, backRect);

CGRect ourRect;

// Set the fill color to opaque red.

CGContextSetRGBFillColor(context, 1.00.00.01.0);

// Set up the rectangle for drawing.

ourRect.origin.x = ourRect.origin.y = 10.0;

ourRect.size.width = Height;

ourRect.size.height = 8.0;

// Draw the filled rectangle.

CGContextFillRect(context, ourRect);

 backRect = CGRectMake(110110508);

CGContextSetRGBFillColor(context, 1.01.01.01.0);

CGContextFillRect(context, backRect);

//CGRect ourRect;

// Set the fill color to opaque red.

CGContextSetRGBFillColor(context, 1.00.00.01.0);

// Set up the rectangle for drawing.

ourRect.origin.x = ourRect.origin.y = 110.0;

ourRect.size.width = Height;

ourRect.size.height = 8.0;

// Draw the filled rectangle.

CGContextFillRect(context, ourRect);

}

CGContextRestoreGState(context);

CGContextSetRGBFillColor(context, 1.01.01.01.0);

[@"孔祥波" drawAtPoint:CGPointMake(0,320-(2*CGImageGetHeight(cards)+6*10+60)) withFont:[UIFontfontWithName:@"Helvetica-Bold" size:20]];

}

No TrackBacks

TrackBack URL: http://iphone.ipsw.info/mt/mt-tb.cgi/272

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值