Google Code Prettify

2013年11月18日 星期一

C# 用 ZXing 產生 QR Code QR Code generator using ZXing



最近在產生QR code時發現了一個不錯的open source,

就是  ZXing.Net 

它可以支援 .net2.0, 3.5, 4.0, 4.5, 而且又是免費的,

程式碼也非常簡單喔!

網路上有很多分享都是 using com.zxing,好像在現在新的版本已經不適用了



編譯環境:

windows7 64bit

.Net Framework 4.5

visual studio 2012 express

ZXing.Net.0.12.0.0


1.下載 ZXing.Net 

2.把DLL加到專案中

依造自己的 .Net Framework 來選擇 DLL



3.Code

//  Created by vince 
//  Copyright (c) 2013年 vince. All rights reserved.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using ZXing;                  // for BarcodeWriter
using ZXing.QrCode;           // for QRCode Engine

namespace qrcode_tutorial
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e) 
        {
            var writer = new BarcodeWriter  //dll裡面可以看到屬性
            {             
                Format = BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions //設定大小
                {
                    Height = 300,
                    Width = 300,
                }
            };
            pictureBox1.Image = writer.Write(textBox1.Text); //轉QRcode的文字             
        }
    }
}



4.執行結果


Arduino 具有模擬功能的 arduino 線上模擬程式123D Circuits


前這陣子才入手 arduino 在玩,

有時候線接了一大堆,才發現有小地方接反,花了滿多時間debug,

後來就一直想說有沒有一種模擬程式可以模擬結果的,

想不到今天剛好就看到啦,而且是線上版免下載的喔!

網址在這:123D Circuits


選擇 sign up for 123D Circuits



可以註冊或用facebook登入




選擇 New circuit





選擇 Arduino + breakboad...

Create New! 就可以進行編輯了喔!







2013年11月17日 星期日

C# 開啟 outlook 與網頁 open outlook and website


在做網頁的開啟或 outlook 的呼叫時,

System.Diagnostic 的命名空間中裡的 Process 類別,可以簡單的幫我們處理


編譯環境

windows7 64bit

.Net Framework4.5(測到.Net3.5都能用)

visual studio 2012 express





Code:

//  Created by vince 
//  Copyright (c) 2013年 vince. All rights reserved.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;  //使用process需增加

namespace c_sharp_outlook_tutorial_and_website
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string mailInfo = string.Format("mailto:{0}?Subject={1}&Body={2}", "vince@mail.com", "test", "hello!");
            Process myProcess = new Process();
            myProcess.StartInfo.FileName = mailInfo.ToString();
            myProcess.Start(); //執行
            myProcess.Dispose();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("www.google.com.tw"); //一行開啟網站
        }
    }
}



2013年11月14日 星期四

C# 取得電腦上所有serial port


Mac Air本身沒有serial port可以使用,而剛好最近在玩Arduino開發版,

剛好可以用 C# 來跟我的 Arduino 通訊

不過這邊先簡單介紹怎麼取得電腦上所有的 serial port,

順便複習一下combobox 和 listbox


首先這邊先建立Windows Form Application

介面就簡單如圖所示:


Code:
//  Created by vince 
//  Copyright (c) 2013年 vince. All rights reserved.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports; //要使用serial port需要引用它

namespace c_sharp_searchSerialPort
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            string [] myPorts = SerialPort.GetPortNames(); //取得所有port的名字的方法

            comboBox1.DataSource = myPorts;   //直接取得所有port的名字
            listBox1.DataSource = myPorts;

            foreach (string port in myPorts)  //使用迴圈方式取得所有port的名字
            {
                comboBox2.Items.Add(port);    //一個一個增加
                listBox2.Items.Add(port);
            }

        }
    }
}


結果如下,可以發現直接指定所有port給combobox1(左邊),它會有預設的port跑出來,

而用迴圈添加的port給combobox2(右邊),它預設是空白,

直接指定所有port給listbobox1(左邊),它會預設選取 port 的名稱




2013年11月12日 星期二

MAC實用技巧 mac 與 windows 7 雙系統下 螢幕截圖


使用MAC時,少了 print screen 這顆鍵,截圖起來頗不順手的,

組合鍵還滿容易忘記的,這邊就做簡單的小記錄分享:



MAC 系統:

command + shift + 3 : 截取整個螢幕到桌面,雙螢幕就會一次存兩張圖下來

command + shift + 4 : 按下會出現十字靶標,可以自己框選要截圖的範圍




WINDOWS 系統: 

fn + shift + F11  : 截取整個螢幕到剪貼簿,可以貼到小畫家(等同 print screen 鍵)

fn + option + shift + F11  : 截取目前使用視窗到剪貼簿,可以貼到小畫家


2013年11月11日 星期一

Labview Call DLL 呼叫DLL



在使用Labview的時候,常會有些 open souce 的 lib 功能是 Labview 沒有的,

這邊簡單介紹怎麼呼叫 DLL 到 Labview 作使用


這裡就直接用 C/C++ 製作 DLL 教學 做的DLL來當範例

不過要注意,當初DLL是編譯成32位元的,如果 Labview 環境是64位元,

要記得重新編譯DLL喔!



編譯環境

windows 7

Labview 2013 64bit


DLLIMPORT int add(int x,int y) //這邊是這次使用的dll的方法
{
 return x+y;
}

1.增加 Call library VI






















2.連結至 DLL,並選擇使用的方法名稱




3.設定回傳 (return) 的類型























我們 DLL 的 add 方法中回傳類型是 int

因此Labview這邊 Type 要選擇 Numeric ,Data type 要選擇 Integer類的


4.設定傳入參數























在我們的DLL中有兩個參數,int a 和 int b,


跟回傳值的設定一樣 Type 要選擇 Numeric ,Data type 要選擇 Integer類的,

要注意的是,Pass 是選擇傳入的是 值 還是 指標


5.Block Diagram 設置





















執行後就可以看到結果囉XD


C# webcam snapshot and save image to bitmap using aforge



在WINDOWS下做WEBCAM 影像的擷取,比較常見的就是用DirectShow或EmguCV,

最近突然發現有一個還不錯的open souce可以擷取webcam影像,而且大小不到50mb

它就是 aforge,這次就決定用它來示範怎麼做影像擷取與存圖!



編譯環境:

windows 7

visual studio 2012 express

aforge .net Framework-2.2.5


1.到  aforge 官網下載最新版.net Framework 並安裝


2.開啟新專案,選擇 Windows Form Application


3.把DLL加進Project

PROJECT  ->  Add Reference   ->   Browse

到 AForge.NET 的安裝目錄下,AForge.NET\Framework\Release,

將  AForge.Video.DirectShow.dll  和  AForge.Video.dll  加進來





















































4.UI介面設計

這邊我們只要簡單加入picture box 和 3個 button 就可以了,接著可以對物件按右鍵,

選擇 property,更改名稱,比較不容易在寫程式的時候搞混




































5.Code
//  Created by vince on 13/11/10.
//  Copyright (c) 2013年 vince. All rights reserved.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AForge.Video;             //記得加入1
using AForge.Video.DirectShow;  //記得加入2

namespace aforge_webcam_tutorial
{
    public partial class Form1 : Form
    {
        public VideoCaptureDevice cam = null; //global
        public FilterInfoCollection usbCams;  //global
        Bitmap image_from_cam;                //global

        public Form1()
        {
            InitializeComponent();
        }

        void got_frame(object sender, NewFrameEventArgs eventArgs)
        {
            image_from_cam = (Bitmap)eventArgs.Frame.Clone();
            pictureBox1.Image = image_from_cam;
        }

        private void startButton_Click(object sender, EventArgs e)
        {
            usbCams = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            cam = new VideoCaptureDevice(usbCams[0].MonikerString);
            cam.NewFrame += new NewFrameEventHandler(got_frame);//註冊事件(got_frame)
            cam.Start();
        }

        private void stopButton_Click(object sender, EventArgs e)
        {
            cam.Stop();  
        }

        private void saveButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            if (sfd.ShowDialog(this) == DialogResult.Cancel) //按下取消鍵時返回
            {
               return;
            }
            image_from_cam.Save(sfd.FileName);//存圖,副檔名記得給他.bmp
        }
    }
}



執行下去就可以直接跑囉XD

下面是存圖片檔案





















下面這張是拍下來存起來的圖片