【问题标题】:How to assign an image of transformed UIImageview to some other UIImageview?如何将转换后的 UIImageview 的图像分配给其他一些 UIImageview?
【发布时间】:2012-09-10 10:58:30
【问题描述】:

在我的应用程序中,我应用了不同类型的转换,例如向左旋转、向右旋转、垂直翻转、水平翻转到 UIImageview。应用这些操作后,UIImageview 的位置会发生变化。我希望将此更改后的图像分配给其他视图,而不是原始图像。当我将imageview.image 分配给另一个视图时,它正在分配原始图像。我该如何纠正这个问题?

正如大卫所建议的那样。我正在为左旋转应用以下代码

//rotation left;
        int x1=ivPhoto.frame.origin.x;
        int y1=ivPhoto.frame.origin.y;

        UIGraphicsBeginImageContext(ivPhoto.image.size);


        CGAffineTransform transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(degrees2));        

        CGContextConcatCTM(UIGraphicsGetCurrentContext(), transform);
         [ivPhoto.image drawInRect:CGRectMake(x1,y1,ivPhoto.frame.size.width, ivPhoto.frame.size.height)];

        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

        ivPhoto.image=newImage;

但我没有得到旋转图像。图像在原始位置

【问题讨论】:

    标签: iphone uiimageview uiimage cgaffinetransform


    【解决方案1】:

    转换完成后,像这样捕获更新的图像:

    CGSize fittingSize = yourImgView.frame.size;
    UIGraphicsBeginImageContext(fittingSize);
    [yourImgView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImahe *capImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    现在将这些 capImage 分配给另一个具有转换图像的 UIImageView

    【讨论】:

      【解决方案2】:

      您应该在上下文中进行更改,并在完成后将其保存到 UIImage。然后在 imageview 中设置该图像:

      UIGraphicsBeginImageContext(sizeOfImage);
      
      
          CGAffineTransform transform = CGAffineTransformIdentity;
      

      等等等等

          CGContextConcatCTM(UIGraphicsGetCurrentContext(), transform);
      [imageView.image drawInRect:CGRectMake(position.x, position.y, size.width, size.height)];
      UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-15
        相关资源
        最近更新 更多