int _tmain(int argc, _TCHAR* argv[]) { //initiation _TCHAR* filename=_T("regenerate_original_picture.txt"); unsigned char data[256]; int packetlen=256; static unsigned short *ImageData[256][256][128]; //What following below is define of the actual argument in the function of "Creat" HBITMAP hBitmap; BITMAPINFOHEADER *bmih=NULL ; unsigned short * pBits =(unsigned short*)memset( pBits, 0x24, 256*256*2 );//pBits是内容// 一旦create了,就可以直接操控PB IT s这个指针, //*( PB IT s + xxxx ) = 255; // 对某个像素赋值. //填装数据 FILE *pfile=_tfopen(filename,_T("rb"));//rb要用_T转换一下 for (int i = 0; i < 256; i++) for (int j = 0; j < 256; j++) { fread(data, 1, packetlen, pfile); //dosomething //pBits,data,memcpy; memcpy(ImageData[i][j],data,256); } int x=1;//x是标示波段的 for (int v = 0; v < 256; v++) for (int c = 0; c < 256; c++) { memcpy( pBits,ImageData[v][c][x],1); } //CreateDIBitmap创建的是设备相关位图句柄 - HBITMAP. //CreateDIBSection创建的是设备无关位图句柄 - HBITMAP. //初始化BITMAPINFOHEADER结构的栏位 bmih->biSize = sizeof (BITMAPINFOHEADER) ; bmih->biWidth = 256 ; bmih->biHeight = 256 ; bmih->biPlanes = 1 ; bmih->biBitCount = 16 ; bmih->biCompression = BI_RGB ; bmih->biSizeImage = 0 ; bmih->biXPelsPerMeter = 0 ; bmih->biYPelsPerMeter = 0 ; bmih->biClrUsed = 0 ; bmih->biClrImportant = 0 ; //在基本准备後,我们呼叫该函式: hBitmap = CreateDIBSection (NULL, (BITMAPINFO *) &bmih, 0, (void**)&pBits, NULL, 0) ; SaveBmp(hBitmap,"bitmap"); return 0; } ——————————– |
|
50分 |
先malloc,再memset
|
50分 |
unsigned short * pBits =(unsigned short*)memset( pBits, 0x24, 256*256*2 );//pBits是内容// 一旦create了,就可以直接操控PB IT s这个指针, //*( PB IT s + xxxx ) = 255; // 对某个像素赋值. pBits都没有分配内存空间,初始化有何用?至于要分配都少空间,你应该清楚 |