【发布时间】:2017-08-19 19:58:40
【问题描述】:
如何在 UIImageView 组件中显示来自硬盘的图像?
我有一个名为“images”的本地文件夹,并希望通过一个亲戚访问它 路径,因为我想用应用程序打包图像。
【问题讨论】:
标签: ios objective-c iphone imagesource
如何在 UIImageView 组件中显示来自硬盘的图像?
我有一个名为“images”的本地文件夹,并希望通过一个亲戚访问它 路径,因为我想用应用程序打包图像。
【问题讨论】:
标签: ios objective-c iphone imagesource
要从驱动器上的某个位置加载图像,请使用:
UIImage * myImage = [UIImage imageWithContentsOfFile: @"../images/1.png"];
或者将图片添加到Xcode项目中并使用:
UIImage * myImage = [UIImage imageNamed: @"1.png"];
然后将图像添加到 imageview:
UIImageView * myImageView = [[UIImageView alloc] initWithImage: myImage];
【讨论】:
只要图片在资源文件夹中,就不需要提供任何路径。
您可以使用它在 imageView 中显示该图像。
yourImageView.image = [UIImage imageNamed:@"something.png"];
【讨论】:
UIImage *img = [UIImage imageWithContentsOfFile:(the file path)];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
【讨论】:
硬盘中的图像是什么意思。你是说你已经将图像保存在 iphone 应用程序的捆绑包中。如果是这样,那么你可以像这样制作这些图像的数组......
NSMutableArray *imageArray;
imageArray=[[NSMutableArray alloc]initWithObjects:@"001.jpg",@"002.jpg",@"003.jpg",@"004.jpg",nil];
然后可以通过这个数组访问你的图片;
或者,如果您只是想显示捆绑包中的单个图像,您可以这样做
UIImageView *creditCardImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 16, 302, 77)];
creditCardImageView.image=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"CreditCard_2RowTable" ofType:@"png"]];
[self.view addSubview:creditCardImageView];
这会对你有所帮助。
【讨论】: