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();
}
}