iPhone 片断代码:截取屏幕保存图像

References

http://iphoneincubator.com/blog/tag/uigraphicsbeginimagecontext

 

Source codes:

 

UIGraphicsBeginImageContext(imageView.frame.size);

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

 

 

NOTES:

 

1. UIGraphicsBeginImageContext


Creates a bitmap-based graphics context and makes it the current context.

void UIGraphicsBeginImageContext (
   CGSize size
);
Parameters
size

The size of the new bitmap context. This represents the size of the image returned by the UIGraphicsGetImageFromCurrentImageContext function.

Discussion

You use this function to configure the drawing environment for rendering into a bitmap. This drawing environment uses the premultiplied RGBA format to store the resulting bitmap data. The environment also uses the default coordinate system for UIKit views, where the origin is in the upper-left corner and the positive axes extend down and to the right of the origin. The drawing environment is pushed onto the graphics context stack immediately.

While the context created by this function is the current context, you can call the UIGraphicsGetImageFromCurrentImageContext function to retrieve an image object based on the current contents of the context. When you are done modifying the context, you must call the UIGraphicsEndImageContext function to clean up the bitmap drawing environment and remove the graphics context from the top of the context stack. You should not use the UIGraphicsPopContext function to remove this type of context from the stack.

In most other respects, the graphics context created by this function behaves like any other graphics context. You can change the context by pushing and popping other graphics contexts. You can also get the bitmap context using the UIGraphicsGetCurrentContext function.

 

2. Fill rect 

 

[[UIColor redColor] set];

UIRectFill(CGRectMake(10,10, 200, 100));

 

3. Draw Text 

 

NSString* greeting = @"Tom, how are you now ";

[greeting drawAtPoint:CGPointMake(205, 0) withFont:[UIFont fontWithName:@"Helvetica" size:36.0]];

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值