0

I do not wants use a picker view to pick a image. I have image name abc.JPG which is in iPhone image library, can I programmatically fetch this image and put on UIImageView?

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
user1462778
  • 23
  • 1
  • 1
  • 4
  • 1
    As far as i understand, we cannot give names to the images in the iPhone/iPad albums app. can u elaborate more on ur problem statement? – Ishank Jun 22 '12 at 07:24
  • See https://stackoverflow.com/questions/6674597/dispay-local-image-in-uiimageview – BillF Jul 22 '17 at 01:13

4 Answers4

3

If the image isn't in your application resource and you don't want to use UIImagePickerController then you can use ALAssetsLibrary to fetch the images on user albums or camera roll.

Take a look here: http://developer.apple.com/library/ios/#documentation/AssetsLibrary/Reference/ALAssetsLibrary_Class/Reference/Reference.html

ewiinnnnn
  • 995
  • 7
  • 7
2
   UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];

myImage.image = [UIImage imageNamed:@"abc.JPG"];

[self.view addSubview:myImage];

or if you have already uiimageview with name myImage then just write:

myImage.image = [UIImage imageNamed:@"abc.JPG"];
Shehzad Bilal
  • 2,535
  • 2
  • 18
  • 27
  • .thanks for reply. my image is not in my application resource folder . Image is present in simulator Library. can this code work fine for that – user1462778 Jun 22 '12 at 07:32
2

Maybe:

UIImageView *myImageView = [UIImageView alloc] init];
myImageView.image = [UIImage imageNamed:@"abc.JPG"];
Rui Peres
  • 25,741
  • 9
  • 87
  • 137
  • 2
    To the gentleman that edited my post: if I wanted to release the `UIImageView` I would. For simplicity I am assuming the op is using ARC. For the person that -1, at least have the **common sense** to explain why. – Rui Peres Jun 22 '12 at 07:23
  • thanks for reply. my image is not in my application resource folder . Image is present in simulator Library. can this code work fine for that – user1462778 Jun 22 '12 at 07:36
  • At least in iOS 6 this method is actually called `imageNamed:`. – mirkokiefer Apr 26 '13 at 12:07
0

Try to follow this tutorial.

Even if you don't want to, I think you have to use UIImagePickerViewController to pick the image, otherwise the image will be picked from Resources in your project.

Phillip
  • 4,276
  • 7
  • 42
  • 74