从相机保存缩放图像

时间:2011-06-10 03:54:54

标签: iphone

我正在为iphone / ipad开发相机应用程序。 我们使用叠加层在取景器顶部显示相机应用程序。 目前我正在尝试保存缩放的图像。我们可以在取景器上缩放图像。但是当我们保存图像时,它会以原始大小保存。 为了解决这个问题,我们使用以下代码缩放缩放图像:

UIImageView *v = [[UIImageView alloc]initWithImage:image];

UIGraphicsBeginImageContext(v.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSaveGState(context);
CGContextScaleCTM(context, zoomvalue,zoomvalue);
[v drawRect:CGRectMake(0,0,320,480)];
CGContextRestoreGState(context);
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

使用上面的代码,我们可以获得缩放的图像。 但是,我们需要裁剪缩放图像的中心部分并保存相同的部分。我们没有得到同样的结果。

请帮助

1 个答案:

答案 0 :(得分:2)

如果您正在使用UIImagePickerController来捕捉图像并缩放图像,那么您可以从选择器UIImagePickerControllerEditedImage获取NSDictionary来获取编辑过的图像 -

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{

    img =  [[info objectForKey:UIImagePickerControllerEditedImage] retain];
    [picker dismissModalViewControllerAnimated:YES];

}
相关问题