2014年11月6日 星期四

VC2010 安裝 openCV 3.0

環境:Windows 7
開發:VC2010 
使用:openCV3.0

1. openCV3.0 下載
2. 下載後解壓會得到opencv資料夾

2014年10月22日 星期三

C# 最簡單的16進位轉2進位

 public string Hex2Int2Binary(string strHex)
 {
     int intNum = Convert.ToInt32(strHex, 16);
     string strBinary = Convert.ToString(intNum, 2);
     return strBinary;
 }

2014年10月8日 星期三

滑鼠畫筆[Processing]

點選滑鼠左右鍵,觸發事件

void setup(){
  size (800,800);
  noStroke();
  background(255);
//  fill(0,102,153,204);
  rectMode(CENTER);

 
}
void draw(){
  if(mousePressed && (mouseButton == LEFT)) {
      fill(0,102,153,204);
      rect(width-mouseX,height-mouseY,50,50);
      rect(mouseX,mouseY,50,50);
  }
  if(mousePressed && (mouseButton == RIGHT)){
      fill(102,102,153,204);
      ellipse(width-mouseX,height-mouseY,50,50);
      ellipse(mouseX,mouseY,50,50);
  }
}







2014年10月7日 星期二

C# FTP 目錄底下檔案搜尋


// ftpPath:FTP 位置
//ftpUser:FTP帳號
//ftpPassword:FTP密碼
//strExtension:被搜尋的副檔名
//strFileList:回傳的檔案名稱(數量要先計算,要先new好該有的數量,另一篇會教如何計算數量)
計算方式

public bool CheckFTPFileList(string ftpPath, string ftpUser, string ftpPassword, string strExtension, ref string[] strFileList)
        {
            bool success = false;
            FtpWebRequest ftpWebRequest = null;
            WebResponse webResponse = null;
            StreamReader reader = null;
            try
            {
                string url = ftpPath;
                //new 一個FTP連線
                ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(url));
                //建立FTP連線
                ftpWebRequest.Credentials = new NetworkCredential(ftpUser, ftpPassword);
                //選擇通訊協定方法
                ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory;
                //完成要求動做後,關閉連線
                ftpWebRequest.KeepAlive = false;
                // 取得FTP回應
                webResponse = ftpWebRequest.GetResponse();
                //讀取FTP資訊
                reader = new StreamReader(webResponse.GetResponseStream());

                string line = "";
                int intFileCount = 0;
                while (line != null)
                {
                    //讀取目錄下檔案名稱及根目錄名稱
                    line = reader.ReadLine();
                   //如有包含指定副檔名,即可記錄
                    if (line.Contains(strExtension))
                    {
                        strFileList[intFileCount] = line;
                        intFileCount++;
                    }
                }
            }
            catch (Exception)
            {
                success = false;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                if (webResponse != null)
                {
                    webResponse.Close();
                }
            }
            return success;
        }

C# FTP根目錄底下,指定副檔名,檔案計算數量

//ftpPath:FTP位置
//ftpUser:FTP帳號
//ftpPassword:FTP密碼
//strExtension:副檔案名稱
//intFileCount:回傳計算結果

public bool CheckFTPCount(string ftpPath, string ftpUser, string ftpPassword, string strExtension, ref int intFileCount)
        {
            bool success = false;
            FtpWebRequest ftpWebRequest = null;
            WebResponse webResponse = null;
            StreamReader reader = null;
            try
            {
                string url = ftpPath;
                //new 一個FTP連線
                ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(url));
                //建立FTP連線
                ftpWebRequest.Credentials = new NetworkCredential(ftpUser, ftpPassword);
                //選擇通訊協定方法
                ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory;
                //完成要求動做後,關閉連線
                ftpWebRequest.KeepAlive = false;
                // 取得FTP回應
                webResponse = ftpWebRequest.GetResponse();
                //讀取FTP資訊
                reader = new StreamReader(webResponse.GetResponseStream());

                string line = "";
                intFileCount = 0;
                while (line != null)
                {
                    //讀取目錄下檔案名稱及根目錄名稱
                    line = reader.ReadLine();
                   //如有包含指定副檔名,即可記錄
                    if (line.Contains(strExtension))
                    {
                        intFileCount++;
                    }

                }
            }
            catch (Exception)
            {
                success = false;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                if (webResponse != null)
                {
                    webResponse.Close();
                }
            }
            return success;
        }

C# EASendMail Lib 程式寄信教學

下載處:EASendMail
// strReceiver :收件者
//strTitle:信件標題
//strBody:信件內容
//strUserName:信箱帳號
//strPW:信箱密碼
public void SendEmail(string strReceiver, string strTitle, string strBody, string strUserName, string strPW)
        {
            try
            {
                SmtpMail oMail = new SmtpMail("TryIt");
                EASendMail.SmtpClient oSmtp = new EASendMail.SmtpClient();

                // Set sender email address, please change it to yours
                oMail.From = "XXX@gamil.com";

                // Set recipient email address, please change it to yours
                oMail.To = strReceiver;

                // Set email subject
                oMail.Subject = strTitle;

                // Set email body
                oMail.TextBody = strBody;

                // Your SMTP server address
                SmtpServer oServer = new SmtpServer("smtp.gmail.com");

                // User and password for ESMTP authentication, if your server doesn't require
                // User authentication, please remove the following codes.          
                oServer.User = strUserName;
                oServer.Password = strPW;

                // If your smtp server requires TLS connection, please add this line
                // oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;

                // If your smtp server requires implicit SSL connection on 465 port, please add this line
                oServer.Port = 465;
                oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;

                try
                {
                    oSmtp.SendMail(oServer, oMail);
                }
                catch (Exception ep)
                {
                    MessageBox.Show(ep.Message);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
來源參考

2014年9月22日 星期一

三數比大小---[C++]

#include <iostream>
#include <stdlib.h>
using namespace std;
int main (){
    int x , y ,z;
    int a ,b ,c;
    cin>>x>>y>>z;
 
   if(x>y && y>z && x>z){
        x=x ; y=y; z=z;  
        }
 
   if(x>y && z>y && x>y){
        x=x; b=y; y=z; z=b;
        }
 
   if(y>x && x>z && y>z){
        a=x; x=y;y=a;z=z;
        }

   if(y>z && z>x && y>x){
        a=x; x=y; c=z; y=c; z=a;
        }
 
   if(z>x && x>y && z>y){
        a=x;b=y;c=z;
        x=z;
        y=a;
        z=b;  
        }            
   if(z>y && y>x && z>x){
        a=x;b=y;c=z;
        x=z;
        y=b;
        z=a;
        }
   
   cout<<endl<<"1:"<<x<<" "<<"2:"<<y<<" "<<"3:"<<z;
     
    system("pause");
    return main();
    }

PS: 此方法只解決 三數一定為不同數時~

2014年9月18日 星期四

VS2013 scan與 scan_f的方法[C code]。

VS2013 在使用 scanf 在編譯的時候會出現 "_CRT_SECURE_NO_WARNINGS" 這個錯誤。

有兩種解決方法:

1. 對該方案點選右鍵 -> 屬性 -> 組態屬性 -> C/C++ -> 前置處理器 的前置處理器定義

    進行編輯, 將_CRT_SECURE_NO_WARNINGS加入。就可以正常使用scanf了。

2. 方式就是改用 scanf_s

    下面有scanf 與 scanf_s兩種寫法的參考

    const int SIZE 1024;
    char *str = new char [SIZE];

    1. scanf
        scanf("%s",  str );
        printf("%s\n", str);
        即可

    2. scanf_s多了第三個參數,是放置該陣列大小,以免溢出,較scanf安全
     
        errno_t err;
        if ((err = scanf_s("%s", str  , SIZE)) == true)
            printf("%s\n", str);

就這樣。
其中,fopen也會有這樣的狀況,所以也是同樣方式,去解決。