Iphone 将JPG图像从文档保存到相册-示例代码
我已经生成了JPG图像,保存到Documents文件夹中,这不是捆绑包附带的。 请帮助将建筑类保存到Gallery 最后借助于 要制定完整的解决方案: //工具Iphone 将JPG图像从文档保存到相册-示例代码,iphone,xcode,ios,photo-gallery,Iphone,Xcode,Ios,Photo Gallery,我已经生成了JPG图像,保存到Documents文件夹中,这不是捆绑包附带的。 请帮助将建筑类保存到Gallery 最后借助于 要制定完整的解决方案: //工具 #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface tools : NSObject { } @end 最后必须从CPP包装器调用它: void onCPPSaveImgToCamRoll ( ) { retur
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface tools : NSObject {
}
@end
最后必须从CPP包装器调用它:
void onCPPSaveImgToCamRoll ( )
{
return saveImage;
}
尝试按如下方式获取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
}
您应该没问题–您的答案在UIImage类参考的第一页 void UIImageWriteToSavedPhotosAlbum ( UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo ); void UIImageWriteToSavedPhotosAlbum( UIImage*图像, id completionTarget, SEL补全选择器, void*contextInfo );
为数不多的几个事实上完全直截了当的例子之一:不要忘记包括savedPhotoImage:didfish。。。方法,使应用程序不会崩溃..:-D void UIImageWriteToSavedPhotosAlbum ( UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo );