保存缩放图像并在缩放后将其发送到服务器

时间:2014-01-21 06:46:50

标签: ios objective-c zooming

我的问题与缩放图像有关。我正在使用YKImageCropper this代码缩放图像我希望保存图像后缩放以便我可以将该图像发送到服务器,在服务器端它们将应用与我应用的相同比例并获得与我相同的图像在我的设备上创建。我的应用程序基本上是在T恤和服务器端创建照片模板,他们将获得此模板,他们将应用相同的过滤器,并为T恤打印做好准备。如果您不理解流程,请告诉我。 我可以通过两种方式做到这一点 1)通过保存缩放图像

2)在原始图像上应用比例

请帮帮我

先谢谢

- (UIImage *)editedImage {
    CGFloat scale = self.image.size.width / self.imageView.frame.size.width;
    CGRect rect = self.overlayView.clearRect;
    rect.origin.x = (rect.origin.x - self.imageView.frame.origin.x) * scale;
    rect.origin.y = (rect.origin.y - self.imageView.frame.origin.y) * scale;
    rect.size.width *= scale;
    rect.size.height *= scale;
    NSLog(@"scale ::: %@",NSStringFromCGPoint(rect.origin));
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef c = UIGraphicsGetCurrentContext();
    CGContextClipToRect(c, CGRectMake(0, 0, rect.size.width, rect.size.height));
    [self.image drawInRect:CGRectMake(-rect.origin.x, -rect.origin.y, self.image.size.width, self.image.size.height)];
    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return result;
}

1 个答案:

答案 0 :(得分:0)

使用 YKImageCropper 裁剪图片(用缩放的术语),

UIImage *image = [UIImage imageNamed:@"Sample.jpg"];
YKImageCropperViewController *vc = [[YKImageCropperViewController alloc] initWithImage:image];
vc.cancelHandler = ^() {
    // When cancel is tapped
};
vc.doneHandler = ^(UIImage *editedImage) {
    // editedImage supplied here is your zoomed image
    // do something with edited image and save it to server.
};

doneHandler 是一个,您可以在裁剪和使用后传递该图像以获取图像。
希望这会有所帮助。