开发者

Rotate the image stored in the sandbox

I want to rotate an image and save to go to the sandbox, but sandbox in the direction of the picture has not changed. Why? Expert guidance please, thank you!

The following is a rotation code:

-(void)leftRotate
{
        switch (i%4)
    {
        case 0:
            myImageView.image = [UIImage imageWithCGImage:myImageView.image.CGImage scale:1 orientation:UIImageOrientationUp];

            break;
        case 1:
            myImageView.image = [UIImage imageWithCGImage:myImageView.image.CGImage scale:1 orientation:UIImageOrientationLeft];

            break;
        case 2:
            myImageView.image = [UIImage imageWithCGImage:myImageView.image.CGImage scale:1 orientation:UIImageOrientationDown];

            break;
        case 3:
            myImageView.image = [UIImage imageWithCGImage:myImageView.image.CGImage scale:1 orientation:UIImageOrientationRight];

            break;

        default:
            break;
    }
    ++i;
}

Here is the code t开发者_运维技巧o save the image to the sandbox:

-(void)save:(id)sender
{
    NSDate *date=[NSDate date];

    NSLog(@"%@",date);
    NSCalendar *calendar=[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSInteger unitFlags=NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit;
    NSDateComponents *component=[calendar components:unitFlags fromDate:date];
    int year=[component year];
    int month=[component month];
    int day=[component day];
    int h=[component hour];
    int m=[component minute];
    int s=[component second];
    fileName=[NSString stringWithFormat:@"%d-%d-%d_%d:%d:%d.png",year,month,day,h,m,s];
    NSLog(@"%@",fileName);
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path=[paths objectAtIndex:0];
    NSLog(@"path:%@",path);
    filePath=[path stringByAppendingPathComponent:fileName];
    NSLog(@"filePath:%@",filePath); 
    NSData *data=[NSData dataWithData:UIImagePNGRepresentation(myImageView.image)];
    [data writeToFile:filePath atomically:YES];       
}


PNG files don't support the rotation flag (which is just saved in the file's metadata, the pixels aren't changed). You'd need to save your image as JPEG to get it rotated in this way, or rotate the actual pixel data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜