@property(nonatomic,strong)UIImageView *imageView;
@property(nonatomic,strong)UIImageView *backgroundImageV;
@property(nonatomic,assign)CGFloat scale;
- //计算imageView的frame
- -(CGRect)getImageByScaleFromImage
:(UIImage *)image - {
-
CGFloat widthScale = image.size.width / SCREEN_WIDTH; -
CGFloat heightScale = image.size.height / SCREEN_HEIGHT; -
self.scale = MAX(widthScale, heightScale); -
return CGRectMake(0, (SCREEN_HEIGHT - (image.size.height - 64) / self.scale) / 2.0, image.size.width / self.scale, image.size.height / self.scale); - }
- //修正图片的旋转方向
- - (UIImage *)fixOrientation:(UIImage *)aImage {
-
-
if (aImage.imageOrientation == UIImageOrientationUp) -
return aImage; -
CGAffineTransform transform = CGAffineTransformIdentit y; -
switch (aImage.imageOrientation) { -
case UIImageOrientationDown: -
case UIImageOrientationDownMi rrored: -
transform = CGAffineTransformTransla te(transform, aImage.size.width, aImage.size.height); -
transform = CGAffineTransformRotate(transform, M_PI); -
break; -
-
case UIImageOrientationLeft: -
case UIImageOrientationLeftMi rrored: -
transform = CGAffineTransformTransla te(transform, aImage.size.width, 0); -
transform = CGAffineTransformRotate(transform, M_PI_2); -
break; -
-
case UIImageOrientationRight: -
case UIImageOrientationRightM irrored: -
transform = CGAffineTransformTransla te(transform, 0, aImage.size.height); -
transform = CGAffineTransformRotate(transform, -M_PI_2); -
break; -
default: -
break; -
} -
switch (aImage.imageOrientation) { -
case UIImageOrientationUpMirr ored: -
case UIImageOrientationDownMi rrored: -
transform = CGAffineTransformTransla te(transform, aImage.size.width, 0); -
transform = CGAffineTransformScale(transform, -1, 1); -
break; -
-
case UIImageOrientationLeftMi rrored: -
case UIImageOrientationRightM irrored: -
transform = CGAffineTransformTransla te(transform, aImage.size.height, 0); -
transform = CGAffineTransformScale(transform, -1, 1); -
break; -
default: -
break; -
} -
-
// Now we draw the underlying CGImage into a new context, applying the transform -
// calculated above. -
CGContextRef ctx = CGBitmapContextCreate(NULL, aImage.size.width, aImage.size.height, -
CGImageGetBitsPerCompone nt(aImage.CGImage), 0, -
CGImageGetColorSpace(aImage.CGImage), -
CGImageGetBitmapInfo(aImage.CGImage)); -
CGContextConcatCTM(ctx, transform); -
switch (aImage.imageOrientation) { -
case UIImageOrientationLeft: -
case UIImageOrientationLeftMi rrored: -
case UIImageOrientationRight: -
case UIImageOrientationRightM irrored: -
// Grr... -
CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.height,aImage.size.width), aImage.CGImage); -
break; -
-
default: -
CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.width,aImage.size.height), aImage.CGImage); -
break; -
} -
-
// And now we just create a new UIImage from the drawing context -
CGImageRef cgimg = CGBitmapContextCreateIma ge(ctx); -
UIImage *img = [UIImage imageWithCGImage:cgimg]; -
CGContextRelease(ctx); -
CGImageRelease(cgimg); -
return img; - }
- -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWit
hInfo:(NSDictionary *)info - {
-
UIImage *firstImage = [info valueForKey:UIImagePickerControllerO riginalImage]; -
UIImage *image = [self fixOrientation:firstImage]; -
NSLog(@"123 %f %f",image.size.width,image.size.height); -
-
//将照片放入UIImageView对象中; -
self.imageView=[[UIImageView alloc]init];
-
self.imageView.frame=[self getImageByScaleFromImage :image]; -
self.imageView.image = image; -
self.backgroundImageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, self.imageView.frame.origin.y, image.size.width, image.size.height)]; -
self.backgroundImageV.image = image; -
UIView *coverView = [[UIView alloc]initWithFrame:self.backgroundImageV.frame]; -
coverView.backgroundColor = [UIColor whiteColor]; -
[self.view addSubview:self.backgroundImageV]; -
[self.view addSubview:coverView]; -
[self.view addSubview:self.imageView]; -
// self.imageView=imageView; -
-
UIView *viewCircle=[[UIView alloc]init]; -
viewCircle.backgroundColor=[UIColor clearColor]; -
viewCircle.layer.borderColor=[[UIColor blackColor]CGColor]; -
viewCircle.layer.borderWidth=1.5; -
viewCircle.frame=CGRectMake(0,64, 25, 25); -
[viewCircle.layer setCornerRadius:CGRectGetHeight([viewCircle bounds]) / 2]; -
viewCircle.layer.masksToBounds=YES; -
self.viewCircle=viewCircle; -
[self.imageView addSubview:self.viewCircle];
-
if (self.openType == UIImagePickerControllerS ourceTypeCamera) {
-
//将图片保存到图库 -
UIImageWriteToSavedPhoto sAlbum(image, self, @selector(image:didFinishSavingWithError :contextInfo:), NULL);
-
}else if(self.openType == UIImagePickerControllerS ourceTypePhotoLibrary){
-
//本身是从图库打开的,就不用保存到图库了;
-
}
-
//判断UIPopoverController对象是否存在 -
if (self.imagePickerPopover) { -
[self.imagePickerPopover dismissPopoverAnimated:YES]; -
self.imagePickerPopover = nil; -
} -
else -
{ -
//关闭以模态形式显示的UIImagePickerController -
[self dismissViewControllerAni mated:YES completion:nil]; -
} -
- }
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
}
//
- (UIColor*) getPixelColorAtLocation:(CGPoint)point
{
}
- (CGContextRef) createARGBBitmapContextF
{
}