從view上截取部分圖片

代碼片中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);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章