2013-02-07 96 views
2

我可以旋转图像,当我点击视图和图像旋转成功,但旋转的图像不保存在iphone相册。如何保存iphone相册中的旋转图像?

当我点击保存按钮之前的图像中的专辑节省请任何一个可以帮助我

- (void) touchesBegan:(NSSet *)_touches withEvent:(UIEvent *)_event 
    { 
    UITouch* touch = [_touches anyObject]; 
    CGPoint location = [touch locationInView:m_block]; 
    m_locationBegan = location; 
    } 

    - (void) touchesMoved:(NSSet *)_touches withEvent:(UIEvent *)_event 
    { 
    UITouch* touch = [_touches anyObject]; 
    CGPoint location = [touch locationInView:m_block]; 
    [self updateRotation:location]; 
    } 

- (void) touchesEnded:(NSSet *)_touches withEvent:(UIEvent *)_event 
    { 
    UITouch *touch=[_touches anyObject]; 
    CGPoint location = [touch locationInView:m_block]; 
    m_currentAngle = [self updateRotation:location];  
} 
- (float) updateRotation:(CGPoint)_location 
    { 
    float fromAngle = atan2(m_locationBegan.y-m_block.center.y, m_locationBegan.x-m_block.center.x); 
    float toAngle = atan2(_location.y-m_block.center.y, _location.x-m_block.center.x); 
    float newAngle = wrapd(m_currentAngle + (toAngle - fromAngle), 0, 2*3.14); 

    CGAffineTransform cgaRotate = CGAffineTransformMakeRotation(newAngle); 
    m_block.transform = cgaRotate; 
    int oneInFifty = (newAngle*50)/(2*3.14); 
    m_label.text = [NSString stringWithFormat:@"Angle: %f 1in50: %i", newAngle, oneInFifty]; 
     return newAngle; 
    } 
    - (IBAction)saveImageToAlbum 
    { 
    [self.library saveImage:m_block.image toAlbum:@"My" withCompletionBlock:^(NSError *error) { 
     if (error!=nil) { 
     NSLog(@"Big error: %@", [error description]); 
    } 
    }]; 

UIImage *image = m_block.image; 
NSUserDefaults * user= [NSUserDefaults standardUserDefaults] ; 
[user setObject:UIImagePNGRepresentation(image) forKey:@"foo"]; 
[user synchronize]; 
[self dismissViewControllerAnimated:YES completion:nil]; 

    } 

回答

0

我认为你正在使用自定义的UIView或者UIImageView的。

您可以通过下面的代码保存任何浏览当前的外观:

+ (UIImage *) imageWithView:(UIView *)view 
{ 
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0); 
    [view.layer renderInContext:UIGraphicsGetCurrentContext()]; 

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); 

    UIGraphicsEndImageContext(); 

    return img; 
} 

我得到这个来自:How to capture UIView to UIImage without loss of quality on retina display

这是工作对我非常好。

所有最好的......

+0

我越来越的角度,你可以看到我的代码,然后如何通过该图像中的角度? – IOSDev

+0

您是否在保存过程中试过这段代码?你得到了什么? – CRDave

+0

我已经试过这段代码,但它不工作,你可以在我的代码中看到我正在重新调整角度。那角度我必须保存然后怎么做,请解决我的问题.. – IOSDev