使用相机时在iPad中收到内存警告,使应用程序崩溃

时间:2014-01-11 06:01:16

标签: c# ios ipad camera xamarin

我在iPad中使用相机时在我的应用中收到收到内存警告。它在点击“使用照片”后或打开相机后立即崩溃我的应用程序。我正在使用带有c#的Xamarin Studio来构建应用程序。我认为它与GC有关但不确定。试图释放记忆并处理物品,但没有运气。

这是我的代码:

imagePickerController.FinishedPickingMedia += (object sender1, UIImagePickerMediaPickedEventArgs e) => {
            BeginInvokeOnMainThread (delegate
                {
                    // Dismiss the image picker first to free its memory : Recieved Memory Warning
                    //imagePickerController.DismissModalViewControllerAnimated(true); : Not Working
                    if(imageOriginal == null)
                        imageOriginal = new UIImage();
                    imageOriginal = e.OriginalImage;
                    imageOriginal = ResizeImageToSize(imageOriginal,640,960);
                    imageData = imageOriginal.AsJPEG (.6f);
                    buffer = new byte[imageData.Length];
                    System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, buffer, 0, Convert.ToInt32(imageData.Length));
                    string imageContents = Convert.ToBase64String(buffer);
                    var imageName = Guid.NewGuid () + ".jpg";
                    //if already choose an image, delete that one
                    if(!string.IsNullOrEmpty(SyncManager.Current.tagLocationRecentImageName))
                    {
                        Proxy.GetBindingClientNew().DeleteTagLocationImageAsync(SyncManager.Current.tagLocationID,SyncManager.Current.tagLocationRecentImageName);
                        Proxy.GetBindingClientNew().DeleteTagLocationImageCompleted += HandleDeleteTagLocationImageCompleted;
                    }
                    Task.Factory.StartNew(()=>{
                        Proxy.GetBindingClientNew().UploadTagLocationImageAsync(imageName.ToString(),imageContents,SyncManager.Current.tagLocationTypeID);
                        Proxy.GetBindingClientNew().UploadTagLocationImageCompleted += HandleUploadTagLocationImageCompleted;
                    });

                    var documentsDirectory = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
                    string jpgFilename = System.IO.Path.Combine (documentsDirectory, imageName); // hardcoded filename, overwrites each time
                    string jpgFilenameThumb = System.IO.Path.Combine (documentsDirectory, imageName + "-thumb");
                    NSError err = null;
                    if (imageData.Save (jpgFilename, false, out err))
                    {
                        Console.WriteLine ("Your image saved with name " + jpgFilename);

                        imageOriginal = ResizeImageToSize(e.OriginalImage,65,65);
                        imageData = imageOriginal.AsJPEG (.6f);
                        imageData.Save (jpgFilenameThumb, false, out err);
                    }

0 个答案:

没有答案