1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| CDC *pDC = m_piclevel.GetDC();
//le bitmap issus du fichier ne provoque pas de plantage
//HBITMAP hBitmap = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
// "e:\\test\\image1.bmp", IMAGE_BITMAP, 0, 0,
// LOADFROMFILE |LR_CREATEDIBSECTION );
//le bitmap ici plante même si je teste le format
HBITMAP hBitmap = (HBITMAP)::CreateBitmap(360,400,32,3,NULL);
//l'appel de la classe
bool m_test = m_pCTools->SetLineOfPixel(hBitmap,pDC,m_data);
//la classe
bool CToolsBmp::SetLineOfPixel(HBITMAP hSource,CDC *pDC,int data[])
{
CDC memdcX;
DWORD dwValue;
memdcX.CreateCompatibleDC(pDC);//map these CDC objects to your window DC
BITMAP bmpX;
CBitmap mybmp;
//mybmp.LoadBitmap(IDB_BITMAP2) if in resource
mybmp.Attach(hSource);
//Get bitmap dimensions into BITMAP structure : bmType bmWidth bmWidthBytes
//Total of bytes by pixels",bmpX.bmWidthBytes/bmpX.bmWidth)
mybmp.GetBitmap(&bmpX);
//allocate memory for image byte buffer
BYTE* bmpBuffer=(BYTE*)GlobalAlloc(GPTR,bmpX.bmWidthBytes * bmpX.bmHeight);
//Get the bitmap bits int a structure
dwValue=mybmp.GetBitmapBits(bmpX.bmWidthBytes*bmpX.bmHeight,bmpBuffer);
for(int row=0;row<bmpX.bmHeight-1;row++)
{
for(int col=0;col<bmpX.bmWidth;col++)
{
int ptopixel=row * bmpX.bmWidthBytes + col*3;
bmpBuffer[ptopixel]=(BYTE)data[col]; // Bleue
bmpBuffer[ptopixel+1]=0; // Green
bmpBuffer[ptopixel+2]=0; // Rood
}
}
//generate image from buffer
dwValue = mybmp.SetBitmapBits(bmpX.bmWidthBytes*bmpX.bmHeight,bmpBuffer);
mybmp.GetBitmap(&bmpX);
memdcX.SelectObject(mybmp);//select mybmp
//Draw the bitmap image
pDC->BitBlt(0,0,bmpX.bmWidthBytes,bmpX.bmHeight ,&memdcX,0,0,SRCCOPY);
GlobalFree((HGLOBAL)bmpBuffer);//Free memory
//TRACE("CToolsBmp::SetLineOfPixel pass");
return true;
} |
Partager