代碼片中bg是一個imageView,
UIGraphicsBeginImageContextWithOptions(bg.frame.size, YES, 1.0);//yes表示透明,1.0表示不進行縮放
[bg.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *bgImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imageRef = bgImg.CGImage;
CGImageRef shotRef = CGImageCreateWithImageInRect(imageRef, CGRectMake(0, bg.frame.size.height - 64, [UIScreen mainScreen].bounds.size.width, 64));
UIImage *shotImage = [[UIImage alloc] initWithCGImage:shotRef];//最後獲得的圖片,size高爲64
CGImageRelease(shotRef);