Leigh Ciechanowski
Leigh Ciechanowski

Reputation: 1317

UIImageView Set Image from File System

I have saved an image to the file system the path for example is

file:///private/var/mobile/Containers/Data/Application/B6DDB8AB-0F53-4DFB-A6E7-F94EBBE29F81/tmp/53bea156-8af2-4bdf-b9cc-5f160fa88d01.png

I then have the following code to set the image of an UIImageView:

var path = "file:///private/var/mobile/Containers/Data/Application/B6DDB8AB-0F53-4DFB-A6E7-F94EBBE29F81/tmp/53bea156-8af2-4bdf-b9cc-5f160fa88d01.png";
private UIImageView imageView;
imageView.Image = UIImage.FromFile(imageName);

This isn't working, however..... How do I set the image of the UIImageView for a file that's saved on the device at the above path?

Upvotes: 1

Views: 1425

Answers (1)

Alanc Liu
Alanc Liu

Reputation: 1294

I don't know why you need set a so strange path for your icon, there is a correct sample to set your image:

public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();
        // Perform any additional setup after loading the view, typically from a nib.

        UIImage image1 = UIImage.FromFile ("tips.png");
        UIImage image2 = UIImage.FromFile("Images/tips2.png");

        UIImageView imageView1 = new UIImageView (new CGRect (50, 50, 50, 50));
        imageView1.Layer.BorderColor = UIColor.Black.CGColor;
        imageView1.Layer.BorderWidth = 1;
        imageView1.Image = image1;
        this.Add (imageView1);

        UIImageView imageView2 = new UIImageView (new CGRect (50, 150, 50, 50));
        imageView2.Layer.BorderColor = UIColor.Black.CGColor;
        imageView2.Layer.BorderWidth = 1;
        imageView2.Image = image2;
        this.Add (imageView2);
    }

And this is my solution screenshot:

enter image description here

If there are some special purpose which make you must set a value like the code you posted, give me some detail about that, I will check latter.

But it's for sure that if you can not get the correct image like the sample, there must be some problems in the path you set.

Hope it can help you.

Upvotes: 3

Related Questions