Reputation: 1924
I want to save rotated image data to CoreData and show the rotated image to UIImageView. But my problem is that I am storing image data to CoreData and when to fetch and to display the data to imageView is showing the original image(Without rotate). Below is the code I am using for storing data to CoreData.
if let imageData = imagePicked.image?.jpegData(compressionQuality: 100) {
CoreDataBaseHelper.shareInstance.saveImage(data: imageData, imageID: arr.count)
}
And below is the code for showing fetched data.
addCell.roomIconImage.image = UIImage(data: fetchedData[indexPath.row].image!)
Can you please help me to save the rotated image to CoreData and show the image.
Upvotes: 0
Views: 153
Reputation: 2859
The image you're saving to the DB is not actually rotated.
By setting the transform
property of UIImageView
you only rotate the rendered view that displays your image, but the actual image data doesn't get changed because of that. It's like when you put a physical picture into a frame and hang the frame on the wall upside down, the picture itself doesn't get modified, you're only changing the way it's being presented.
If you need to modify the underlying image, take at look a various techniques here: How to Rotate a UIImage 90 degrees?
Upvotes: 1