1. Digital Camera Filer - Source Code (update)

    這個程式其實很簡單, 最麻煩的兩個部份都找到現成的 library 就解決掉了, 剩下的就只有剪剪貼貼的手工業而以. 先介紹這個 tools 開發時用到的兩套 library:

    1. PhotoLibrary: 封裝 System.Drawing.Image 方便讀取 EXIF 等資訊.
      Project Site: http://www.gotdotnet.com/workspaces/workspace.aspx...
    2. Microsoft RAW Image Viewer: 它提供了 canon sdk 及 .net wrapper
      Download Site: http://www.microsoft.com/downloads/details.aspx?fa...

    扣掉這兩套 lib 幫的忙之外, 其它剩下的就真的沒啥好看的了... 只有一些五四三的還能拿來講一講... 底下是整個 project 的 class diagram:

    程式主要是用到 Factory Patterns, 每種要處理的檔案類型各有一種對應的 MediaFiler 類別來負責, 之後主程式就是 recursive 找出所有的檔案, 一個一個丟給 MediaFiler 處理而以. 簡單的說明一下這幾個 class:

    • class MediaFiler: 沒啥好說的, 所有的 MediaFiler 都要從這個抽像類別繼承下來. MediaFiler 會處理單一個特定格式的檔案歸檔動作.
    • class CanonPairThumbMediaFiler: 一樣是抽像類別, 不過處理的檔案類型較特別, 專門處理會附帶一個縮圖檔 ( *.thm , 內容為 JPEG 格式縮圖 ) 的檔案類型.

    扣掉這兩個 abstract class, 剩下就一個蘿蔔一個坑了... 來點名吧:

    • JpegMediaFiler: 就是處理 *.jpg 的 MediaFiler
    • CanonRawMediaFiler: 處理 *.crw (會附帶處理對應的 .thm)
    • CanonVideoMediaFiler: 處理 *.avi (會附帶處理對應的 .thm)

     

    [update: 2006/11/20]

    講這麼多還丟 source code 幹嘛? 其實有個目的, 就是這工具的架構及選用的 library 其實已經有足夠的擴充能力去適應非 canon 的檔案格式了, 改版後做了一點調整, 搭配了 Attribute 來達成這目的, 舉片段的 code 當例子:

      237         public static MediaFiler Create(string sourceFile)

      238         {

      239             FileInfo sf = new FileInfo(sourceFile);

      240             foreach (Type t in GetAvailableMediaFilers())

      241             {

      242                 //

      243                 //  match

      244                 //

      245                 MediaFilerFileExtensionAttribute ea = GetFileExtensionAttribute(t);

      246                 if (string.Compare(ea.FileExtension, sf.Extension, true) == 0)

      247                 {

      248                     //

      249                     //  file extension match

      250                     //

      251                     ConstructorInfo ctor = t.GetConstructor(new Type[] { typeof(string) });

      252                     return ctor.Invoke(new object[] { sourceFile }) as MediaFiler;

      253                 }

      254             }

      255             return null;

      256         }

      

     for loop 的部份就是列出所有已載入 AppDomain 的 Assemblies 裡所有包含的 Type, 過濾的條件是:

    1. 要繼承自 class MediaFiler
    2. class 要有貼上 MediaFilerFileExtensionAttribute 自訂屬性

    符合這兩個條件的所有 type 就會一個一個拿來比對. 也許有人會問, 用 attrib 看起來比較強嗎? 這種典型的應用不是應該用 abstract method, 讓底下的 class 來實作就好?

    是的, 如果我用 java 寫的話, 我會這麼做. 不過, polymophism 的前題就是要有 instance, 我連要用那個 class 來產生 instance 都還不曉得, 如何能享用到 polymphism 的好處? 用 static method 就沒有這種好處了, 況且 c# 語法也沒有辦法強迫衍生類別一定要 implements 某些 static method ...

    這時透過 attrib 就可以很漂亮的解決這個問題, 細節就不管了, 總之我透過 custom attribute 替每個 MediaFiler 標明, 每個 MediaFiler 負責的 file extension 為何.

    動態挑到適當的 MediaFiler 後, 剩下的就靠 Reflection 產生 instance, 收工.

     

    看起來有點小題大作, 目的只有一個, 如果有新的檔案格式要支援怎麼辦? 目前的架構很簡單, 只要加上新的 MediaFiler implementation, 然後用 custom attribute 標明它負責的是那種 file extension, 其它就通通結束了, Factory Pattern 核心的部份 Create( ) 完全不用改.

    優點不只如此, 還可以再做的徹底一點, 其它檔案類型的支援, 甚至不用改到原本的 code / .exe, 只要另外開 class library project, 寫在其它的 assembly, 丟在同一個目錄下執行就好了. 以往要做到 plug-ins  架構的程式非常麻煩, 現在十行左右的 code 就完成了.

     

    最後, 要看 source code 的人可以到下面列的網址下載整個 project. 順便廣告一下我自己寫的 zip folder http handler (H), 幹嘛用的? 直接把 zip 檔丟上來, 透過 http handler 加持, 就可以把 .zip 檔視為一個目錄了... 方便的很, 上面的 class diagram 其實就是藏在 zip 檔裡的圖而以... 我就不用另外再維護兩份檔案了 (一份圖檔, 一份 zip 下載檔)

    Source Code (Visual Studio 2005 Project): http://www.chicken-house.net/files/chicken/Chicken...

    2006/11/18 .NET 技術隨筆

  2. Canon Digital Camera 記憶卡歸檔工具 - Release Notes

    好戲不拖棚了, 這個小工具寫到現在, 大部份的問題都解決掉了, 接下來除非有碰到啥 Bug, 否則就不會再大改版了. 在這裡總結一下:

     

    overview:

    DigitalCameraFiler 是專為數位相機記憶卡歸檔用的工具, 包括一般相片, raw file, 及 video clip, 可以依照拍照時的各種資訊 (exif, 包括拍照時間, 相機型號, 光圈值, 快門值... etc) 的組合當成檔名及目錄名稱自動歸檔. 這個工具沒有 windows 介面, 為 Console Application. 可以搭配批次等等工具一起使用.

     

    how it work:

    這工具運作的方式很簡單, 它會掃描指定的目錄 (記憶卡) 下的所有檔案, 碰到支援的檔案類型就會依照定義好的歸檔動作去處理它. 以下是這個工具支援的幾種類型, 及它的處理方式:

    1. JPEG file: 最常見的類型, 碰到 *.jpg 檔會先依照 exif 裡的 Orientation 值決定要不要把照片轉正. 轉好後就把照片放到指定位置.
    2. RAW file: 支援 Canon 的 *.crw 檔案. crw 會搭配對應的 .thm 檔, 會從這兩個檔案取得必要的 exif 資訊, 用來做歸檔的動作. 除了把 .crw 放到指定位置之外, 也會另外把 .crw 轉成 .jpg 放在同一個目錄下. 在轉換檔案格式的同時, 也會把對應的 .thm 檔的 exif 都複製一份到 .jpg 檔.
    3. VIDEO file: 支援 Canon 拍攝的 MJPEG ( *.avi ) 檔. Canon 一樣會準備一份對應的 .thm 檔, 歸檔 .avi 時就會依照對應的 .thm 內的 exif 資訊為準.

     

    configuration:

    這個工具主要的目的就是依照 exif 等資訊來安排歸檔的路逕, 因此設定的方式採取 .net framework 裡通用的 format string 格式為準. 細節可以直接參考 MSDN 網站, 設定的方式如下:

    pattern: 格式化字串. 大括號 { } 內的數字代表要用後面定的第幾個 exif 代碼替代.

    exif list: 你要取用的 exif variable list. 序號從 0 開始算.

    舉例來說, 如果你指定的 pattern 為:

    " c:\photos\{0:yyyy-MM-dd}\{1}-{2}"

    而指定的 exif variable list 為:

    " DateTime,Model,FileName"

    則用我的 G2 在 2006/11/11 拍的照片 IMG_1234.jpg 則會被歸檔到這個位置:

    c:\photos\2006-11-11\Canon PowerShot G2-IMG_1234.jpg

    pattern 可以依照這樣的原則任意指定, 不存在的目錄會自動建立, 而可用的 exif variable 到底有多少? 在命令列執行這個工具, 不帶任何參數的話就會列出所有的變數名. 這些設定寫在 DigitalCameraFiler.exe.config 檔案內, pattern 可以各別為 JPEG / RAW / VIDEO 分別指定, 而 EXIF List 則是共用的.

     

    下回會把 source code 也一起 release 出來, 請有耐心點等待 :D

     

    安裝檔下載位置: http://www.chicken-house.net/files/chicken/ChickenHouse.Tools.DigitalCameraFiler.Binary.zip

    2006/11/17 .NET 技術隨筆

  3. IQ test ...

    同事給的 IQ test 網站: http://web.tickle.com/tests/uiq/index-pop.jsp?sid=...

    只有 124 分 :'(

    共有 40 題, 英文的題目... 看來敗在英文太爛, 真糟糕, 語言能力只有 40% ~ 50% 的水準 :~~~

    測完有詳細的 report, 分四個領域個別分析你的能力.. 貼一小段我的測試報告上來:

     

     

     

     

     


    Congratulations, Andrew!
    Your IQ score is 124

    This number is based on a scientific formula that compares how many questions you answered correctly on the Classic IQ Test relative to others.
    Your Intellectual Type is Precision Processor. This means you're exceptionally good at discovering quick solutions to problems, especially ones that involve math or logic. You're also resourceful and able to think on your feet. And that's just some of what we know about you from your test results.

     

     

     

    Mathematical Intelligence

    Your Mathematical Percentile
    90th percentile

    You scored in the 90th percentile on the mathematical intelligence scale.This means that you scored higher than 80% - 90% of people who took the test and that 10% - 20% scored higher than you did. The scale above illustrates this visually.
    Your mathematical intelligence score represents your combined ability to reason and calculate. You scored relatively high, which means you're probably the one your friends look to when splitting the lunch bill or calculating your waitresses' tip. You may or may not be known as a math whiz, but number crunching might come a little easier to you than it does others.

     

     

     

    Visual-Spatial Intelligence

    Your Visual-Spatial Percentile
    70th percentile

    You scored in the 70th percentile on the visual-spatial intelligence scale.
    This means that you scored higher than 60% - 70% of people who took the test and that 30% - 40% scored higher than you did. The scale above illustrates this visually.
    The visual-spatial component of intelligence measures your ability to extract a visual pattern and from that envision what should come next in a sequence. Your score was relatively high, which could mean that you're the one navigating the map when you're on an outing with friends. You have, in some capacity, an ability to think in pictures. Maybe this strength comes out in subtle ways, like how you play chess or form metaphors.

     

     

     

    Linguistic Intelligence

    Your Linguistic Percentile
    50th percentile

    You scored in the 50th percentile on the linguistic intelligence scale.
    This means that you scored higher than 40% - 50% of people who took the test and that 50% - 60% scored higher than you did. The scale above illustrates this visually.
    Linguistic abilities include reading, writing and communicating with words. Tickle's test measures knowledge of vocabulary, ease in completing word analogies and the ability to think critically about a statement based on its semantic structure. Your score was relatively low, which could just mean that you convey ideas through other means than verbally. Or maybe it just means you find other ways to spend your time than doing crossword puzzles.

     

     

     

    Logical Intelligence

    Your Logical Percentile
    100th percentile

    You scored in the 100th percentile on the logical intelligence scale.
    This means that you scored higher than 90% - 100% of people who took the test and that 0% - 10% scored higher than you did. The scale above illustrates this visually.
    Tickle's logical intelligence questions assess your ability to think things through. The questions determine the extent to which you use reasoning and logic to determine the best solution to a problem. Your logic score was relatively high, which could mean that when the car breaks down, your friends look to you to help figure out not only what's wrong, but how to fix it and how you're going to get to the next gas station.

    2006/11/15 有的沒的 當年勇

  4. IE6 縮放網頁: using css + htc

    之前在小熊子朋友 DarkThread 的網頁看到一篇, 可以不用裝 IE7 / Firefox 等就可以有縮放網頁的功能.. 不過有個限制是要在網頁加上一段 html code, 逛的網頁不是自己能改的就頭痛了...

    之前這篇講到用 css 可以把所有的網頁縮放大小, 不過縮放比例是寫死在 css 裡的... 看到 DarkThread 的那篇, 就手癢了起來, 試試用 htc + css 的方式, 看看能不能藉著這個技巧把縮放網頁的功能散佈到所有的網站上...

    htc (Html Component) 是從 IE5.0 開始的 "新技術", 基本上它的目的就像 asp.net 的 server control, 你可以透過它創造自己的 html tag, 只不過 htc 是 client side 的技術, 而 server control 是 server side 的技術, 用法很像, 技巧完全不一樣...

    htc 在 IE5.0 只是很基本的 support, 它是從 css 裡的 behavior 延伸出來的, 因為它是靠 css 的 behavior 把 html element 跟 htc 綁在一起, 因此可以透過 css 直接把功能散佈到整個網站,  就變成它最擅長的地方了, 下次貼一篇把整個網站的右鍵選單停用的例子, 超簡單...

    原理大概是這樣, 因為 IE 提供了 user 自訂 css 的功能, 你可以把你自訂的 css 檔套用在所有你的 ie 開啟的網頁, 加上 htc (html component) 可以藉著 css 套用到網頁上, 這次就來試試這兩者的組合...

    1. 在 c:\ 放了三個檔案: zoom.htc / zoom.css / zoom.html (點這裡下載)

    2. 打開 IE, 工具 -> 網際網路 -> 存取設定 -> 樣式表 -> 指定 c:\zoom.css

    3. 開網頁, c:\zoom.html

    4. 按住 ALT, 同時點一下滑鼠左鍵, 不錯, 底下跳出 select 來了, 選百分比就可以直接改變網頁放大率...

     

    看起來好像很不錯, html 裡完全跟我自訂的 css / htc 沒關係, 但是效果卻出來了 (y). 不過在早期的 IE 這樣就大功告成了, 現在的 IE 可沒那麼簡單... :'(

    接著再打開 google 首頁看看...

    Orz, 因為 c:\zoom.htc 跟 http://www.google.com.tw 在兩個不同的 security zone, 而且 domain 也不同, 兩者的 cross talk 被 IE 給檔了下來... ouch... 看來就差這個該死的安全機制... 不然一切就太完美了... 這個限制還沒有找到很簡單的解法, 有點子的人就提供一下吧... :'(

    2006/11/12 HTML/CSS 技術隨筆

  5. 沒網路...

    好不容易等到周末, 結果一回家就沒電話沒網路... 還以為沒繳錢... 打去中華電信問才知道今晚施工, 要到明早才好... :@

    沒事做只好貼一貼來抱怨一下 :@

    2006/11/11 有的沒的