ハード ドライブから UIImageView コンポーネントに画像を表示するにはどうすればよいですか?
「images」というローカル フォルダーがあり、アプリで画像をパッケージ化したいので、相対パス経由でアクセスしたいと考えています。
ハード ドライブから UIImageView コンポーネントに画像を表示するにはどうすればよいですか?
「images」というローカル フォルダーがあり、アプリで画像をパッケージ化したいので、相対パス経由でアクセスしたいと考えています。
ドライブのどこかからイメージをロードするには、次を使用します。
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];
imageWithContentsOfFileのドキュメントを確認してください。
ハードドライブの画像とはどういう意味ですか.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];
これはあなたを助けるでしょう。