2016-08-26 143 views
0

我已保存的图像文件系统例如路径的UIImageView设置图像是从文件系统

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

然后我有以下代码来设置的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); 

这不工作,但是.....我如何设置UIImageView的图像保存在上述路径设备上的文件?

+0

您应该使用'UIImage.FromFile(path)'而不是'UIImage.FromFile(imageName)',然后检查文件是否存在于路径上。 'if(File.Exists(path))' –

回答

1

我不知道为什么你需要为您的图标这么奇怪的路径,有一个正确的样本来设置你的形象:

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); 
    } 

这是我的解决方案的截图:

enter image description here

如果有一些特殊目的让你必须设置一个像你发布的代码的价值,给我一些细节,我会检查后者。

但可以肯定的是,如果您无法像样本那样得到正确的图像,那么您设置的路径中必定存在一些问题。

希望它能帮助你。