Iphone 将照片保存到自定义库
我的问题真烦人。我正在创建一个应用程序,它可以拍摄照片,并需要将照片保存到自定义图库。我已经找到了一些关于如何使用AlassetLibrary执行此操作的教程,但有一个大问题。。。没有Iphone 将照片保存到自定义库,iphone,objective-c,ios6,photo-gallery,alassetslibrary,Iphone,Objective C,Ios6,Photo Gallery,Alassetslibrary,我的问题真烦人。我正在创建一个应用程序,它可以拍摄照片,并需要将照片保存到自定义图库。我已经找到了一些关于如何使用AlassetLibrary执行此操作的教程,但有一个大问题。。。没有saveImage:toAlbum:withCompletionBlock:方法。我已使用addAssetGroupAlbumWithName:resultBlock:failureBlock:创建自定义相册,但无法将图像保存到此图库!我使用的是iOS 6和iPhone4 有什么想法吗 您在问题saveImage:
saveImage:toAlbum:withCompletionBlock:
方法。我已使用addAssetGroupAlbumWithName:resultBlock:failureBlock:
创建自定义相册,但无法将图像保存到此图库!我使用的是iOS 6和iPhone4
有什么想法吗 您在问题
saveImage:toAlbum:withCompletionBlock
中提到的方法不属于。这个方法是用英文写的。必须在类中导入类别才能使用该方法
要了解有关objective C category的更多信息,请查看开发人员。查看此处:
这里有一个Stackoverflow线程:如果您使用的是AssetLibrary,那么您可以编写以下代码
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIImagePickerController *imagePicker;
if (buttonIndex < 2)
{
self.library = [[[ALAssetsLibrary alloc] init] autorelease];
self.imageEditor = [[[DemoImageEditor alloc] initWithNibName:@"DemoImageEditor" bundle:nil] autorelease];
self.imageEditor.doneCallback = ^(UIImage *editedImage, BOOL canceled){
if(!canceled)
{
anotherImage = true;
NSString *imageName;
imageName =@"Abc.jpg";
UIImageWriteToSavedPhotosAlbum(editedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
editedImage = [self scaleImage:editedImage toSize:CGSizeMake(600,600)];
[[NSUserDefaults standardUserDefaults] setObject:UIImagePNGRepresentation(editedImage)forKey:@"image"];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
if (error)
alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
else
alert = [[UIAlertView alloc] initWithTitle:@"Success"
message:@"Image saved to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert release];
}
-(作废)操作表:(UIActionSheet*)操作表单击按钮索引:(NSInteger)按钮索引
{
UIImagePickerController*图像选择器;
如果(按钮索引<2)
{
self.library=[[AlassetLibrary alloc]init]autorelease];
self.imageEditor=[[DemoImageEditor alloc]initWithNibName:@“DemoImageEditor”捆绑包:nil]自动释放];
self.imageEditor.doneCallback=^(UIImage*editedImage,BOOL已取消){
如果(!取消)
{
另一个图像=真;
NSString*imageName;
imageName=@“Abc.jpg”;
UIImageWriteToSavedPhotosAlbum(编辑图像,self,@selector(图像:didFinishSavingWithError:contextInfo:),无);
EditeImage=[自缩放图像:EditeImage toSize:CGSizeMake(600600)];
[[NSUserDefaults standardUserDefaults]setObject:UIImagePNGRepression(EditeImage)forKey:@“image”];
}
-(无效)图像:(UIImage*)图像未完成保存错误:(N错误*)错误上下文信息:(无效*)上下文信息
{
UIAlertView*警报;
如果(错误)
警报=[[UIAlertView alloc]initWithTitle:@“错误”
消息:@“无法将图像保存到相册。”
代表:自动取消按钮:@“确定”
其他按钮:无];
否则
警报=[[UIAlertView alloc]initWithTitle:@“成功”
消息:@“图像已保存到相册。”
代表:自动取消按钮:@“确定”
其他按钮:无];
[警报发布];
}
这会解决你的问题。你检查过了吗?是的,我之前看到过,但看看我在@Vignesh回复下的评论:)谢谢!我没有意识到这是一个类别…我在网上搜索并撕下了我的头发,最后:我还有一个问题。是否可以修改这个类别而不将这些照片保存到相机卷中?只有custom相册。@Cojoj。不客气。这是不可能的。所有图像都将存储在照相胶卷中。你不能停止。