1、将double类型的数据存储于image类型的变量中:
(1)、 char *CManualForecastResultBll::DoubleArray2Binary(std::vector<double> &doubleArray){ int len = doubleArray.size(); char *bin = new char[len * sizeof(double)]; unsigned __int64 *p = (unsigned __int64*)bin; for (int i = 0; i < len; i++) { *p = DOUBLE2UINT64(doubleArray.at(i)); p++; } return bin;}unsigned __int64 CManualForecastResultBll::DOUBLE2UINT64(double v){ unsigned __int64 *pu64n = NULL; pu64n = reinterpret_cast<unsigned __int64*>(&v); return *pu64n;}
(2)、
VARIANT varBLOB; SAFEARRAY *psa; SAFEARRAYBOUND rgsabound[1]; rgsabound[0].lLbound = 0; rgsabound[0].cElements = (ULONG)(pData->qLen); psa = SafeArrayCreate(VT_UI1, 1, rgsabound); byte * pQt = pData->QTLINE; //自己的数据byte类型 for (long i = 0; i < pData->qLen; i++) SafeArrayPutElement (psa, &i, pQt++); varBLOB.vt = VT_ARRAY | VT_UI1; varBLOB.parray = psa; pRecordset->GetFields()->GetItem(SimulateResultDataFeilds[i])->AppendChunk(varBLOB);
2、根据已知image类型中存储的数据类型(例如:double、float等)取数据:
case VT_ARRAY | VT_UI1:
Binary2DoubleArray(vtFld); break;
//void DBRecordset::Binary2DoubleArray(_variant_t vtFld){ int len = vtFld.parray->rgsabound->cElements / sizeof(double); double *pdata = new double[len]; /*int len = vtFld.parray->rgsabound->cElements / sizeof(float); float *pdata = new float[len];*/ SafeArrayAccessData(vtFld.parray, (void**)&pdata); /*unsigned __int64 *pu64n = new unsigned __int64[len]; SafeArrayAccessData(vtFld.parray, (void**)&pu64n);*/ ofstream writetofile("image.txt"); for (int i = 0; i < len; i++) { if (i % 30 == 0 && i != 0) { writetofile<<endl; } writetofile<<pdata[i]<<"\t"; //writetofile<<*(reinterpret_cast<double*>(&pu64n[i]))<<"\t"; writetofile.flush(); } writetofile<<endl; writetofile.close(); SafeArrayUnaccessData(vtFld.parray);}
转载于:https://www.cnblogs.com/shenchao/p/3270515.html
相关资源:图片存储到SQLServer数据库中