zoukankan      html  css  js  c++  java
  • Unity3d 屏幕截图。并保存。iOS

    - ( 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;  
            }  
        }  
    }  
  • 相关阅读:
    汉诺塔
    给出一个字符串,要求插入最少的字符,使得原字符串为一个回文串
    最长回文子串
    回文数 第N个回文数
    屋子里有1到100号100盏关闭的灯
    无头结点的单链表删除一个中间结点
    单链表逆转
    编程之美2.21 加法
    在一个数组中找 差值最大的两个数 差值最小的两个数 推广到 点对
    斐波那契
  • 原文地址:https://www.cnblogs.com/qingjoin/p/3671430.html
Copyright © 2011-2022 走看看