【问题标题】:freehand cropping in iosios中的徒手裁剪
【发布时间】:2013-02-13 12:53:11
【问题描述】:

我想使用相机拍摄一个人的图像,然后在应用程序中编辑图像。该应用程序应该具有裁剪(最好是徒手裁剪)仅离开背景的人的功能,以便我能够在不同背景下使用该人。我不确定如何进行裁剪部分..请在 ios 中帮助我

【问题讨论】:

    标签: ios uiimageview uiimage


    【解决方案1】:

    我创建了一个可以满足您需求的手绘裁剪工具。

    https://github.com/nicholjs/BFCropInterface

    【讨论】:

      【解决方案2】:

      我已使用此代码手动裁剪图像。我将它用于静止的 UIView,而不是相机图像,但它适用于任何类型的 UIView。这里 startX、startY、endX 和 endY 是在 toucheBegan、touchMove 和 touchEnd 函数中获取的整数值。希望对您有所帮助。

      谢谢

      UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
        [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
             if(self.isRetina){
               contentRectToCrop = CGRectMake(startX*2, startY*2, (endX*2-startX*2), endY*2-startY*2);
             }else{
              contentRectToCrop = CGRectMake(startX, startY, (endX-startX), endY-startY);
                    }
            CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], contentRectToCrop); 
          UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
      

      【讨论】:

      • 我试过了,但是裁剪后的图像的分辨率与原始图像相比太差了,有什么解决方案请帮助我
      【解决方案3】:

      是的,您没有使用正确的视网膜显示检查。上述函数以像素为单位计算裁剪图像。我最初遇到同样的问题,但是这段代码解决了我的问题,请将此功能与以前的代码一起使用,问题将得到解决。

      -(BOOL)isRetina
      {
          if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0) {
              return YES;
          }
          return NO;
      
      }
      

      谢谢

      【讨论】:

      • 先生,我使用的是 ipad 1 和 ipad 2,这些不是视网膜分辨率,但图像看起来很模糊
      猜你喜欢
      • 2015-09-22
      • 1970-01-01
      • 2011-09-06
      • 1970-01-01
      • 2012-11-08
      • 2016-06-16
      • 2011-10-28
      • 1970-01-01
      • 2012-12-12
      相关资源
      最近更新 更多