0

我不知道为什么我的应用程序在第二次尝试旋转图像时出现错误

-(UIImage *)rotateImage:(UIImage *)image{
    // calculate the size of the rotated view's containing box for our drawing space
    CGSize rotatedSize = image.size;

    // Create the bitmap context
    UIGraphicsBeginImageContext(rotatedSize);
    CGContextRef bitmap = UIGraphicsGetCurrentContext();

    // Move the origin to the middle of the image so we will rotate and scale around the center.
    CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2);

    //   // Rotate the image context
    CGContextRotateCTM(bitmap, DegreesToRadians(90));

    // Now, draw the rotated/scaled image into the context
    CGContextScaleCTM(bitmap, 1.0, -1.0);
    CGContextDrawImage(bitmap, CGRectMake(-image.size.width / 2, -image.size.height / 2, image.size.width, image.size.height), image.CGImage);

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;

}

我通过以下方式调用此函数:

 NSLog(@"%f %f",rotatedOriginImage.size.width,rotatedOriginImage.size.height);
    rotatedOriginImage = [self rotateImage:rotatedOriginImage];

在第一次登录时:

2012-07-11 17:22:50.825 meshtiles[3330:707] 600.000000 600.000000

但在第二次:

2012-07-11 17:22:55.253 meshtiles[3330:707] *** -[UIImage size]: message sent to deallocated instance 0x8452560

对此案有任何支持,请帮助我

4

1 回答 1

2

如果您不使用 ARC,那么您newImage将从您的方法中返回一个自动释放的对象。当你拿回来时,你需要保留它。

rotatedOriginImage = [[self rotateImage:rotatedOriginImage] retain];

但是你必须记住在调用 rotateImage 之后也要释放它。所以你需要改变你的代码来做到这一点

于 2012-07-11T10:46:05.860 回答