在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 關(guān)于VC++的圖像數(shù)據(jù)訪問的研究

            關(guān)于VC++的圖像數(shù)據(jù)訪問的研究

            作者: 時間:2016-12-16 來源:網(wǎng)絡(luò) 收藏

              3.4 圖像數(shù)據(jù)的讀取
              圖像數(shù)據(jù)的讀取過程可以分為以下三歩:
             ?。?) 獲得picture字段中圖像文件的實際長度。
             ?。?) 調(diào)用getchunk函數(shù),返回變體對象。
             ?。?) 獲得數(shù)組數(shù)據(jù)指針,把數(shù)據(jù)寫入打開的文件中。
              具體實現(xiàn)代碼如下:
              long nsize=m_precordset-》getfields()-》getitem
              (“picture ”)-》actualsize;//獲得圖像文件的長度
              if(nsize1 》 0)
              { varblob=m_precordset-》getfields()-》getitem
             ?。?ldquo;picture ”)-》getchunk(nsize);
              //獲得varblob的值
              if(varblob.vt == (vt_array | vt_ui1))
              {char *pbuf = null;
              lpvoid pbuf2 = null;
              safearrayaccessdata(varblob.parray,
             ?。╲oid **)&pbuf);//獲得數(shù)組數(shù)據(jù)指針
              hglobal=globalalloc(gmem_moveable,
              nsize);
              pbuf2 = globallock(hglobal);
              memcpy(pbuf2,pbuf,nsize1);
              //復(fù)制數(shù)據(jù)到緩沖區(qū)
             ?。海篻lobalunlock(hglobal);
              safearrayunaccessdata (varblob.parray);
              hr=::createstreamonhglobal( hglobal,
              true, &pstream );
              hr=::oleloadpicture( pstream, nsize1, true, iid_ipicture, (
              lpvoid * )&ppicture );
              ppicture-》render(pdc-》m_hdc,0,0,rect.width(),rect.height(),
              0,nheight,nwidth,-nheight,null);
              //將圖像數(shù)據(jù)顯示在用戶界面
              }
              }
            4 應(yīng)用mfc odbc訪問圖像數(shù)據(jù)
              4.1 mfc odbc的介紹
              odbc(open database connect
              -ivity)是微軟公司開放服務(wù)結(jié)構(gòu)中有關(guān)數(shù)據(jù)庫的一個組成部分。mfc的odbc類對較復(fù)雜的odbc
              api進行了封裝,提供了簡化的調(diào)用接口,方便了數(shù)據(jù)庫應(yīng)用程序的開發(fā)[2]。
              mfc
              odbc類主要包括cdatabase類、crecordset類和cfieldexchange類。cdatabase類的主要功能是建立與數(shù)據(jù)庫的連接;crecordset類針對數(shù)據(jù)源中記錄集,它負責對記錄的操作;cfieldexchange類負責crecordset與數(shù)據(jù)源的數(shù)據(jù)交換。
              4.2 配置odbc數(shù)據(jù)源
              用odbc管理器定義了一個數(shù)據(jù)源,管理器根據(jù)數(shù)據(jù)源所在的位置,數(shù)據(jù)庫類型及odbc驅(qū)動器等信息,建立起odbc與具體數(shù)據(jù)庫之間的聯(lián)系。在windows
              xp的系統(tǒng)中,配置odbc數(shù)據(jù)源的過程為:控制面板—性能和維護—管理工具—數(shù)據(jù)源(odbc)。
              4.3 odbc連接數(shù)據(jù)庫
              創(chuàng)建cdatabase對象并連接數(shù)據(jù)庫:
              cdatabase m_db;//定義的數(shù)據(jù)庫全局變量
              cbitmap bitmap;
              //定義的圖像類全局變量,存儲圖像數(shù)據(jù)
              m_db.open(null, false, false, “odbc;driver={microsoft access
              driver (*.mdb)};
              dbq= picture.mdb”);
              4.4 圖像數(shù)據(jù)的存儲
              首先做一些變量的定義:
              m_ picture為picture字段對應(yīng)的長二進制成員變量;
              m_hdata用來存放picture字段的數(shù)據(jù);
              m_dwdatalength為picture字段的實際長度。
              圖像數(shù)據(jù)的存儲過程可以分為以下三步:
             ?。?) 打開圖像數(shù)據(jù),獲得數(shù)據(jù)長度;
             ?。?) 申請緩沖區(qū),把文件讀入此緩沖區(qū);
             ?。?) 通過調(diào)用update()刷新數(shù)據(jù)庫記錄。
              具體實現(xiàn)代碼如下:
              static char based_code szfilter[]=“bitmap files
             ?。?.bmp)|*.bmp||”;
              cdbimages dbimages(m_db);
              cfiledialog fd(true,null,null,0,szfilter,this);
              if (idok != fd.domodal()) return;
              dbimages.open();
              dbimages.addnew();
              cfile fileimage;
              cfilestatus filestatus;
              fileimage.open(fd.getpathname(), cfile::moderead);
              fileimage.getstatus(filestatus);
              //獲得打開圖像文件的狀態(tài)
              dbimages.m_ picture.m_dwdatal -ength =
              filestatus.m_size;
              hglobal hglobal=globalalloc(gptr,filestatus.m_size);
              //分配內(nèi)存
              dbimages.m_ picture.m_hdata = globallock(hglobal);
              //鎖定內(nèi)存
              fileimage.readhuge(dbimages.m_
              picture.m_hdata,filestatus.m_size);
              //向緩沖區(qū)讀取圖像數(shù)據(jù)
              dbimages.setfielddirty(&dbimages.m_ picture);
              //修改標志數(shù)據(jù)庫
              dbimages.setfieldnull(&dbim -ages.m_ picture,false);
              dbimages.update();
              //刷新數(shù)據(jù)庫的記錄
              globalunlock(hglobal);
              dbimages.close();
              4.5 圖像數(shù)據(jù)的讀取
              圖像數(shù)據(jù)的讀取過程可以分為以下三步:
             ?。?) 定義臨時文件。
              (2) 向臨時文件中存放從數(shù)據(jù)庫中讀取到的圖像數(shù)據(jù)。
             ?。?) 取出圖像數(shù)據(jù),獲得圖像數(shù)據(jù)的寬度和高度。
              具體實現(xiàn)代碼如下:
              cdbimages dbimages(m_db);
              cstring strfilename ;
              i=1;
              strfilename.format(“%s”,i)
              dbimages.open();
              if (dbimages.iseof())
              afxmessagebox(“unable to get image from picture”);
              else{char tmppath[_max_path 1];
              gettemppath(_max_path,tmppath);
              strfilename.insert(0,tmppath);
              cfile outfile(strfilename,cfile::modecreate
              |cfile::modewrite);
              lpstr buffer=(lpstr)globallock(dbimages.m_ picture.m_hdata);
              outfile.writehuge(buffer,dbima -ges.m_
              picture.m_dwdatalength);
              globalunlock(dbimages.m_ picture.m_hdata);
              outfile.close();
              hbitmap hbm=(hbitmap)::loa -dimage(null,
              strfilename,image_bitmap, 0, 0, lr_loadfromfile);
              if (bitmap.attach(hbm)) { bitmap bm;
              bitmap.getbitmap(&bm); //獲得圖像的尺寸
              bitmap.setbitmapdimension(bm.bmwidth,bm.bmheight);//獲得圖像的寬度和高度
              }
            5 結(jié)束語
              筆者介紹了使用ado技術(shù)和mfc
              odbc在access中存儲和讀取圖像數(shù)據(jù)的方法以及部分程序代碼。這兩種訪問方法在vc++
              7.0的環(huán)境下進行調(diào)試結(jié)果顯示,使用ado來訪問數(shù)據(jù)庫中的圖像數(shù)據(jù)更加的方便,更加的高效,使用mfc
              odbc方法訪問大對象數(shù)據(jù)的速度相對較慢。在開發(fā)擴展時會發(fā)現(xiàn)mfc
              odbc不能用于其他的非關(guān)系數(shù)據(jù)庫,使用的范圍相對較窄。這兩種方法還可以應(yīng)用于其他二進制大對象數(shù)據(jù)的訪問。

            上一頁 1 2 下一頁

            評論


            相關(guān)推薦

            技術(shù)專區(qū)

            關(guān)閉