我不知道爲什麼我的應用程序得到的錯誤,當我嘗試在第二次[UIImage的大小]:消息發送到釋放實例0x8452560
-(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
這種情況下,任何的支持,請大家幫我
你需要告訴我們你從哪裏得到'rotatedOriginImage'。問題不在於'-rotateImage:'方法,問題是您給它的對象已被過度發佈。 – joerick 2012-07-11 10:50:27
第一次和第二次是什麼意思?是在旋轉之前和旋轉之後?你必須檢查你的rotateOriginImage.Is它在代碼中的某處發佈了嗎? – AJS 2012-07-11 10:54:17
調用方法「rotateImage」後設置「rotatedOriginImage」並返回圖像。您在設置之前正在訪問它的大小。 NSLog語句應該在調用「rotateImage」方法的行之後。 – AJS 2012-07-11 10:56:59