Skip to content

Instantly share code, notes, and snippets.

@sakusan393
Created July 14, 2012 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakusan393/3111977 to your computer and use it in GitHub Desktop.
Save sakusan393/3111977 to your computer and use it in GitHub Desktop.
AIR for iOSでスクリーンショットをカメラロールに保存するANEを作ってみたけど真っ白な画面しか取れない ref: http://qiita.com/items/836ed007a1e29877e89f
//
// ScreenShotANE.m
// ScreenShotANE
//
// Created by sakurai hiroyuki on 12/07/14.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "ScreenShotANE.h"
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>
#define DEFINE_ANE_FUNCTION(fn) FREObject (fn)(FREContext context, void* functionData, uint32_t argc, FREObject argv[])
#define MAP_FUNCTION(fn, data) { (const uint8_t*)(#fn), (data), &(fn) }
//APIとなるメソッド
//FREObject TweetPost(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
DEFINE_ANE_FUNCTION(SaveScreenShot)
{
id delegate = [[UIApplication sharedApplication] delegate];
UIWindow* stage = [delegate window];
UIGraphicsBeginImageContextWithOptions(stage.frame.size, NO, 0);
//UIView.layerが真っ白。Flashの表示領域はどうしていしたらいいの???
[stage.layer renderInContext:UIGraphicsGetCurrentContext()];
NSData *pngData = UIImagePNGRepresentation(UIGraphicsGetImageFromCurrentImageContext());
UIImage *screenImage = [[UIImage imageWithData:pngData] retain];
UIImageWriteToSavedPhotosAlbum(screenImage, nil, nil, nil);
UIGraphicsEndImageContext();
NSLog(@"++++++save++++++");
return NULL;
}
//初期化関数
void SaveScreenShotContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx,
uint32_t* numFunctionsToTest, const FRENamedFunction** functionsToSet) {
*numFunctionsToTest = 1;
FRENamedFunction* func = (FRENamedFunction*)malloc(sizeof(FRENamedFunction)*1);
func[0].name = (const uint8_t*)"SaveScreenShot"; //ネイティブ拡張関数名
func[0].functionData = NULL;
func[0].function = &SaveScreenShot; //ネイティブコード関数のポインタ
*functionsToSet = func;
}
void SaveScreenShotContextFinalizer(FREContext ctx) {
return;
}
void SaveScreenShotExtInitializer(void** extDataToSet, FREContextInitializer* ctxInitializerToSet,
FREContextFinalizer* ctxFinalizerToSet) {
*extDataToSet = NULL;
*ctxInitializerToSet = &SaveScreenShotContextInitializer;
*ctxFinalizerToSet = &SaveScreenShotContextFinalizer;
}
void SaveScreenShotExtFinalizer(void* extData) {
return;
}
//
// ScreenShotANE.m
// ScreenShotANE
//
// Created by sakurai hiroyuki on 12/07/14.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "ScreenShotANE.h"
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>
#define DEFINE_ANE_FUNCTION(fn) FREObject (fn)(FREContext context, void* functionData, uint32_t argc, FREObject argv[])
#define MAP_FUNCTION(fn, data) { (const uint8_t*)(#fn), (data), &(fn) }
//APIとなるメソッド
//FREObject TweetPost(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
DEFINE_ANE_FUNCTION(SaveScreenShot)
{
id delegate = [[UIApplication sharedApplication] delegate];
UIWindow* stage = [delegate window];
UIGraphicsBeginImageContextWithOptions(stage.frame.size, NO, 0);
//UIView.layerが真っ白。Flashの表示領域はどうしていしたらいいの???
[stage.layer renderInContext:UIGraphicsGetCurrentContext()];
NSData *pngData = UIImagePNGRepresentation(UIGraphicsGetImageFromCurrentImageContext());
UIImage *screenImage = [[UIImage imageWithData:pngData] retain];
UIImageWriteToSavedPhotosAlbum(screenImage, nil, nil, nil);
UIGraphicsEndImageContext();
NSLog(@"++++++save++++++");
return NULL;
}
//初期化関数
void SaveScreenShotContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx,
uint32_t* numFunctionsToTest, const FRENamedFunction** functionsToSet) {
*numFunctionsToTest = 1;
FRENamedFunction* func = (FRENamedFunction*)malloc(sizeof(FRENamedFunction)*1);
func[0].name = (const uint8_t*)"SaveScreenShot"; //ネイティブ拡張関数名
func[0].functionData = NULL;
func[0].function = &SaveScreenShot; //ネイティブコード関数のポインタ
*functionsToSet = func;
}
void SaveScreenShotContextFinalizer(FREContext ctx) {
return;
}
void SaveScreenShotExtInitializer(void** extDataToSet, FREContextInitializer* ctxInitializerToSet,
FREContextFinalizer* ctxFinalizerToSet) {
*extDataToSet = NULL;
*ctxInitializerToSet = &SaveScreenShotContextInitializer;
*ctxFinalizerToSet = &SaveScreenShotContextFinalizer;
}
void SaveScreenShotExtFinalizer(void* extData) {
return;
}
*functionsToSet = func;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment