0

I'm trying to show an image with following method:

[myImageView setImage:[UIImage imageNamed:@"myImage.png"]];

And it's working just fine with the iPhone simulator. However, when I debug on the device, the image is not visible.

Clearly it's about resolution because the resolution of my image is much more higher than UIImageView's(and it has to be...) and also when I use an image with same resolution of UIImageView, it's working fine on device, too.

I tried what said here but it didn't solve my problem.

What do you suggest to make UIImageView work with larger images than its frame?

Thanks in advance.

Community
  • 1
  • 1
kubilay
  • 5,047
  • 7
  • 48
  • 66

4 Answers4

0

If image resolution is your problem, try the solution provided here. Else, try the sample PhotoScroller in Apple's Reference Library. It provides a way to display big images in chunks (tiles). That should do what you want.

Community
  • 1
  • 1
iOS
  • 3,526
  • 3
  • 37
  • 82
0

Do this,

myImageView=[[UIImageView alloc]initWithFrame:CGRectMake(50,50,200,300)];
[myImageView setImage:[UIImage imageNamed:@"myImage.png"]];
[self.view addSubView:myImageView];

It will work.

Vineesh TP
  • 7,755
  • 12
  • 66
  • 130
  • The UIImageView is an IB element but I tried your code anyway, it didn't work. Thank you. – kubilay Sep 10 '12 at 05:58
  • Do you have anotherView ? and add SubView on self.view – Vineesh TP Sep 10 '12 at 06:00
  • It's all about this: http://stackoverflow.com/questions/4449256/download-and-save-image-to-root#comment4859514_4449256 "imageNamed: works only with images you deployed with your app-package. But you can't write to this package - you have to save your image to your app documents folder." I'm downloading images... Thanks again. – kubilay Sep 10 '12 at 06:21
0

This is the simplest issue that can occur sometimes. It is because of the image name case sensitivity required in the device while the simulator ignore the case sensitivity for the image name.

So, make sure your image name in the bungle is exactly the same what you are specified here. Not even on capital or small letter difference. Just check the image name - "myImage.png"

Please let me know if you still have any problem in the UIImageView image display.

AppAspect
  • 4,461
  • 2
  • 30
  • 46
  • Thanks, but as I said in my comment under the question, I'm using numeric file names so that shouldn't be the problem. – kubilay Sep 10 '12 at 05:57
0

Since I'm downloading images to show in runtime, I'm getting the application main bundle path with this code below:

NSString *path = [NSString stringWithFormat:@"%@", [[NSBundle mainBundle] executablePath]];
NSArray *parts = [path componentsSeparatedByString:@"/"];
NSString *pathToSave = [path substringToIndex:([path length] - [[NSString stringWithFormat:@"%@", [parts objectAtIndex:[parts count]-1]] length])];

And I save images with this code:

NSString *url = [NSString stringWithFormat:@"%@", [imageURLs objectAtIndex:0]];
NSString *filename = [url lastPathComponent];
NSData *thedata = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
NSString *localFilePath = [NSString stringWithFormat:@"%@%i%@", pathToSave, [[NSString stringWithFormat:@"%@", [element child:@"id"]] intValue], filename];
[thedata writeToFile:localFilePath atomically:YES];

When I manually download an image and add to project, [UIImageView setImage:] did work this time. So I realized that there's something wrong with saving images from URL.

The reason I didn't think this should be the problem is that it's working just fine with the iOS simulator.

I'll take a look at that issue, however since my application name contains special characters like "İ" (Turkish) I think that might be the reason, the application might not be able to save to correct path.

kubilay
  • 5,047
  • 7
  • 48
  • 66