简体   繁体   English

UIImage在UIImageView中显示不正确

[英]UIImage displaying incorrectly in UIImageView

This might not be the proper place to ask this since it seems the issue is with the actual image, but I'm hoping someone here has seen this issue before. 这可能不是一个合适的位置,因为看来问题出在实际图像上,但是我希望这里的人以前见过这个问题。

I am loading images from a server. 我正在从服务器加载图像。 First I take the photo, upload it from the server and then view it in a different part of the application. 首先,我拍摄照片,将其从服务器上传,然后在应用程序的不同部分中查看。 This is when I saw that the aspect ratio of any image I had just uploaded was way off. 这是当我看到我刚刚上传的任何图像的纵横比都大大降低时。 See image one below. 参见下图一。 Images that I had uploaded in the past did not have these issues. 我过去上传的图像没有这些问题。 The difference is that I had to pull the previous images into photoshop to rotate them. 所不同的是,我不得不将以前的图像拖入photoshop进行旋转。

I got my node.js server to orient them for me but then when I load them up in the UIImageView they are squished and stretched. 我得到了我的node.js服务器来为我定向,但是当我将它们加载到UIImageView中时,它们被压扁并拉伸了。 Viewing them in the browser or on my computer shows them as normal. 在浏览器或计算机上查看它们可以正常显示。 Out of curiosity I opened one in photoshop, did not manipulate it at all and saved it out. 出于好奇,我在photoshop中打开了一个,根本没有操纵它,将其保存了下来。 When I uploaded it to my server and viewed it on the iPhone again it looked as it should. 当我将其上传到服务器并再次在iPhone上查看时,它看起来应该是应有的状态。 See the second image below. 请参阅下面的第二张图片。

Again all other images load just fine but the ones that did not go through Photoshop come out all wonky. 同样,所有其他图像都可以正常加载,但未通过Photoshop的图像就显得很奇怪。

Any thoughts? 有什么想法吗? Thanks in advance for your help. 在此先感谢您的帮助。

在此处输入图片说明

在此处输入图片说明

EDIT : When viewing the photos in the browser they are also stretched when resized. 编辑:在浏览器中查看照片时,它们在调整大小时也会拉伸。 When I click to view full size and then click again to view the scaled to fit the screen they look fine. 当我单击以查看完整大小,然后再次单击以查看缩放以适合屏幕时,它们看起来很好。 Just wanted to throw some more info out there to see if anyone knows what's up. 只是想向那里抛出更多信息,以查看是否有人知道最新情况。

try this code, 试试这个代码,

    - (UIImage*)imageWithImage:(UIImage*)images
              scaledToSize:(CGSize)newSize;
{
    UIGraphicsBeginImageContext( newSize );
    [images drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return newImage;
}

and then set imageview imaeg this way 然后以这种方式设置imageview imaeg

   imageView.image =  [self imageWithImage:mi.imageView.image scaledToSize:CGSizeMake(78, 78)];

I'm not sure what the problem is exactly but I found a sort of solution. 我不确定问题到底出在哪里,但我找到了解决方案。

First off I tried it from a 4s to make sure it wasn't an issue with my phone and I got the same result. 首先,我从4s开始尝试以确保手机没有问题,并且得到了相同的结果。 I found out that if I strip the exif data out of the image it seems to work just fine. 我发现,如果我将exif数据从图像中剥离,则似乎工作正常。 What I ended up doing is using a package on my server, GraphicsMagic, and running the images through autoOrient. 我最终要做的是在服务器上使用GraphicsMagic包,并通过autoOrient运行图像。 After this is done and saved out to disk the images load just fine in both the browser and on the iPhone. 完成此操作并将其保存到磁盘后,图像在浏览器和iPhone上的加载都很好。 If anyone has any explanation of what would cause that, that would be great. 如果有人对造成这种情况的原因有任何解释,那就太好了。

Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM