2013-02-07 37 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