相关疑难解决方法(0)

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万
查看次数

如何更改AVCaptureVideoDataOutput的视频方向


这是问题所在.我正在使用AVCaptureVideoDataOutput从相机获取视频帧并使用AVAssetWriter从它们制作视频.它工作正常,但我得到的视频是颠倒的,因为我的应用程序的设备的默认方向是横向左侧,而不是像AVCaptureVideoDataOutput中默认声明的那样.我试图改变AVCaptureConnection类中的方向,但isVideoOrientationSupported总是假的,是否有可能修复它?

这是一些代码:

 AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput 
            deviceInputWithDevice:[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] 
            error:nil];
 /*We setupt the output*/
 AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init]; 
 captureOutput.alwaysDiscardsLateVideoFrames = YES; 
 captureOutput.minFrameDuration = CMTimeMake(1.0, 24.0); //Uncomment it to specify a minimum duration for each video frame
 [captureOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];

 // Set the video output to store frame in BGRA (It is supposed to be faster)
 NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey; 
 NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA]; 



 NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key]; 
 [captureOutput setVideoSettings:videoSettings]; 


 /*And we create a capture session*/
 self.captureSession …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c

12
推荐指数
2
解决办法
2万
查看次数

AVAssetTrack preferredTransform始终返回格局

我有应用程序记录视频.

要处理电话轮换,我有以下代码:

    // called on phone rotation
    AVCaptureConnection *previewLayerConnection = [[self previewLayer] connection];
    if ([previewLayerConnection isVideoOrientationSupported]) {
        [previewLayerConnection setVideoOrientation:[self getVideoOrientation]];
    }
Run Code Online (Sandbox Code Playgroud)

和getVideoOrientation函数:

- (AVCaptureVideoOrientation) getVideoOrientation {
    UIInterfaceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
    AVCaptureVideoOrientation newOrientation = AVCaptureVideoOrientationPortrait;
    switch (deviceOrientation) {
        case UIInterfaceOrientationPortrait:
            NSLog(@"UIInterfaceOrientationPortrait");
            newOrientation = AVCaptureVideoOrientationPortrait;
            break;
        case UIInterfaceOrientationLandscapeLeft:
            NSLog(@"UIInterfaceOrientationLandscapeRight");
            newOrientation = AVCaptureVideoOrientationLandscapeLeft;
            break;
        case UIInterfaceOrientationLandscapeRight:
            NSLog(@"UIInterfaceOrientationLandscapeLeft");
            newOrientation = AVCaptureVideoOrientationLandscapeRight;
            break;
        default:
            NSLog(@"default");
            newOrientation = AVCaptureVideoOrientationPortrait;
            break;
    }

    return newOrientation;
}
Run Code Online (Sandbox Code Playgroud)

应用程序的这一部分正常工作(我在任何设备方向上都可以看到视频).但是当我尝试制作缩略图(或播放视频)时,我遇到了问题.

正如我在其他问题中所读到的,我为每首曲目做了以下事情:

        AVAssetTrack* videoTrack    = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
        CGAffineTransform txf …
Run Code Online (Sandbox Code Playgroud)

avfoundation ios

7
推荐指数
1
解决办法
1163
查看次数