J'ai une UIImage qui est UIImageOrientationUp (portrait) que je voudrais tourner dans le sens antihoraire de 90 degrés (en mode paysage). Je ne veux pas utiliser un CGAffineTransform. Je veux que les pixels de la UIImage à fait changer de position. Je suis à l'aide d'un bloc de code (voir ci-dessous), à l'origine prévu pour redimensionner une UIImage pour ce faire. J'ai fixé un objectif de taille de la taille actuelle de la UIImage mais j'obtiens une erreur (Error): CGBitmapContextCreate: données non valides octets/ligne: doit être d'au moins 1708 pour 8 bits entier/composant, 3 volets, kCGImageAlphaPremultipliedLast. (Je n'ai pas d'erreur à chaque fois que je vais vous donner une taille plus PETITE que la taille de la cible, en passant). Qui de vous me montrer comment il vous suffit de TOURNER mon UIImage de 90 degrés vers la GAUCHE en utilisant simplement de base fonctions graphiques tout en préservant la taille actuelle?
-(UIImage*)reverseImageByScalingToSize:(CGSize)targetSize:(UIImage*)anImage
{
UIImage* sourceImage = anImage;
CGFloat targetWidth = targetSize.height;
CGFloat targetHeight = targetSize.width;
CGImageRef imageRef = [sourceImage CGImage];
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
CGColorSpaceRef colorSpaceInfo = CGImageGetColorSpace(imageRef);
if (bitmapInfo == kCGImageAlphaNone) {
bitmapInfo = kCGImageAlphaNoneSkipLast;
}
CGContextRef bitmap;
if (sourceImage.imageOrientation == UIImageOrientationUp || sourceImage.imageOrientation == UIImageOrientationDown) {
bitmap = CGBitmapContextCreate(NULL, targetHeight, targetWidth, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo);
} else {
bitmap = CGBitmapContextCreate(NULL, targetWidth, targetHeight, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo);
}
if (sourceImage.imageOrientation == UIImageOrientationRight) {
CGContextRotateCTM (bitmap, radians(90));
CGContextTranslateCTM (bitmap, 0, -targetHeight);
} else if (sourceImage.imageOrientation == UIImageOrientationLeft) {
CGContextRotateCTM (bitmap, radians(-90));
CGContextTranslateCTM (bitmap, -targetWidth, 0);
} else if (sourceImage.imageOrientation == UIImageOrientationDown) {
// NOTHING
} else if (sourceImage.imageOrientation == UIImageOrientationUp) {
CGContextRotateCTM (bitmap, radians(90));
CGContextTranslateCTM (bitmap, 0, -targetHeight);
}
CGContextDrawImage(bitmap, CGRectMake(0, 0, targetWidth, targetHeight), imageRef);
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage* newImage = [UIImage imageWithCGImage:ref];
CGContextRelease(bitmap);
CGImageRelease(ref);
return newImage;
}