简体   繁体   English

xcode,如何添加根据我在相机胶卷中选择的内容更改图像的图像视图?

[英]xcode, How do I add an image view that changes images depending on what I select in camera roll?

There is no view controller or any interfacebuilder, I want to build this with just code. 没有视图控制器或任何interfacebuilder,我只想用代码来构建它。 I have the method setup where you can click on button to go to camera roll, but now I am lost on what to do next. 我有方法设置,可以单击按钮转到相机胶卷,但是现在我迷失了下一步。 I need a way to select an image and it will allow me to add the image to an image view. 我需要一种选择图像的方法,它将允许我将图像添加到图像视图中。 Any tips on what to do will be appreciated. 任何建议做什么都将不胜感激。

 - (void)viewDidLoad {
   UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 50)];
[self.view addSubview: imgView];


UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
           action:@selector(aMethod)
 forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.view addSubview:button];
}

-(void)aMethod{

UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.allowsImageEditing = YES;
[[self navigationController] presentModalViewController:picker animated:YES];
 }

I think this could help :- 我认为这可以帮助:-

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

as delegete of imagePickerController 作为imagePickerController的imagePickerController

You can get the image by info key :- 您可以通过信息键获取图像:-

UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

For more see this link . 有关更多信息,请参见此链接

info is a dictionary containing the original image and the edited image , If an image was picked; info是包含原始图像和已编辑图像dictionary ,如果已选择图像; or a filesystem URL for the movie, if a movie was picked. 或电影的文件系统URL (如果已选择电影)。 The dictionary also contains any relevant editing information. dictionary还包含任何相关的编辑信息。 The keys for this dictionary are listed in Editing Information Keys . dictionary的键在“ 编辑信息键”中列出。

The previous answer was correct....but here is another way of looking at it.... 先前的答案是正确的...。但这是查看它的另一种方式...。

As long as you have your code calling your photo album the next step you will need is: 只要您有调用相册的代码,下一步您将需要:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}

That will place the returned info into your selected imageView..... 这会将返回的信息放入您选择的imageView中。

What you have in your posted code is opening your photo library....the net step is to say OK....Ive finished picking my media....what am I going to do with it? 您发布的代码中的内容正在打开您的照片库。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在保存在相机胶卷上的图像上添加图像方向exif元数据信息? - How do I add the image orientation exif metadata information on an image saved on the camera roll? 如何将图像保存到相机胶卷? - How can I save an image to the camera roll? 从相机和相机胶卷加载和保存图像时出现问题。 我究竟做错了什么? - Problems loading and saving images from camera and camera roll. What am I doing wrong? 如何使用AVFoundation将视频写入iPhone胶卷? - How do i write video to iphone camera roll using AVFoundation? 如何在iPhone胶卷上取回保存的图片? - How do I get back a saved picture on iPhone camera roll? 如何将视频放入 iOS 4.2 中的 iPhone 模拟器相机胶卷? - How do I get video into the iPhone simulator camera roll in iOS 4.2? 如何以编程方式将图像保存在 iPhone 的相机胶卷中? - How to save images in camera roll in iphone programmatically? 如何根据通过表视图的选择在uiview中显示不同的视图控制器(请参见说明中的图像)? - How do I display different view controllers in a uiview depending on selection through a tableview (Please see the image in description)? 将UIImagePickerController与源类型camera一起使用时,是否必须将捕获的图像保存到Camera Roll? - Must I save the captured image to the Camera Roll when using UIImagePickerController with source type camera? 我如何使用不同的图像,具体取决于iOS设备类型? - How do I use different images, depending on iOS device type?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM