标签: uiimagepickercontroller

iOS UIImagePickerController上传后的结果图像方向

我在iOS 3.1.3 iPhone上测试我的iPhone应用程序.我使用以下方法选择/捕获图像UIImagePickerController:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setDelegate:self];
[self.navigationController presentModalViewController:imagePicker animated:YES];
[imagePicker release];



- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
    imageView.image = self.image;
    [self.navigationController dismissModalViewControllerAnimated:YES];
    submitButton.enabled = YES;
}
Run Code Online (Sandbox Code Playgroud)

然后我在某个时候使用ASI类将它发送到我的Web服务器:

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://example.com/myscript.php"]];
[request setDelegate:self];
[request setStringEncoding:NSUTF8StringEncoding];
[request setShouldContinueWhenAppEntersBackground:YES];
//other post keys/values
[request setFile:UIImageJPEGRepresentation(self.image, 100.0f) withFileName:[NSString stringWithFormat:@"%d.jpg", [[NSDate date] timeIntervalSinceNow]] andContentType:@"image/jpg" forKey:@"imageFile"];
[request startAsynchronous];
Run Code Online (Sandbox Code Playgroud)

问题:当我用iphone拍照同时保持它的风景时,图像会上传到服务器并按照你的预期进行查看.当拍摄手机拍照时,图像会被上传并在旋转90度时被观看.

我的应用程序设置为仅在纵向模式下工作(颠倒和常规).

如何在上传后使图像始终显示正确的方向?

UIImageView中显示的图像看起来是正确的(在拍照后直接显示),但在服务器上查看则另有说明.

iphone cocoa-touch uiimagepickercontroller uiimage ios

327
推荐指数
11
解决办法
13万
查看次数

将图像添加到iPhone模拟器

我想用UIImagePickerControllerUIImagePickerControllerSourceTypePhotoLibrary,但它说,"没有照片".模拟器从哪里获取图像?我应该在哪里复制图像,以便它们显示在模拟器中?

iphone photo uiimagepickercontroller ios ios-simulator

268
推荐指数
18
解决办法
15万
查看次数

iOS 8快照未呈现的视图会导致空快照

在iOS 8中,我遇到了从相机捕获图像的问题,直到现在我正在使用此代码

UIImagePickerController *controller=[[UIImagePickerController alloc] init];
controller.videoQuality=UIImagePickerControllerQualityTypeMedium;
controller.delegate=(id)self;
controller.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentViewController:controller animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

但是在iOS 8中我得到了这个:

Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
Run Code Online (Sandbox Code Playgroud)

我曾尝试与所提供的解决方案这个帖子

@property (strong,nonatomic)UIImagePickerController *controller;

_controller=[[UIImagePickerController alloc] init];
_controller.videoQuality=UIImagePickerControllerQualityTypeMedium;
_controller.delegate=(id)self;
_controller.sourceType=UIImagePickerControllerSourceTypeCamera;
_[self presentViewController:controller animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

还有这个

...
controller.modalPresentationStyle=UIModalPresentationFullScreen;
or
controller.modalPresentationStyle=UIModalPresentationCurrentContext;
...
Run Code Online (Sandbox Code Playgroud)

还有这个

double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), …
Run Code Online (Sandbox Code Playgroud)

objective-c uiimagepickercontroller ios8

228
推荐指数
10
解决办法
11万
查看次数

裁剪UIImage

我有一些调整图像大小的代码,所以我可以获得图像中心的缩放块 - 我使用它来获取UIImage并返回图像的小方形表示,类似于在专辑视图中看到的照片应用程序.(我知道我可以使用a UIImageView并调整裁剪模式以获得相同的结果,但这些图像有时会显示在中UIWebViews).

我已经开始注意到这段代码中的一些崩溃,我有点难过.我有两种不同的理论,我想知道是否有基础.

理论1)我通过绘制到目标大小的屏幕外图像上下文来实现裁剪.由于我想要图像的中心部分,我设置CGRect传递给的参数drawInRect大于我的图像上下文边界的东西.我希望这是犹太洁食,但我是否试图汲取我不应该触及的其他记忆?

理论2)我在后台线程中做了所有这些.我知道UIKit的部分内容仅限于主线程.我假设/希望绘制到屏幕外的视图不是其中之一.我错了吗?

(哦,我多么想念NSImage's drawInRect:fromRect:operation:fraction:方法.)

cocoa-touch image-manipulation objective-c uiimagepickercontroller ios

206
推荐指数
11
解决办法
17万
查看次数

在iOS中检测摄像头的权限

我正在开发一个非常简单的视频应用程序 我使用官方控件:UIImagePickerController.

这是问题所在.在第一次展示UIImagePickerController时,iOS会要求获得许可.用户可以单击是或否.如果用户单击否,则不会解除控件.相反,如果用户一直点击开始按钮,则计时器继续亮起,而屏幕始终为黑色,用户无法停止计时器或返回.用户唯一能做的就是杀死应用程序.下次呈现UIImagePickerController时,它仍然是黑屏,如果单击开始,用户将无法返回.

我想知道这是不是一个错误.我们有什么方法可以检测到相机的权限,以便我们可以决定是否显示UIImagePickerController?

permissions camera uiimagepickercontroller ios ios-permissions

137
推荐指数
3
解决办法
7万
查看次数

我可以从URL加载UIImage吗?

我有一个图像的URL(从UIImagePickerController获取)但我不再拥有内存中的图像(该URL是从以前的应用程序运行中保存的).我可以再次从URL重新加载UIImage吗?

我看到UIImage有一个imageWithContentsOfFile:但我有一个URL.我可以使用NSData的dataWithContentsOfURL:来读取URL吗?

EDIT1


根据@ Daniel的回答,我尝试了以下代码,但它不起作用......

NSLog(@"%s %@", __PRETTY_FUNCTION__, photoURL);     
if (photoURL) {
    NSURL* aURL = [NSURL URLWithString:photoURL];
    NSData* data = [[NSData alloc] initWithContentsOfURL:aURL];
    self.photoImage = [UIImage imageWithData:data];
    [data release];
}
Run Code Online (Sandbox Code Playgroud)

当我运行它时控制台显示:

-[PhotoBox willMoveToWindow:] file://localhost/Users/gary/Library/Application%20Support/iPhone%20Simulator/3.2/Media/DCIM/100APPLE/IMG_0004.JPG
*** -[NSURL length]: unrecognized selector sent to instance 0x536fbe0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL length]: unrecognized selector sent to instance 0x536fbe0'
Run Code Online (Sandbox Code Playgroud)

查看调用堆栈,我调用URLWithString,调用URLWithString:relativeToURL:,然后是initWithString:relativeToURL:,然后是_CFStringIsLegalURLString,然后是CFStringGetLength,然后是forwarding_prep_0,然后转发,然后调用 - [NSObject doesNotRecognizeSelector].

我的NSString(photoURL的地址是0x536fbe0)没有响应长度的任何想法?为什么它说它没有响应 - [NSURL长度]?难道不知道param是NSString,而不是NSURL吗?

EDIT2


好的,代码的唯一问题是字符串到URL的转换.如果我硬编码字符串,其他一切工作正常.所以我的NSString有问题,如果我无法弄清楚,我想这应该是一个不同的问题.插入此行(我从上面的控制台日志粘贴路径),它工作正常:

photoURL = @"file://localhost/Users/gary/Library/Application%20Support/iPhone%20Simulator/3.2/Media/DCIM/100APPLE/IMG_0004.JPG";
Run Code Online (Sandbox Code Playgroud)

iphone uiimagepickercontroller uiimage ios

131
推荐指数
6
解决办法
16万
查看次数

UIImagePickerController错误:在iOS 7中快照未呈现的视图会导致空快照

我只在iOS 7中收到此错误并且应用程序崩溃了.在iOS 6中,我从未收到任何错误,只是在打开相机时出现内存警告.

Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
Run Code Online (Sandbox Code Playgroud)

这就是我在做的事情.

imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setDelegate:self];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setAllowsEditing:YES];

[self presentModalViewController:imagePicker animated:YES];
Run Code Online (Sandbox Code Playgroud)

我确实试图延迟presentModalViewController,但我仍然得到相同的消息.几秒钟后(7-10),应用程序崩溃了.

此错误仅出现在iOS 7中.

有人有线索吗?先感谢您.

iphone camera uiimagepickercontroller ios ios7

103
推荐指数
4
解决办法
7万
查看次数

使用UIImagePickerController时iOS 10错误[access] <private>

我正在使用XCode 8并使用iOS 10.2 Beta进行测试.

我已将Photos,PhotosUI和MobileCoreServices框架添加到项目中.

非常简单的代码:

#import <Photos/Photos.h>
#import <PhotosUI/PhotosUI.h>
#import <MobileCoreServices/MobileCoreServices.h>

@interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate, PHLivePhotoViewDelegate>

@property (strong, nonatomic) IBOutlet UIImageView *imageview;

@end
Run Code Online (Sandbox Code Playgroud)

和实施:

- (IBAction)grab:(UIButton *)sender{
    UIImagePickerController *picker = [[UIImagePickerController alloc]init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.allowsEditing = NO;
    picker.delegate = self;

    // make sure we include Live Photos (otherwise we'll only get UIImages)
    NSArray *mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeLivePhoto];
    picker.mediaTypes = mediaTypes;

    // bring up the picker
    [self presentViewController:picker animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)

一旦我点击按钮,应用程序崩溃时出现非常无用的错误:

[access] <private>

而已.没有其他的. …

objective-c uiimagepickercontroller ios presentviewcontroller ios10

102
推荐指数
5
解决办法
6万
查看次数

presentModalViewController:在ios6中不推荐使用Animated

我使用以下代码作为图像选择器.但是当我在模拟器中运行它时,我有一个内存泄漏,我得到一个关于presentModalViewcontroller:animated在iOS6中被弃用的警告.我也被dismissModalViewController:animated弃用了.我正在使用SDK 6.1.

ImagePicker的代码:

- (void)showAlbum:(id)sender { 
    imagePicker=[[UIImagePickerController alloc]init];
    imagePicker.delegate = self;
    imagePicker.allowsEditing =NO;
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:imagePicker animated:YES];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    //release picker
    [picker dismissModalViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uiimagepickercontroller uiimage

100
推荐指数
3
解决办法
7万
查看次数

如何让用户使用Swift选择图像?

我正在用Swift编写我的第一个iOS应用程序(仅限iPhone).主应用程序视图应允许用户从照片库中选择图像.

我找到了以下ViewController.swift的示例代码:

class ViewController: UIImagePickerController, UINavigationControllerDelegate, UIImagePickerControllerDelegate  {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {

        var imagePickerController = UIImagePickerController()
        imagePickerController.delegate = self
        imagePickerController.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
        imagePickerController.allowsEditing = true
        self.presentViewController(imagePickerController, animated: true, completion: { imageP in

        })
    }


    func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: …
Run Code Online (Sandbox Code Playgroud)

uiimagepickercontroller ios swift

69
推荐指数
7
解决办法
10万
查看次数