UIImage方法(imageWithCGImage: scale: orientation:)

本文介绍了一个用于UIImage的自定义方法,该方法可以实现图片的放大与旋转功能。通过CGImageRef、放大倍数及方向参数,开发者能够灵活地调整图片的显示效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


+ (UIImage *)imageWithCGImage:(CGImageRef)cgImage scale:(CGFloat)scale orientation:(UIImageOrientation)orientation

作用:对UIImage进行放大旋转

参数1: cgImage = image.CGImage  image为原始图片

参数2:scale            原始图片放大倍数

参数3:orientation  即UIImage的imageOrientation属性   控制image的绘制方向

   

typedef NS_ENUM(NSInteger, UIImageOrientation) {

    UIImageOrientationUp,            // default orientation     

    UIImageOrientationDown,          // 180 deg rotation 	 


    UIImageOrientationLeft,          // 90 deg CCW      	 
    UIImageOrientationRight,         // 90 deg CW            
    UIImageOrientationUpMirrored,    // as above but image mirrored along other axis. 
					horizontal flip          
    UIImageOrientationDownMirrored,  // horizontal flip    	 
    UIImageOrientationLeftMirrored,  // vertical flip        
    UIImageOrientationRightMirrored, // vertical flip        
};

AVCaptureConnection *videoConnection = [self.ImageOutPut connectionWithMediaType:AVMediaTypeVideo]; UIDeviceOrientation curDeviceOrientation = [[UIDevice currentDevice] orientation]; AVCaptureVideoOrientation avcaptureOrientation = [self avOrientationForDeviceOrientation:curDeviceOrientation]; [videoConnection setVideoOrientation:avcaptureOrientation]; [videoConnection setVideoScaleAndCropFactor:self.effectiveScale]; if (!videoConnection || !self.session.isRunning) { ATLog(@"take photo failed!"); return; } MJWeakSelf; [self.ImageOutPut captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) { dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ if (imageDataSampleBuffer) { NSData * imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; weakSelf.image = [UIImage imageWithData:imageData]; if (weakSelf.image) { weakSelf.image = [UIImage updateImageSize:weakSelf.image]; } weakSelf.image = [[TZImageManager manager] fixOrientation:weakSelf.image];//[UIImage fixOrientation:weakSelf.image]; PHAuthorizationStatus authorStatus = [PHPhotoLibrary authorizationStatus]; if (authorStatus == PHAuthorizationStatusAuthorized) { [[TZImageManager manager] savePhotoWithImage:weakSelf.image completion:^(PHAsset *asset, NSError *error) { [weakSelf addPHAsset:asset]; }]; }else{ [weakSelf gotoEditImageController:weakSelf.image asset:nil]; } } }); }];优化此代码
最新发布
07-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值