Unity3d 화면 캡처.저장합니다.iOS

5564 단어 unity3d
- ( void ) imageSaved: ( UIImage *) image didFinishSavingWithError:( NSError *)error   
    contextInfo: ( void *) contextInfo  
{  
    NSLog(@" ");  
    if (error != nil) {  
        NSLog(@" ");  
    }  
}  
void _SavePhoto(char *readAddr)  
{  
    NSString *strReadAddr = [NSString stringWithUTF8String:readAddr];  
    UIImage *img = [UIImage imageWithContentsOfFile:strReadAddr];  
    NSLog([NSString stringWithFormat:@"w:%f, h:%f", img.size.width, img.size.height]);  
    PhotoManager *instance = [PhotoManager alloc];  
    UIImageWriteToSavedPhotosAlbum(img, instance,   
        @selector(imageSaved:didFinishSavingWithError:contextInfo:), nil);  
}  

 
 
 
 
 
using UnityEngine;  
using System.Runtime.InteropServices;  
   
public class TestSavePhoto : MonoBehaviour  
{  
    [DllImport("__Internal")]  
    private static extern void _SavePhoto(string readAddr);  
   
    private string _cptrAddr;  
   
    private void OnGUI()  
    {  
        if (GUILayout.Button("_SavePhoto!", GUILayout.Height(50), GUILayout.Width(200)))  
        {  
            Debug.Log("_SavePhoto");  
            var readAddr = Application.persistentDataPath + "/" + _cptrAddr;  
            _SavePhoto(readAddr);  
        }  
        if (GUILayout.Button("TakePhoto", GUILayout.Height(50), GUILayout.Width(200)))  
        {  
            Debug.Log("TakePhoto");  
            var cptrAddr = "testpic"; //   
            var readAddr = Application.persistentDataPath + "/" + cptrAddr;// , iOS   
            Debug.Log("cptr:" + cptrAddr + ", read:" + readAddr);  
            Application.CaptureScreenshot(cptrAddr);  
            _cptrAddr = cptrAddr;  
        }  
    }  
}  

좋은 웹페이지 즐겨찾기