C# 获取IOS SaveToPhotoAlbum的状态
是否可以获取UIImage的函数SaveToPhotoAlbum函数的状态 我正在尝试在保存后尽快共享照片,我需要知道照片何时保存到相册 我得到的最接近的例子是 或 我试着用电子邮件示例来实现这一点,但我得到的图像是白色的,因为我相信我在保存到相册/保存相框之前尝试过获取UIImage 这就是我保存截图的方式C# 获取IOS SaveToPhotoAlbum的状态,c#,xamarin,xamarin.ios,uiimage,C#,Xamarin,Xamarin.ios,Uiimage,是否可以获取UIImage的函数SaveToPhotoAlbum函数的状态 我正在尝试在保存后尽快共享照片,我需要知道照片何时保存到相册 我得到的最接近的例子是 或 我试着用电子邮件示例来实现这一点,但我得到的图像是白色的,因为我相信我在保存到相册/保存相框之前尝试过获取UIImage 这就是我保存截图的方式 public void ScreenGrab() { UIGraphics.BeginImageContext (UIApplication.SharedA
public void ScreenGrab()
{
UIGraphics.BeginImageContext (UIApplication.SharedApplication.KeyWindow.RootViewController.View.Frame.Size);
//new iOS 7 method to snapshot
UIApplication.SharedApplication.KeyWindow.RootViewController.View.DrawViewHierarchy (UIApplication.SharedApplication.KeyWindow.RootViewController.View.Frame, true);
UIImage image = UIGraphics.GetImageFromCurrentImageContext ();
UIGraphics.EndImageContext ();
//saves captured frame onto album
image.SaveToPhotosAlbum((SavedImage, error) => {
if(error ==null)
{
Console.WriteLine("error:" + error );
}
});
}
这就是我如何得到我的最新截图
public UIImage GetLatestImageFromAlbum()
{
UIImage image = new UIImage ();
//must return a UIImage
//Fetch all the assets based on the format given
var assets = PHAsset.FetchAssets (new PHFetchOptions (){ Predicate = NSPredicate.FromFormat (@"mediaType == " + (int)PHAssetMediaType.Image) });
//Request Options for the Image
var options = new PHImageRequestOptions () {
NetworkAccessAllowed = true,
DeliveryMode = PHImageRequestOptionsDeliveryMode.HighQualityFormat,
Synchronous = true
};
//Must check if there is access for the photo album on iOS
if (PHPhotoLibrary.AuthorizationStatus == PHAuthorizationStatus.Authorized) {
Console.WriteLine ("Access Granted");
PHImageManager.DefaultManager.RequestImageForAsset ((PHAsset)assets.LastObject, UIApplication.SharedApplication.KeyWindow.RootViewController.View.Bounds.Size, PHImageContentMode.AspectFill, options, (UIImage result, NSDictionary info) => {
image = result;
});
} else {
Console.WriteLine ("Access Denied");
}
return image;
}
出现错误时,我尝试调用GetLatestImageFromAlbum()空,但它不工作,因为我假设照片尚未完全保存,因此无法检索照片
我还尝试在ScreenGrab()之后直接调用GetLatestImageFromAlbum(),但同样的事情也发生了,就像这样
testIOS.ScreenGrab();
slComposer.AddImage(testIOS.GetLatestImageFromAlbum());
我不知道你们想用哪种语言回答,但要用Swift 2.2
UIImageWriteToSavedPhotosAlbum(image, self, #selector(self.imageSaved(_:didFinishSavingWithError:contextInfo:)), nil)
func imageSaved(image: UIImage!, didFinishSavingWithError error: NSError?, contextInfo: AnyObject?) {
if (error != nil) {
// Something wrong happened.
} else {
// Everything is alright.
}
}
我不知道你们想用哪种语言回答,但要用Swift 2.2
UIImageWriteToSavedPhotosAlbum(image, self, #selector(self.imageSaved(_:didFinishSavingWithError:contextInfo:)), nil)
func imageSaved(image: UIImage!, didFinishSavingWithError error: NSError?, contextInfo: AnyObject?) {
if (error != nil) {
// Something wrong happened.
} else {
// Everything is alright.
}
}
我找到了一种解决问题的方法,首先我们必须触发屏幕抓图,然后在更新循环中等待,以检查图像是否保存完毕(我使用布尔值进行了保存),一旦保存完毕,您就可以从相册中触发GrabLatestImageFromAlbum。我找到了一种解决问题的方法,首先,我们必须触发屏幕抓图,然后在更新循环中等待,以检查图像是否保存完毕(我使用布尔值进行了保存),一旦保存完毕,您就可以从相册中触发抓取最新估计值。我现在用c做这件事#我现在用c做这件事#