在UIImageView中显示本地图片

发布于 2024-11-19 22:01:45 字数 93 浏览 4 评论 0原文

如何在 UIImageView 组件中显示来自硬盘的图像?

我有一个名为“images”的本地文件夹,想通过亲戚访问它 路径,因为我想将图像与应用程序打包。

How do I display an image in the UIImageView component from the hard drive?

I have a local folder called "images" and would like to access it via a relative
path, since I want to package the images with the app.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

乖乖 2024-11-26 22:01:46

只要图像位于资源文件夹中,您就不需要提供任何路径。

您可以使用它在 imageView 中显示该图像。

yourImageView.image = [UIImage imageNamed:@"something.png"];

You dont need to give any path as long as the image is in your resources folder.

You can display that image in the imageView using this.

yourImageView.image = [UIImage imageNamed:@"something.png"];
假情假意假温柔 2024-11-26 22:01:46
UIImage *img = [UIImage imageWithContentsOfFile:(the file path)];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];

检查文档 imageWithContentsOfFile:

UIImage *img = [UIImage imageWithContentsOfFile:(the file path)];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];

check the docs for imageWithContentsOfFile:

在梵高的星空下 2024-11-26 22:01:46

硬盘中的图像是什么意思?您是说您已将图像保存在 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];

这会对您有所帮助。

What do you mean by images in hard drive.Are you saying that you have kept your images in your bundle in iphone app.If so then you can make array of those images like this....

NSMutableArray *imageArray;
imageArray=[[NSMutableArray alloc]initWithObjects:@"001.jpg",@"002.jpg",@"003.jpg",@"004.jpg",nil];

And then can access your images by this array;

Or if you simply want to show a single image from the bundle you can do this way

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];

This will help you.

橪书 2024-11-26 22:01:45

要从驱动器上的某个位置加载图像,请使用:

UIImage * myImage = [UIImage imageWithContentsOfFile: @"../images/1.png"];

或将图像添加到 Xcode 项目并使用:

UIImage * myImage = [UIImage imageNamed: @"1.png"];

然后将图像添加到 imageview:

UIImageView * myImageView = [[UIImageView alloc] initWithImage: myImage];

To load image from somewhere on your drive use:

UIImage * myImage = [UIImage imageWithContentsOfFile: @"../images/1.png"];

Or add image to the Xcode project and use:

UIImage * myImage = [UIImage imageNamed: @"1.png"];

After that add image to imageview:

UIImageView * myImageView = [[UIImageView alloc] initWithImage: myImage];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文