Presentation is loading. Please wait.

Presentation is loading. Please wait.

ImageJ Macro Language FileDemo.txt範例

Similar presentations


Presentation on theme: "ImageJ Macro Language FileDemo.txt範例"— Presentation transcript:

1 ImageJ Macro Language FileDemo.txt範例
指導教授:黃文楨 老師 學生: 蔡一清

2 取得特定目錄路徑 getDirectory(title)
Title為home、startup、current、plugins、 macros、image、temp,若為空白則會跳出 選擇檔案的對話方塊供人選擇。 範例1:getDirectory("startup")  C:\PROGRA~1\ImageJ\ 範例1:getDirectory("temp")  C:\DOCUME~1\zephyr\LOCALS~1\Temp\ 多媒體作業 2/8

3 目錄/檔案操作 File Funcion 提供讀寫、建立、刪除檔案/目錄的功能。
File.makeDirectory(path) 傳入路徑來建立目錄。 File.exists(path) 判斷所傳入目錄是否存在。  如果存在,則傳回1 File.separator 傳回"\" 或 "/"字元。 File.delete(path) 刪除特定檔案。 File.dateLastModified 傳回檔案最後修改日期時間。 File.length 回傳檔案所佔大小(bytes)。 多媒體作業 3/8

4 程式範例及執行結果(1) 程式碼 requires("1.35g"); //Get path to temp directory
tmp = getDirectory("temp"); if (tmp=="") exit("No temp directory available"); //Create a directory in temp myDir = tmp+"my-test-dir"+File.separator; File.makeDirectory(myDir); if (!File.exists(myDir)) exit("Unable to create directory"); print(""); print(myDir); 執行結果 temp ="C:\DOCUME~1\zephyr\LOCALS~1\Temp\" myDir = "C:\DOCUME~1\zephyr\LOCALS~1\Temp\my-test-dir\" 多媒體作業 4/8

5 建立影像檔案 newImage(title, type, width, height, depth) 建立影像。
Title為"8-bit"、"16-bit"、"32-bit"、"RGB"。 可附加"white ", "black " 、 "ramp",預設是"white"。 saveAs(format, path) 儲存目前影像到檔案。 format參數有"tiff", "jpeg", "gif", "bmp", "png"....等。 getTitle 取得影像標題。 getFileList (directory) 傳回目錄底下所有檔名到陣列中。 多媒體作業 5/8

6 程式範例及執行結果(2) 程式碼 //Create some images and save them in the directory
setBatchMode(true); newImage("image1", "8-bit Ramp", 400, 400, 3); saveAs("tiff", myDir+getTitle); close(); newImage("image2", "16-bit Black", 512, 512, 1); newImage("image3", "RGB Black", 512, 512, 1); wait(2000); 執行結果 多媒體作業 6/8

7 程式範例及執行結果(3) 程式碼 //Display info about the files
list = getFileList(myDir); for (i=0; i<list.length; i++) print(list[i]+": "+File.length(myDir+list[i])+" "+File. dateLastModified(myDir+list[i])); // Delete the files and the directory File.delete(myDir+list[i]); File.delete(myDir); if (File.exists(myDir)) exit("Unable to delete directory"); else print("Directory and files successfully deleted") 執行結果 image1.tif: Thu Oct 16 15:54:52 CST 2008 image2.tif: Thu Oct 16 15:54:52 CST 2008 image3.tif: Thu Oct 16 15:54:54 CST 2008 多媒體作業 7/8

8 Thank You !


Download ppt "ImageJ Macro Language FileDemo.txt範例"

Similar presentations


Ads by Google