如何在IOS中以角度绘制图像

时间:2014-11-27 18:42:25

标签: ios objective-c drawing

我想以角度绘制图像。我有一个ImageView具有竞争模式Aspect to fit。我还有一个dragView用户可以在View上移动和旋转。我用CGAffineTransformMakeRotation

移动了dragView

ImageViewdragView都添加在主(自我)视图中。

我已完成以下代码。

它有两个问题

  1. 我不知道如何以CGAffineTransformMakeRotation
  2. 的角度保存图像
  3. dragView当前未放置在图像上。它在x和y位置有一些变化。
  4. -(void)btnSaveClicked {

    UIGraphicsBeginImageContextWithOptions(imgView.image.size, NO, 0.0); // create context as the image size
    UIImage *dragImage = [self imageWithView:dragView]; // convert image from the dragView
    [imgView.image drawInRect:CGRectMake(0, 0, imgView.image.size.width, imgView.image.size.height)];  // draw main image
    
    CGSize size = imageDraw.size;
    float factor = imgView.image.size.width / imgView.frame.size.width;
    if (factor <  imgView.image.size.height / imgView.frame.size.height) {
        factor = imgView.image.size.height / imgView.frame.size.height;
    }
    
    CGRect rect = CGRectMake(self.view.frame.size.width/2-size.width/factor/2, self.view.frame.size.height/2-size.height/factor/2, size.width/factor, size.height/factor);
    
    CGPoint point = CGPointMake((dragView.frame.origin.x+10-rect.origin.x)*factor,(dragView.frame.origin.y+10 - rect.origin.y)*factor);
    [dragImage drawAtPoint:point blendMode:kCGBlendModeNormal alpha:1.0];  // draw the dragImnage but the point is wrong
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    imgView.image = newImage;
    

    }

    示例项目:https://github.com/SunnyShah407/WaterMark/tree/master

0 个答案:

没有答案