我已经生成了JPG图像,保存到Documents文件夹,没有捆绑包。 请帮助建筑类将其保存到图库。
Finnaly在kviksilver
的帮助下要制定完整的解决方案:
// tools.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface tools : NSObject {
}
@end
// tools.m
#import "tools.m"
@implementation tools
-(IBAction)saveImage{
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory=[paths objectAtIndex:0];
NSString *imagePath=[documentsDirectory stringByAppendingPathComponent:@"file7.jpg"];
UIImage *image=[UIImage imageWithContentsOfFile:imagePath];
UIImageWriteToSavedPhotosAlbum(image, self,@selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil);
}
@end
最后必须从CPP包装器调用它:
void onCPPSaveImgToCamRoll ( )
{
return saveImage;
}
答案 0 :(得分:2)
您的答案位于UIImage类参考的第一页。
void UIImageWriteToSavedPhotosAlbum ( UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo );
答案 1 :(得分:0)
尝试像这样获取imagePath:
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory=[paths objectAtIndex:0];
NSString *imagePath=[documentsDirectory stringByAppendingPathComponent:@"Image.jpg"];
然后设置图像:
UIImage *image=[UIImage imageWithContentsOfFile:imagePath];
UIImageWriteToSavedPhotosAlbum(image, self,@selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil);
savedPhotoImage:didFinishSavingWithError:contextInfo:将在完成保存或失败后调用
在你的班级中创建两个方法:
-(void)saveImage{
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory=[paths objectAtIndex:0];
NSString *imagePath=[documentsDirectory stringByAppendingPathComponent:@"Image.jpg"];
UIImage *image=[UIImage imageWithContentsOfFile:imagePath];
UIImageWriteToSavedPhotosAlbum(image, self,@selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil);
}
- (void)savedPhotoImage:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInf{
// possible error handling
}
你应该没事 -