2011-06-21 21 views
0

私は画像を切り取って写真ライブラリに切り取った画像を保存しなければならないプロジェクトに取り組んでいます。私は画像をトリミングするのに成功しましたが、画像を切り抜いて表示すると、伸びています。アスペクトフィットモードも使用しています。しかし、まだそのstretched.HereコードUiimageの高さと幅の比率を調整する方法

-(void)cropLassoArea { 

isLassoSelected = NO; 
lassoStyle = 0; 
CGRect frame; 
frame = mainImageView.frame; 
mainImageView.frame.size = CroppedImage.size; 
for (int i = 0; i < [lassoArray count]; i++) { 

    CAShapeLayer *layer = [lassoArray objectAtIndex:i]; 

    CGPathRef myPath = layer.path; 
    UIGraphicsBeginImageContext(mainImageView.frame.size); 

    [mainImageView setContentMode:UIViewContentModeCenter]; 


    [mainImageView.image drawInRect:CGRectMake(0, 0,CroppedImage.size.width,CroppedImage.size.height)]; 

    context = UIGraphicsGetCurrentContext(); 
    CGContextBeginPath(context); 
    CGContextAddPath(context, myPath); 

    CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [UIColor whiteColor].CGColor); 
    CGContextSetBlendMode(context, kCGBlendModeClear); 
    CGContextDrawPath(context, kCGPathFill); 
    CGContextEOFillPath(context); 

    mainImageView.image = UIGraphicsGetImageFromCurrentImageContext(); 
    CGContextSaveGState(context); 
    UIGraphicsEndImageContext(); 

} 

}

答えて

0

である私はthis場所からファイルをダウンロードするためにあなたを示唆していると私はあなたが彼らのチュートリアルを通過することをお勧めします。それは簡単で、あなたのイメージを全く伸ばしません。私はこれらのファイルを私の作業プロジェクトの1つで使用しました。ヘッダーファイルをインポートして次の行を呼び出すだけです。

UIImage *tmpImage = [yourImageView.image resizedImage:CGSizeMake(desiredWidth,DesiredHeight) interpolationQuality:kCGInterpolationHigh]; 
    yourImageView.contentMode = UIViewContentModeCenter; 
    [yourImageView setImage:tmpImage]; 

希望します。

関連する問題