0
votes

I am trying to load a large UIImage into a UIImageView without rescaling the image first.

This is what I currently have (where self.mediaView is my UIImageView):

self.mediaView.contentMode = UIViewContentModeScaleAspectFit;
self.mediaView.clipsToBounds = YES;
[self.mediaView setFrame:self.view.bounds];
NSLog(@"screen dimensions: %f x %f", _screenWidth, _screenHeight);
NSLog(@"frame size: %f x %f", self.mediaView.frame.size.width, self.mediaView.frame.size.height);
NSLog(@"image dimensions: %f x %f", self.selectedMedia.getView.image.size.width, self.selectedMedia.getView.image.size.height);
[self.mediaView setImage:self.selectedMedia.getView.image];

From my logs, I know the following:

screen dimensions: 320.000000 x 568.000000
frame size: 320.000000 x 460.000000
image dimensions: 1136.000000 x 852.000000

But when the UIImageView loads, the UIImage is cut off, so I can tell the UIImage isn't being scaled properly.

Any tips on how to fix this?

2
Your code seems correct so maybe the problem is with the imageview check with the view debugger if it exceeds the screen borders, also where are you running this method ? - Or Ron
@Or.Ron I tried the view debugger at your suggestion. When I selected the imageView, the dimensions are 320 x 460. But when I click "show clicked content" I can see that the image is still 1136x852 - scientiffic

2 Answers

0
votes

I had to set the exact width and height constraints in my storyboard (using autolayout) in order to ensure that the imageView would be constrained to a particular size).

0
votes

what does "image dimensions: 1136.000000 x 852.000000" mean?

I have two kinds of understanding.

  1. origal image's dimensions :1136.000000 x 852.000000
  2. [self.mediaView setImage:self.selectedMedia.getView.image] has been called,the image's dimensions:1136.000000 x 852.000000