PIXNET Logo登入

阿勇的blog

跳到主文

歡迎光臨阿勇在痞客邦的小天地

部落格全站分類:不設分類

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 12月 31 週五 201016:06
  • 將二個bitmap合成一個bitmap(印出bitmap字串)

之前有寫一個印出bitmap字的程式
現在將這個功能擴充成印出bitmap字串
void combinetext(Bitmap *bitmap, Bitmap *font)
{
int x1 = bitmap->x;
int y1 = bitmap->y;
unsigned int width1 = bitmap->width;
unsigned int height1 = bitmap->height;
unsigned int pitch1 = bitmap->pitch;
unsigned char* data1 = bitmap->data;
int x2 = x1 + width1 + font->x;
int y2 = font->y;
unsigned int width2 = font->width;
unsigned int height2 = font->height;
unsigned int pitch2 = font->pitch;
unsigned char* data2 = font->data;
int x3 = x1;
if(x1 > x2) {
x3 = x2;
}
unsigned int width3 = width1 + font->x + width2;
int y3 = y1;
unsigned int height3 = height1;
if(y1 > y2) {
y3 = y2;
height3 += (y1 - y2);
}
if(y1+height1 < y2+height2) {
height3 += (y2+height2) - (y1+height1);
}
unsigned int pitch3 = width3/8;
if(width3 % 8 != 0) {
pitch3 += 1;
}
int size3 = pitch3 * height3;
unsigned char *data3 = calloc(size3, sizeof(unsigned char));
int shiftX1 = 0;
int shiftY1 = (height3+y3) - (height1+y1);
for(int j=0; j<height1; j++) {
int nj = j+shiftY1;
for(int i=0; i<pitch1; i++) {
int n = shiftX1/8+i+nj*pitch3;
unsigned char data = data1[i+j*pitch1];
int shift = shiftX1%8;
if(shift == 0) {
data3[n] |= data;
} else {
data3[n] |= (0x7f & data>>shift);
data3[n+1] |= data<<(8-shift);
}
}
}
int shiftX2 = x2-x3;
int shiftY2 = (height3+y3) - (height2+y2);
for(int j=0; j<height2; j++) {
int nj = j+shiftY2;
for(int i=0; i<pitch2; i++) {
int n = shiftX2/8+i+nj*pitch3;
unsigned char data = data2[i+j*pitch2];
int shift = shiftX2%8;
if(shift == 0) {
data3[n] |= data;
} else {
data3[n] |= (0x7f & data>>shift);
data3[n+1] |= data<<(8-shift);
}
}
}
free(bitmap->data);
bitmap->x = x3;
bitmap->y = y3;
bitmap->width = width3;
bitmap->height = height3;
bitmap->pitch = pitch3;
bitmap->data = data3;
}
(繼續閱讀...)
文章標籤

阿勇 發表在 痞客邦 留言(0) 人氣(9)

  • 個人分類:bitmap font
▲top
  • 11月 23 週二 201017:04
  • Qt中讀寫jpg和gif

在我的開發電腦中,可以執行(秀出jpg和gif),但是其他電腦不行。
雖然我知道是dll的問題,但是還是找好久。
在執行檔處,建立一個資料夾叫imageformats
然後將qt\plugins\imageformats內要用的dll複製到剛剛建立的資料夾
(繼續閱讀...)
文章標籤

阿勇 發表在 痞客邦 留言(0) 人氣(30)

  • 個人分類:Qt
▲top
  • 11月 11 週四 201015:22
  • 在Qt中列出所有serial port

由於QSettings不能利用含有反斜線的key,來找到值。
所以只好和winapi交互利用。
要注意的是QSettings得到的鍵值是斜線,可是winapi是反斜線
const QStringList WinDongle::getComPort()
{
QStringList comports;
QString keyPath = "HARDWARE\\DEVICEMAP\\SERIALCOMM";
HKEY comsKey;
LPCWSTR winKeyPath = (LPCWSTR)keyPath.constData();
if(RegOpenKey(HKEY_LOCAL_MACHINE, winKeyPath, &comsKey) != ERROR_SUCCESS)
{
error = UNKNOW;
RegCloseKey(comsKey);
return comports;
}
QSettings settings(QString("HKEY_LOCAL_MACHINE\\")+keyPath, QSettings::NativeFormat);
QStringList keys = settings.allKeys();
foreach( const QString & key, keys )
{
QString newKey(key);
newKey.replace(QString("/"), QString("\\"));
LPCWSTR winKey = (LPCWSTR)newKey.constData();
char *szData= new char[101];
DWORD dwType, dwLen=100;
if (RegQueryValueEx(comsKey, winKey,
NULL, &dwType, (unsigned char *)szData, &dwLen) == ERROR_SUCCESS)
{
comports.append( QString::fromUtf16((ushort*)szData) );
}
delete[] szData;
}
RegCloseKey(comsKey);
return comports;
}
(繼續閱讀...)
文章標籤

阿勇 發表在 痞客邦 留言(0) 人氣(56)

  • 個人分類:Qt
▲top
  • 11月 11 週四 201014:20
  • Qt 字串轉換

//Convert a QString To LPCTSTR
LPCTSTR QString_To_LPCTSTR(QString mQTData)
{
return (LPCTSTR)mQTData.utf16();
}
//Convert a QString To LPCSTR
LPCSTR QString_To_LPCSTR(QString mQTData)
{
return (LPCSTR)mQTData.utf16();
}
//Convert a QString To LPTSTR
LPTSTR QString_To_LPTSTR(QString mQTData)
{
return (LPTSTR)mQTData.utf16();
}
//Convert a LPCTSTR To QString
QString LPCTSTR_To_QString(LPCTSTR mWinData)
{
return QString::fromUtf16((ushort*)mWinData);
}
//Convert a LPBYTE To QString
QString LPBYTE_To_QString(LPBYTE mWinData)
{
return QString::fromUtf16((ushort*)mWinData);
}
//Convert a Char[] To QString
QString Char_To_QString(char mWinData[])
{
return QString::fromUtf16((ushort*)mWinData);
}
//Convert a WCHAR* to a QString
QString WCHAR_to_QString(WCHAR* mBuffer)
{
return QString::fromWCharArray(mBuffer);
}
//Convert a TCHAR To QString
QString TChar_To_QString(TCHAR mWinData[])
{
return QString::fromUtf16((ushort*)mWinData);
}
(繼續閱讀...)
文章標籤

阿勇 發表在 痞客邦 留言(0) 人氣(12)

  • 個人分類:Qt
▲top
  • 11月 07 週日 201016:53
  • opengl 視窗置中

其實視窗置中和openGL一點關係都沒有
問題在你的視窗是誰建立的
是用glfw? glut? or ??
至於置中,就還簡單了
視窗的左上角位置 = 0.5 X( 桌面大小 - 視窗大小 )
(繼續閱讀...)
文章標籤

阿勇 發表在 痞客邦 留言(0) 人氣(113)

  • 個人分類:opengl
▲top
  • 11月 07 週日 201016:05
  • CodeLite

每次在用Code::Block都覺得用的很不習慣
尤其最近用久了Qt Creator後
整個寫code的習慣,都被養刁了
但是我又不想用vc
終於讓我找到CodeLite了
(繼續閱讀...)
文章標籤

阿勇 發表在 痞客邦 留言(0) 人氣(23)

  • 個人分類:
▲top
  • 11月 04 週四 201022:14
  • Squirrel

今天灌Code::Block時發現Squirrel的選項。
wiki了一下
It is used extensively by Code::Blocks for scripting and was also used in Final Fantasy Crystal Chronicles: My Life as a King[2] It is also used in Left 4 Dead 2 for scripted events[3].
(繼續閱讀...)
文章標籤

阿勇 發表在 痞客邦 留言(0) 人氣(0)

  • 個人分類:squirrel
▲top
  • 10月 26 週二 201011:57
  • Qt多國語言機制

Qt原本就內建了一套多國語言的機制,可是需要用到Qt Linguist。另外如果要作到動態的話,使用Qt Designer建立的GUI才有提供,要不然只能手動設定(參考)。
所以我自己改寫了一個class Translator。
為了使用方便,我利用了Singleton Pattern,
(繼續閱讀...)
文章標籤

阿勇 發表在 痞客邦 留言(0) 人氣(383)

  • 個人分類:Qt
▲top
  • 10月 19 週二 201008:43
  • license header template (Qt creator)

大部分的程式開頭,都有一段宣告。像是LGPL、GPL或doxygen的註譯等。
Qt creator提供一個license template的功能,當每次增加新的檔案時,都會在文件最前面加上設定好的字串。
Tools > Options... > C++ > License Template > Browse
選擇文件檔(像是gpl.txt)
以下Qt提供的特殊placeholders
(繼續閱讀...)
文章標籤

阿勇 發表在 痞客邦 留言(0) 人氣(50)

  • 個人分類:Qt
▲top
  • 10月 04 週一 201009:47
  • DPInst & nsis

DPInst是驅動程式安裝架構DIFx(Driver Install Frameworks) 所提供的工具之ㄧ。使用方式很簡單。以下說明是以FTDI的driver為例:
  • 將ftdi的driver解壓縮到driver資料夾
  • 到微軟下載wdk
  • 安裝完wdk後,可在WinDDK\redist\DIFx\dpinst中看到二個資料夾MultiLin(提供多國語言),EngMui(提供特定語言,預設為英文,除非提供.mui檔)
  • 在MultiLin提供三個資料夾x86,amd64,ia64
  • 將x86內的dpinst.exe重新命名為x86.exe,將amd64內的dpinst.exe重新命名為x64.exe。將x86.exe和x64.exe複製到driver資料夾(現在執行x86或x64就會幫你安裝FTDI的driver了)
  • 因為我想要安裝程式時,偷偷的替user安裝驅動(也就是不用秀出DPInst的視窗)。
  • 所以在driver的資料夾建立一個dpinst.xml檔。
    <?xml version="1.0"?>
    <dpInst>
    <!--- 不秀出視窗 -->
    <suppressWizard/>
    <quietInstallStrict/>
    <!--- 強迫安裝 -->
    <forceIfDriverIsNotBetter/>
    </dpInst>
  • 在nsis中加入下面程式,即可自動判斷安裝32還是64位元的驅動
    ; Check OS is 32bit or 64bit
    !include "x64.nsh"
    !define FTDI_32_URL "$INSTDIR\driver.exe"
    !define FTDI_64_URL "$INSTDIR\driverd.exe"
    Function installFTDI
    ${If} ${RunningX64}
    StrCpy $2 ${FTDI_64_URL}
    ${Else}
    StrCpy $2 ${FTDI_32_URL}
    ${EndIf}
    ExecWait $2
    FunctionEnd
  • (繼續閱讀...)
    文章標籤

    阿勇 發表在 痞客邦 留言(0) 人氣(674)

    • 個人分類:windows
    ▲top
    «1...67813»

    個人資訊

    阿勇
    暱稱:
    阿勇
    分類:
    不設分類
    好友:
    累積中
    地區:

    熱門文章

    • (0)Cordova速記
    • (0)Cordova run simulation
    • (5)swift速記
    • (1)cordova發布到andriod
    • (4)迷香
    • (11)notification results in “unrecognized selector sent to instance…”
    • (0)分開設定xcode的configureration
    • (10)關於doesNotRecognizeSelector引起的exception crash
    • (1)在SQL中,當二個鍵同時相等時,唯一鍵成立。
    • (56)防止繼承的delegate跟原本的衝突(how to extend a protocol for a delegate in objective C)

    文章分類

    • 替代役的日子 (5)
    • 黑色鈣片 (4)
    • java (3)
    • picasa (1)
    • lua (1)
    • mingw (1)
    • nsis (1)
    • squirrel (1)
    • freetype (1)
    • bitmap font (7)
    • windows (5)
    • c (1)
    • NetBeans (2)
    • uml (1)
    • html5 (1)
    • Wheel Light (4)
    • Qt (26)
    • opengl (6)
    • chrome (2)
    • hg (2)
    • mac (4)
    • apns (1)
    • python (4)
    • php (2)
    • SQL (4)
    • iOS (3)
    • xcode (4)
    • Objective-C (8)
    • phonegap (1)
    • swift (1)
    • cordova (2)
    • 未分類文章 (1)

    最新文章

    • Cordova速記
    • Cordova run simulation
    • swift速記
    • cordova發布到andriod
    • 迷香
    • notification results in “unrecognized selector sent to instance…”
    • 分開設定xcode的configureration
    • 關於doesNotRecognizeSelector引起的exception crash
    • 在SQL中,當二個鍵同時相等時,唯一鍵成立。
    • 防止繼承的delegate跟原本的衝突(how to extend a protocol for a delegate in objective C)

    動態訂閱

    文章精選

    文章搜尋

    誰來我家

    參觀人氣

    • 本日人氣:
    • 累積人氣: