<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > 關(guān)于VC++的圖像數據訪(fǎng)問(wèn)的研究

關(guān)于VC++的圖像數據訪(fǎng)問(wèn)的研究

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

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

上一頁(yè) 1 2 下一頁(yè)

評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>