我如何将 NSData 文件作为视频写入 Photolibrary/SavedPhotosAlbum?

发布于 2024-12-02 21:28:07 字数 1006 浏览 1 评论 0原文

我有一个 NSData 视频文件。如何将 NSData 文件作为视频写入 Photolibrary/SavedPhotosAlbum?

我通过以下代码使用 UIimage 完成了它。我有一个 UiImage 作为 myNsData(NSData)

UIImage *viewImage = [UIImage imageWithData:myNsData];    

  ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];  
  // Request to save the image to camera roll  
  [library writeImageToSavedPhotosAlbum:[viewImage CGImage] orientation:(ALAssetOrientation)[viewImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
}

我怎样才能为视频实现相同的功能。

我在 NSData cals 中搜索。

我发现只有两种方法。 他们

(void)writeVideoAtPathToSavedPhotosAlbum:(NSURL *)videoPathURL completionBlock:(ALAssetsLibraryWriteVideoCompletionBlock)completionBlock;

- (BOOL)videoAtPathIsCompatibleWithSavedPhotosAlbum:(NSURL *)videoPathURL;

中的两个正在使用 URL。实际上,我不想将 NSData 文件写入除 Photolibrary/SavedPhotosAlbum 之外的任何地方。

我需要将 NSData 文件直接写入 Photolibrary/SavedPhotosAlbum,就像我保存图像一样。该怎么做?有人可以帮助我吗?

i have a Video file as NSData.how can i write the NSData file as Video in to Photolibrary/SavedPhotosAlbum?

i done it with UIimage through the following code. i had a UiImage as myNsData(NSData)

UIImage *viewImage = [UIImage imageWithData:myNsData];    

  ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];  
  // Request to save the image to camera roll  
  [library writeImageToSavedPhotosAlbum:[viewImage CGImage] orientation:(ALAssetOrientation)[viewImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
}

how can i do it the same functionality for Video.

i searched in NSData calss .

i found only two ways.
they are

(void)writeVideoAtPathToSavedPhotosAlbum:(NSURL *)videoPathURL completionBlock:(ALAssetsLibraryWriteVideoCompletionBlock)completionBlock;

- (BOOL)videoAtPathIsCompatibleWithSavedPhotosAlbum:(NSURL *)videoPathURL;

two of them are using URL.actually i didn't want to write the NSData file any where except in Photolibrary/SavedPhotosAlbum.

i need to write the NSData file directly in to the Photolibrary/SavedPhotosAlbum like i saved an image.How can do that?can any one Help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缱绻入梦 2024-12-09 21:28:07

您需要使用视频 AVAssetWriterInput 创建 AVAssetWriter 并将数据添加到输入中。

创建 AVAssetWriter 时,需要指定资产的 URL。

之后,您可以使用 ALAssetsLibrary (writeVideoAtPathToSavedPhotosAlbum:completionBlock:) 将资产写入照片库,并使用上面创建的资产的 url。

You need to create an AVAssetWriter with a video AVAssetWriterInput and add your data into the input.

When you create the AVAssetWriter, you need to specify an URL for the asset.

After you can use the ALAssetsLibrary (writeVideoAtPathToSavedPhotosAlbum:completionBlock:) to write the asset to the photo library, with the url of the asset created above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文