【问题标题】:UISlider which blurs image with CiGaussianBlur also rotates image使用 CiGaussianBlur 模糊图像的 UISlider 也会旋转图像
【发布时间】:2014-05-17 15:59:38
【问题描述】:

我有一个范围从 0 到 30 的 UISlider。

不幸的是,当我使用 UISlider 时,图像开始模糊,但它也会旋转。

代码如下:

-(IBAction)slider:(UISlider *)sender
{
    float slideValue = [sender value];

    CIImage *beginImage = [[CIImage alloc] initWithImage:image];
    CIContext *context = [CIContext contextWithOptions:nil];

    CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur" keysAndValues:kCIInputImageKey, beginImage, @"inputRadius", [NSNumber numberWithFloat:slideValue], nil];
    CIImage *outputImage = [filter valueForKey:kCIOutputImageKey];

    CGImageRef cgimg = [context createCGImage:outputImage fromRect:[beginImage extent]];
    UIImage *newImg = [UIImage imageWithCGImage:cgimg];

    [imageView setImage:newImg];
    CGImageRelease(cgimg);
}

问题出在哪里?

提前致谢。

【问题讨论】:

  • 你的意思是无论滑块位置如何,生成的图像都会旋转 90 度?
  • 我记得最近看到一两个关于此类问题的问题。我认为这与 UIImage 和 CIImage 之间的转换有关。进行一些搜索,您应该会找到一些相关信息。
  • 注意,顺便说一句,不应该重复调用CIContext *context = [CIContext contextWithOptions:nil];,因为它非常低效。调用一次并将context 放入实例变量中。

标签: ios uiimage uislider blur


【解决方案1】:

问题出在这一行:

UIImage *newImg = [UIImage imageWithCGImage:cgimg];

这太简单了。致电[UIImage imageWithCGImage:cgimg scale:originalScale orientation:originalOrientation];(您需要为这些提供正确的值)。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-04-19
  • 1970-01-01
  • 1970-01-01
  • 2013-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多