将一个一维的Raw Data转为灰度的BITmap |
尚未結案
|
coolsoft
一般會員 發表:19 回覆:10 積分:5 註冊:2003-07-15 發送簡訊給我 |
有一个BYTE 类型的内存如
BYTE *pBuffer=(BYTE *)malloc(300*200);
//对pBuffer进行设置
//如何把这个pBuffer存储成Bitmap(24bit)?
//做如下尝试
//
BYTE *pImageBuffer=(BYTE *)malloc(300*200*3);
for (int y=0;y<200;y )
for (int x=0;x<300;x )
{
pImageBuffer[y*3*300 3*x]=pBuffer[y*300 x];
pImageBuffer[y*3*300 3*x 1]=pBuffer[y*300 x];
pImageBuffer[y*3*300 3*x 2]=pBuffer[y*300 x]; }
//保存pImageBuffer
long lBufferSize=300*200*3;
HANDLE hf = CreateFile(
"d:\\a.bmp", GENERIC_WRITE, 0, NULL,//m_szSnappedName
CREATE_ALWAYS, NULL, NULL );
if( hf == INVALID_HANDLE_VALUE )
return 0;
// write out the file header
//
BITMAPFILEHEADER bfh;
memset( &bfh, 0, sizeof( bfh ) );
bfh.bfType = 'MB';
bfh.bfSize = sizeof( bfh ) lBufferSize sizeof( BITMAPINFOHEADER );
bfh.bfOffBits = sizeof( BITMAPINFOHEADER ) sizeof( BITMAPFILEHEADER );
DWORD dwWritten = 0;
WriteFile( hf, &bfh, sizeof( bfh ), &dwWritten, NULL );
// and the bitmap format
//
BITMAPINFOHEADER bih;
memset( &bih, 0, sizeof( bih ) );
bih.biSize = sizeof( bih );
bih.biWidth = 300;
bih.biHeight = 200;
bih.biPlanes = 1;
bih.biBitCount = 24;
dwWritten = 0;
WriteFile( hf, &bih, sizeof( bih ), &dwWritten, NULL );
// and the bits themselves
//
dwWritten = 0;
WriteFile( hf, pImageBuffer, lBufferSize, &dwWritten, NULL );
CloseHandle( hf );
free(pImageBuffer);
free(pBuffer); //结果存储的图片显示出来,竖线变成了倾斜的了,哎见下图.上面是正常的,下图是变异的.
请各位帮忙审一审!!!谢谢!
|
coolsoft
一般會員 發表:19 回覆:10 積分:5 註冊:2003-07-15 發送簡訊給我 |
|
justdo
高階會員 發表:2 回覆:359 積分:222 註冊:2004-08-17 發送簡訊給我 |
參考這一篇http://delphi.ktop.com.tw/topic.php?TOPIC_ID=74571
看是不是資料對齊的問題
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |