简体   繁体   中英

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.

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. 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. When I uploaded it to my server and viewed it on the iPhone again it looked as it should. 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.

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.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. I found out that if I strip the exif data out of the image it seems to work just fine. What I ended up doing is using a package on my server, GraphicsMagic, and running the images through autoOrient. After this is done and saved out to disk the images load just fine in both the browser and on the iPhone. If anyone has any explanation of what would cause that, that would be great.

Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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