UIImage displaying incorrectly in UIImageView - ios

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!

Related

Show image of 10000x8000 pixels in iOS app

I'm trying to show image in my iOS APP.The image is of 10000x8000, which is much higher than iPhone's screen resolution, if I add it to UIImageView ,the APP will receive memory warnings and lead to crash.Can any one give me a advice about how to deal with it? Thanks a lot.
This is the sample app from apple which displays large size image, it uses TileImageView scale the image and reuse tiles according to present zoom.
https://developer.apple.com/library/ios/samplecode/LargeImageDownsizing/Introduction/Intro.html
Or if you simple want scale down the image, you could use this.
+ (UIImage*)imageWithImage:(UIImage*)image
scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
This is just a side note and not an answer.
#AmitTandel's answer will surely help you but,
remember, you should not always request for this high resolution image instead you should implement a logic which stores this high resolution image to somewhere after reducing it using #Amit's answer. And then at the time of re-requesting for the same image url, you should first look up in to your stored directory, if that image not exist only then you may request for an image.
But yes, I'm not suggesting you to follow my answer as you will require to download this very high resolution sized image (which is actually none of use), so if you're getting this image from your server, you can ask them to give you reduced size for images. I've heard that, they can reduce images to different sizes to help apps showing specific images at variant places.

In iOS image from SOAP service set as NSData is cut. Which can be the reason?

I have SOAP service. I use sudzc.com generated wrapper to access the service. During the communication I receive an image (several different images) which I have to expose. I use NSData field saved in .plist file to store the image. My problem is that in some cases The image is cut on the right side. I use Aspect fit. I am almost sure that the image is cut inside my App, because we have similar App on Android and in that App image is ok. Also I use Right and the right side is also cut.
Any ideas how to manage that situation?
EDIT:
I tried with fixed image (as poojathorat suggested). The fixed image was shown ok.
I remove all constraints and widen the area of the image in the IB but it is still cut (even it is resized - the sizes of the parts of the image are bigger).
Set the content mode of image as scaleToFill.
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.clipsToBounds = YES;

UIImage is somehow adding padding for me

I have an PNG image file foo#2x.png that is 128x128 pixels. My expectation is that when I load it on a retina device the resulting size will be 64x64 points. In fact though I am getting a UIImage* that is 100x100 pts, where the extra points (18pts on each side) are just empty (I confirmed by drawing a border in the containing UIImageView*).
I have tried loading the image via [UIImage imageNamed], [UIImage imageWithData], and [UIImage imageWithData:scale]. They all give back the same image, and I'm confused. Anyone able to explain where this extra space is coming from?
[EDIT] Per John's request,
[UPDATE] It seems this had to do with the simulator caching something from somewhere. Deleting the app from the simulator, doing a clean build, and re-running gives me the size expected. Not clear how this happened, since this isn't a changed or modified image file -- it's totally new and has never existed at 100x100 pts. Open to hearing how this could happen, but don't want to waste anyone's time chasing rabbits.
Answering my own question (see last UPDATE), somewhat bewildered but willing to move on with a healthy suspicion of what the simulator is doing.

ImageResizer rotates images

I use ImageResizer in my web application. It resizes most of the images on the page correctly. But there is one set of images, that it rotates. The code is the same for all the images.
See the following link, if you remove the querystring for ?width=500, then the image is right, but the width, resizes the image and rotates it for some reason
Please any help would be appreciated.
Cameras do not rotate images according to the orientation sensor; they just set a flag in the metadata.
Install the AutoRotate plugin and put &autorotate=true in the querystring. This will cause the image to be rotated according to the metadata prior to any rotate commands.
When I downloaded the images they were upside down, I fixed this paint.net, re-uploaded, now they are fine. The funny thing is when viewing the image in browser without the querystring they were fine.Wierd...

Problems with iOS 6 Canvas iPhone Image Upload

i've got a problem by uploading an image into the HTML 5 Canvas Object.
When i was uploading the images with my computer it works fine and i have no problems. but when any image is uploaded from the iPhone-Camera, the origin height is getting distorted.
how can i fix this bug?
does any one know, how to fix this, working together with fabric.js ? because i'm not drawing the images into the canvas 2d context but in the layers of the fabric.js. this is important to get the full interactivity with all items, drawn on canvas.
i hope anyone could help me.
thanks in advance
P.S
Don't know if this answer is related to yours but it might get you in the right direction:
Mobile Safari renders <img src="data:image/jpeg;base64..."> scaled on Canvas?

Resources