-1

在我的应用程序中,我应用了不同类型的转换,例如向左旋转、向右旋转、垂直翻转、水平翻转到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;

但我没有得到旋转的图像。图像处于原始位置

4

2 回答 2

0

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

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

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

于 2012-09-10T11:06:32.680 回答
0

您应该在上下文中进行更改,并在完成后将其保存到 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();
于 2012-09-10T11:07:38.513 回答