UIImagePickerController每秒拍摄一次黑屏

时间:2014-10-22 13:40:34

标签: ios xamarin.ios xamarin ios8 uiimagepickercontroller

在所有iOS 8设备上,当我使用UIImagePickerController时,我正面临一个新问题(在iOS 7上它工作正常)。 第一枪按预期工作。当我尝试拍摄另一张照片时,UIImagePickerController会出现但显示黑屏。

所有控件如开关相机,取消和拍照按钮均可用且正常工作。如果我尝试制作第二张照片并触摸按钮,我会正确预览拍摄的照片。如果我保存该照片并尝试制作另一张照片,则所有照片都按预期运行。只有第四张照片再次出现同样的问题。等等...

这是我的代码:

public void ButtonCameraClicked(object sender, EventArgs eventArgs)
{
    _imagePickerDelegate = new ImagePickerControllerDelegate(this);
    _imagePicker = new UIImagePickerController();
    _imagePicker.ImagePickerControllerDelegate = _imagePickerDelegate;

    if (UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera))
        _imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
    else
        _imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;

    PresentViewController(_imagePicker, true, null);
}

public override void FinishedPickingMedia(UIImagePickerController picker, NSDictionary info)
{
    BTProgressHUD.Show("Bild wird gespeichert...");
    var image = (UIImage)info.ObjectForKey(new NSString("UIImagePickerControllerOriginalImage"));
    image.SaveToCustomPhotosAlbum(info[UIImagePickerController.MediaMetadata] as NSDictionary, _controller.AlbumName, _controller.MediaSaved);
    picker.DismissViewController(true, null);
}

我已经谷歌搜索了很多尝试过以下的事情而没有任何成功

只初始化

if (_imagePicker == null)
{
    _imagePickerDelegate = new ImagePickerControllerDelegate(this);
    _imagePicker = new UIImagePickerController();
    _imagePicker.ImagePickerControllerDelegate = _imagePickerDelegate;
}

或使用完成功能块

PresentViewController(_imagePicker, true, () => { });

PresentViewController(_imagePicker, true, () => { Thread.Sleep(300); });

或与主线程同步

InvokeOnMainThread(() => { ... });` 
`NSOperationQueue.MainQueue.AddOperation(() => { ... });

整个代码文件位于:https://gist.github.com/anonymous/83a855d44d697235849b

1 个答案:

答案 0 :(得分:0)

我尝试了你尝试过的所有东西然后决定走另一条路。组件商店中的Xamarin.Mobile组件不仅提供了相机的跨平台实现,而且在我的测试中不受同一iOS 7+黑色预览屏幕问题的影响。

来自 https://components.xamarin.com/gettingstarted/xamarin.mobile

的示例用法
using Xamarin.Media;
using System.Threading;
using System.Threading.Tasks;
//...


var picker = new MediaPicker();
MediaPickerController controller = picker.GetTakePhotoUI (new StoreCameraMediaOptions {
   Name = "test.jpg",
   Directory = "MediaPickerSample"
});

// On iPad, you'll use UIPopoverController to present the controller
PresentViewController (controller, true, null);

controller.GetResultAsync().ContinueWith (t => {
// Dismiss the UI yourself
   controller.DismissViewController (true, () => {
    //might want to add if(t.Result.Status = task.enumstatus.rantocompletion)
    //or camera cancels will throw exceptions
    MediaFile file = t.Result;
    });

}, TaskScheduler.FromCurrentSynchronizationContext());