Unity端
- 先新建个项目吧,添加一个
Button
和两个UIimage
吧。之后我们提取的相片会在UIimage上显示。
至于为什么要两个,主要是一会我还要进行图片的压缩。然后把小图也显示出来。
- 新建个脚本,代码如下:
public void GetBigImage(string filename){
string path="file://"+platformPath+filename;
Debug.Log (path);
StartCoroutine (loadImage(path,true));
}
public void GetSmallImage(string filename){
string path="file://"+platformPath+filename;
Debug.Log (path);
StartCoroutine (loadImage(path,false));
}
public void OnClickButton(){
if(Application.platform != RuntimePlatform.OSXEditor){
_GetImage();
}
}
public string platformPath{
get{
string path=null;
if(Application.platform==RuntimePlatform.IPhonePlayer)
{
path= Application.persistentDataPath.Substring (0, Application.persistentDataPath.Length - 5);
path = path.Substring(0, path.LastIndexOf('/'))+"/Documents/";
}
else
{
path=Application.dataPath+"/GameData/";
}
return path;
}
}
IEnumerator loadImage(string path,bool isBig){
WWW www = new WWW(path);
yield return www;
if (www.isDone && www.error == null) {
if(isBig){
Big_Spr = Sprite.Create (www.texture, new Rect (0, 0, www.texture.width, www.texture.height), new Vector2 (0, 0));