截圖寫出資料
我用c++ 寫出位圖 大小為1*1 像素 顯示正常 24真色彩 輸出
但是 我用 16進制查看檔案的時候 資料不對呀
應該是54位元組后+ 4位元組的資料 (3位元組顏色和1個位元組的對齊)
16進制查看有 7位元組 ???
有時候是正確的 4位元組

uj5u.com熱心網友回復:
截取影像的關鍵代碼
//截取圖片
bool pixelex::captrue(long x,long y,long w,long h,char* filepath)
{
//路徑處理
// setpath(filepath);
filepath="c:/123.txt";
long pixelLength;
byte * pixelDate=NULL;
FILE * wfile=NULL;
//打開檔案
wfile = fopen( filepath, "wb" );
fwrite( head, 54, 1, wfile );
//更改grab.bmp的頭檔案中的高度和寬度
fseek( wfile, 0x0012, SEEK_SET );
fwrite( &w, sizeof(w), 1, wfile );
fwrite( &h, sizeof(h), 1, wfile );
//為像素分配記憶體
pixelLength = w * 3;
if ( pixelLength % 4 != 0 )
{
pixelLength += 4 - pixelLength%4;
}
pixelLength *= h;
pixelDate = (byte *)malloc( pixelLength );
if ( pixelDate == 0 )
{
AfxMessageBox(L"記憶體分配失敗");
}
if(ishaverc)
{
glReadPixels(x, y, w, h, GL_BGR_EXT, GL_UNSIGNED_BYTE, pixelDate );
glFlush();
// AfxMessageBox(L"有");
}else
{
bool ok=apihook::getdx()->readpix(x,y,w,h,pixelDate);
if(!ok)
{
fclose( wfile );
free( pixelDate );
return false;
}
// AfxMessageBox(L"沒有");
}
CString o;
o.Format(L"%d",pixelLength);
AfxMessageBox(o);
//這里輸出一直是4沒有錯
fseek( wfile, 0, SEEK_END );
fwrite( pixelDate, pixelLength, 1, wfile );
fclose( wfile );
free( pixelDate );
return true;
}
uj5u.com熱心網友回復:
關鍵一點 不是bmp 應該是4位元組對齊的 但是7個位元組 顯示確是正常的黃色。。。。。。轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/81003.html
上一篇:求代碼片上網路映射演算法
下一篇:c++
