将 JPG 图像从文档保存到相册 - 示例代码
我已经生成了 JPG 图像,保存到 Documents 文件夹中,该图像不随捆绑包一起提供。 请帮助建筑类别将其保存到图库。
最后在 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;
}
I have generated JPG image, saved to Documents folder, that not comes with bundle.
Please help with the building class for saving it to Gallery.
Finnaly with help of kviksilver
To make complete solution:
// 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
In the end have to call it from CPP wrapper:
void onCPPSaveImgToCamRoll ( )
{
return saveImage;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的答案位于 UIImage 类参考的第一页中。
Your answer is in the first page of the UIImage Class Reference.
尝试像这样获取imagePath:
然后设置图像:
savedPhotoImage:didFinishSavingWithError:contextInfo:将在完成保存或失败时调用只需
在类中创建两个方法:
你应该没问题 -
try getting imagePath like this:
then setting image:
savedPhotoImage:didFinishSavingWithError:contextInfo: will be called when finished saving or failing
just create two methods in your class:
and you should be ok –