This topic is now archived and is closed to further replies.


Displaying byte array

Recommended Posts

hi,all: I got a 2D byte array with every element represent a RGB color value(0-255),the two dimension stand for row and col,now i want to display them into a window.I''ve been using the win32 function SetPixel and each time fetching 3 byte from the array to form a RGB value.It works but the speed is too slow,since the byte array data are static,it''s no reason to display them every time in the OnDraw callback function(I use VC). So i think of the bitmap.Here is the code i use: //in initial setup function //pByte is the 2D byte array,we have construct it with RGB order ... m_pBitmap = new CBitmap; m_pdcMemory = new CDC; m_pBitmap->CreateBitmap(cols,rows,24,24,NULL); m_pBitmap->SetBitmapBits(3*cols*rows,pByte); CClientDC dc(this); OnPrepareDC(&dc); m_pdcMemory->CreateCompatibleDC(&dc); m_pdcMemory->SelectObject(m_pBitmap); //in OnDraw callback function pDC->BitBlt(0,0,cols,rows,m_pdcMemory,0,0,SRCCOPY); That is it.But nothing displays in the window.Where does things get wrong?(If i use LoadBitmap member function of CBitmap in the setup function then everything is ok) I think maybe bitmap is not the best way of deeling with this situation,but it''s far more better then SetPixel. Anybody can help me find the mistake or just give me another way to do this thing? thinks a lot!

Share this post

Link to post
Share on other sites