0

バンドルに付属していない JPG 画像を生成し、Documents フォルダーに保存しました。ギャラリーに保存するための建物クラスを手伝ってください。

kviksilverの助けを借りてFinnaly

完全なソリューションを作成するには:

// 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;
}
4

2 に答える 2

2

あなたの答えは UIImage Class Reference の最初のページにあります。

void UIImageWriteToSavedPhotosAlbum (
   UIImage *画像、
   id完了ターゲット、
   SEL補完セレクター、
   ボイド *contextInfo
);
于 2011-06-01T17:18:31.317 に答える
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: 保存が終了したとき、または失敗したときに呼び出されます

クラスに 2 つのメソッドを作成するだけです。

-(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

}

大丈夫です –</p>

于 2011-06-01T17:14:02.870 に答える