1,222
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
//截取图片
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;
}