1、UIView截图
-(UIImage*)captureView:(UIView *)theView{
CGRect rect = theView.frame;
if ([theView isKindOfClass:[UIScrollView class]]) {
rect.size = ((UIScrollView *)theView).contentSize;
}
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[theView.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
2、UIScrollview截图
- (UIImage *)captureScrollView:(UIScrollView *)scrollView{
UIImage* image = nil;
UIGraphicsBeginImageContext(scrollView.contentSize);
{
CGPoint savedContentOffset = scrollView.contentOffset;
CGRect savedFrame = scrollView.frame;
scrollView.contentOffset = CGPointZero;
scrollView.frame = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
[scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
scrollView.contentOffset = savedContentOffset;
scrollView.frame = savedFrame;
}
UIGraphicsEndImageContext();
if (image != nil) {
return image;
}
return nil;
}
3、合并多张图片
- (UIImage *)composeWithHeader:(UIImage *)header content:(UIImage *)content footer:(UIImage *)footer{
CGSize size = CGSizeMake(content.size.width, header.size.height +content.size.height +footer.size.height);
UIGraphicsBeginImageContext(size);
[header drawInRect:CGRectMake(0,
0,
header.size.width,
header.size.height)];
[content drawInRect:CGRectMake(0,
header.size.height,
content.size.width,
content.size.height)];
[footer drawInRect:CGRectMake(0,
header.size.height+content.size.height,
footer.size.width,
footer.size.height)];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
4、流媒体
将音频、图片转成base64Binary
+(NSData *)base64Encoded:(NSData *)data
{
//base64binary(流媒体)
static char encodingTable[64] = {
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' };
const unsigned char *bytes = [data bytes];
NSMutableString *result = [NSMutableString stringWithCapacity:[data length]];
新闻热点
疑难解答