I am getting a UIImage with UIImagePickerController. After getting the image, I set it as the background of a UITableView. The image looks exactly as I took it. But then if I save the image to my server and then load the image back. Whether I save using UIImagePNGRepresentation
or UIImageJPEGRepresentation
, the image rotates upon saving (rotation happens before server call). I have read here that the png would rotate but that the jpeg would not. But for me both rotate 90 degrees. Any thoughts why jpeg is bad in my case?
MORE
I get the raw image from image picker as UIImage. Then I keep a pointer to the UIImage. Some time later, I want to save the UIImage. So normally I do UIImagePNGRepresentation(myUIImage)
. I am using AFNetworking as
if ([self.imageDictionaries count]>0)
for (NSDictionary *imgDic in self.imageDictionaries) {
[formData appendPartWithFileData:UIImagePNGRepresentation([imgDic objectForKey:@"image"])
name:[imgDic objectForKey:@"name"]//@"image"
fileName:[imgDic objectForKey:@"fileName"]//@"image.png"
mimeType:[imgDic objectForKey:@"mimeType"]//@"image/png"
];
}
}
//[imgDic objectForKey:@"name"] is just a UIImage
One of the items of imageDictionaries look like this
NSDictionary *background =@{
@"image":self.backgroundImage,
@"name":@"bkgimg",
@"fileName":@"bkgimg.png",
@"mimeType":@"image/png"
};
Also note that my code works fine. The one and only problem is that the image is rotating. self.backgroundImage
is a pointer to the UIImage that I obtained from UIImagePickerController as
UIImage *background = info[UIImagePickerControllerOriginalImage];
The image does not rotate if I were to use UIImagePickerControllerEditedImage
. But that's a whole other story for another time.