中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

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

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

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

          3.4 圖像數(shù)據(jù)的讀取
          圖像數(shù)據(jù)的讀取過程可以分為以下三歩:
         ?。?) 獲得picture字段中圖像文件的實(shí)際長(zhǎng)度。
         ?。?) 調(diào)用getchunk函數(shù),返回變體對(duì)象。
         ?。?) 獲得數(shù)組數(shù)據(jù)指針,把數(shù)據(jù)寫入打開的文件中。
          具體實(shí)現(xiàn)代碼如下:
          long nsize=m_precordset-》getfields()-》getitem
         ?。?ldquo;picture ”)-》actualsize;//獲得圖像文件的長(zhǎng)度
          if(nsize1 》 0)
          { varblob=m_precordset-》getfields()-》getitem
          (“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ù)庫的一個(gè)組成部分。mfc的odbc類對(duì)較復(fù)雜的odbc
          api進(jìn)行了封裝,提供了簡(jiǎn)化的調(diào)用接口,方便了數(shù)據(jù)庫應(yīng)用程序的開發(fā)[2]。
          mfc
          odbc類主要包括cdatabase類、crecordset類和cfieldexchange類。cdatabase類的主要功能是建立與數(shù)據(jù)庫的連接;crecordset類針對(duì)數(shù)據(jù)源中記錄集,它負(fù)責(zé)對(duì)記錄的操作;cfieldexchange類負(fù)責(zé)crecordset與數(shù)據(jù)源的數(shù)據(jù)交換。
          4.2 配置odbc數(shù)據(jù)源
          用odbc管理器定義了一個(gè)數(shù)據(jù)源,管理器根據(jù)數(shù)據(jù)源所在的位置,數(shù)據(jù)庫類型及odbc驅(qū)動(dòng)器等信息,建立起odbc與具體數(shù)據(jù)庫之間的聯(lián)系。在windows
          xp的系統(tǒng)中,配置odbc數(shù)據(jù)源的過程為:控制面板—性能和維護(hù)—管理工具—數(shù)據(jù)源(odbc)。
          4.3 odbc連接數(shù)據(jù)庫
          創(chuàng)建cdatabase對(duì)象并連接數(shù)據(jù)庫:
          cdatabase m_db;//定義的數(shù)據(jù)庫全局變量
          cbitmap bitmap;
          //定義的圖像類全局變量,存儲(chǔ)圖像數(shù)據(jù)
          m_db.open(null, false, false, “odbc;driver={microsoft access
          driver (*.mdb)};
          dbq= picture.mdb”);
          4.4 圖像數(shù)據(jù)的存儲(chǔ)
          首先做一些變量的定義:
          m_ picture為picture字段對(duì)應(yīng)的長(zhǎng)二進(jìn)制成員變量;
          m_hdata用來存放picture字段的數(shù)據(jù);
          m_dwdatalength為picture字段的實(shí)際長(zhǎng)度。
          圖像數(shù)據(jù)的存儲(chǔ)過程可以分為以下三步:
         ?。?) 打開圖像數(shù)據(jù),獲得數(shù)據(jù)長(zhǎng)度;
         ?。?) 申請(qǐng)緩沖區(qū),把文件讀入此緩沖區(qū);
         ?。?) 通過調(diào)用update()刷新數(shù)據(jù)庫記錄。
          具體實(shí)現(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);
          //修改標(biāo)志數(shù)據(jù)庫
          dbimages.setfieldnull(&dbim -ages.m_ picture,false);
          dbimages.update();
          //刷新數(shù)據(jù)庫的記錄
          globalunlock(hglobal);
          dbimages.close();
          4.5 圖像數(shù)據(jù)的讀取
          圖像數(shù)據(jù)的讀取過程可以分為以下三步:
         ?。?) 定義臨時(shí)文件。
         ?。?) 向臨時(shí)文件中存放從數(shù)據(jù)庫中讀取到的圖像數(shù)據(jù)。
         ?。?) 取出圖像數(shù)據(jù),獲得圖像數(shù)據(jù)的寬度和高度。
          具體實(shí)現(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中存儲(chǔ)和讀取圖像數(shù)據(jù)的方法以及部分程序代碼。這兩種訪問方法在vc++
          7.0的環(huán)境下進(jìn)行調(diào)試結(jié)果顯示,使用ado來訪問數(shù)據(jù)庫中的圖像數(shù)據(jù)更加的方便,更加的高效,使用mfc
          odbc方法訪問大對(duì)象數(shù)據(jù)的速度相對(duì)較慢。在開發(fā)擴(kuò)展時(shí)會(huì)發(fā)現(xiàn)mfc
          odbc不能用于其他的非關(guān)系數(shù)據(jù)庫,使用的范圍相對(duì)較窄。這兩種方法還可以應(yīng)用于其他二進(jìn)制大對(duì)象數(shù)據(jù)的訪問。

        上一頁 1 2 下一頁

        評(píng)論


        相關(guān)推薦

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

        關(guān)閉