System.Drawing 的 DLL 檔案可至以下目錄中找到 :
C:\Program Files\Unity\Editor\Data\Mono\lib\mono\2.0


using UnityEngine;
using System.Collections;
using System.Drawing;
using System.Threading;
using System;

public class NewBehaviourScript2 : MonoBehaviour {

public Texture2D t;
int w = 0;
int h = 0;
UnityEngine.Color32 [] c;
string path = "";

void Awake(){
path = Application.persistentDataPath;
}

void OnGUI(){
if(GUI.Button(new Rect(5,5,100,100), "ok")){
w = t.width;
h = t.height;
c = t.GetPixels32();
new Thread (Run).Start ();
}
}

int count = 1;

void Run(){
try{
Bitmap bm = new Bitmap (w, h);

int x = 0;
int y2 = 0;
for(int i = 1; i < c.Length; i++){

int y = i / w;
if(y!=y2){
x=0;
}
y2 = y;

bm.SetPixel(x++,h - y -1,System.Drawing.Color.FromArgb(c[i].r, c[i].g, c[i].b));
}

bm.Save (path + "/" + count + ".jpg");
count++;
}catch(Exception e){
print (e);
}
}

}

創作者介紹
創作者 黃彥霖 的頭像
黃彥霖

彥霖 實驗筆記

黃彥霖 發表在 痞客邦 留言(0) 人氣()