使用 UIIImagePicker 的 CGAffineTransform 缩放 UIImage 并保存到 Parse SDK
问题描述
我使用以下代码来缩放我的 UIImagePickerController
.
I use the following code to scale my UIImagePickerController
.
然后我拍照并呈现在 UIImageView
Then I take the picture and present it in a UIImageView
到目前为止一切都很好.然后我通过将图像转换为 NSData
Everything is good so far. Then I send the image up to my database by converting it to NSData
当我从服务器加载数据并将其呈现在另一个相同大小的 UIImageView
中时,我确实设置了相同的纵横比:
When I load the data back from the server and present it in another UIImageView
of the same size I do set the same aspect ratio:
但图像看起来失真(水平挤压).关于为什么会这样的任何想法?
but the image looks distored (squished horizontally). Any ideas as to why this might be?
将 UIImage 转换为 NSData &保存
问题:
当我重新下载数据时,UIImage 似乎被压扁了.当我查看数据库中的图像时,它似乎很好.不知道为什么会这样……
When I redownload the data, the UIImage appears squished. When I look at the image on my database, it seems fine. Not sure why this is happening...
前后对比图:
推荐答案
在上传之前尝试标准化图像的方向.这样即使元数据丢失,图像也能正常工作
Try normalizing the image's orientation before uploading.This will allow the image to work properly even if the metadata is lost
这里有一个类别可以做到这一点:
Here is a category to do that:
UIImage+OrientationFix.h
UIImage+OrientationFix.m
您只需拨打电话:
这篇关于使用 UIIImagePicker 的 CGAffineTransform 缩放 UIImage 并保存到 Parse SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!