I want to save a 24 bit bitmap's RGB data as a file.I firstly import it to resource editor. void CReadView::OnDraw(CDC* pDC) { CReadDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here int i,j; int counter=0; BYTE data[640*480*3]; CBitmap bmp; bmp.LoadBitmap(IDB_BITMAP1); bmp.GetBitmapBits(640*480*3,data); BITMAP bitmap; bmp.GetBitmap(&bitmap); for(i=0;i<bitmap.bmHeight;i++) for(j=0;j<bitmap.bmWidth;j++) { pDC->SetPixel(j,i, RGB(data[counter],data[counter+1],data[counter+2])); counter+=3; } } The result is not correct.:confused:
Chen XuNuo
Posts
-
How to use GetBitmapBits( ) correctly -
How to end a threadThank you very much.The problem has been solved. :rose: :)
-
How to end a threadI am going to be crazy..X| The problem still haven't been solved. UINT BulletGo(LPVOID pParam) { CBullet* bullet=(CBullet*)pParam; while(TRUE) { switch(bullet->GetDirection()) { case UP: bullet->GoUp(); break; case DOWN: bullet->GoDown(); break; case LEFT: bullet->GoLeft(); break; case RIGHT: bullet->GoRight(); break; } if(!bullet->m_bCanGo) break; else bullet->MoveWindow(bullet->GetPosition().x,bullet->GetPosition().y, bullet->GetThisRect().Height(),bullet->GetThisRect().Width()); Sleep(30); } return 0; } BOOL CBullet::GoDown() { if(m_rtParent.bottom==0) GetParent()->GetClientRect(&m_rtParent); if((m_ptPosition.y+m_rtThis.Height())<m_rtParent.bottom) { m_ptPosition.y+=6; m_bCanGo=TRUE; return TRUE; } else { m_bCreated=FALSE; m_bCanGo=FALSE; while( ::WaitForSingleObject(m_pThread->m_hThread,1) == WAIT_TIMEOUT) { Sleep(1); } delete m_pThread; this->DestroyWindow(); return FALSE; } } I destroy the window after ending the thread. Is the judgement: ::WaitForSingleObject(m_pThread->m_hThread,1) == WAIT_TIMEOUT right?If it is right,where is the problem.. :((
-
How to end a threadI have found the error:I can't end the thread after destorying the window,right? ;P
-
How to end a threadI set a breakpoint on "return 0" in the thread function.When the bullet hit the bottom of client rect,the appliction jump to the breakpoint,and I step over,the debugger doesn't pop up error dialog until execute to the line AfxEndThread(nResult) in function UINT APIENTRY _AfxThreadEntry(void* pParam). How do you think the two methods of conrol the enemies and bullets that one use threads and the other use timer in class?Which waste more CPU resource?
-
How to end a threadMmmm...I think if I draw the 'entities' with DC,I think the application would take large CPU resource,so I do it in thread.And I think using thread to control the enemies and the bullets easier. I will try you advice, thank you~
-
How to end a threadThank you for you advice.But it helps nothing to the problem... :sigh:
-
How to end a threadThe application pops up a dialog about error saying that Debug Assertion Failed! Program : D:\Code\TankGame\Debug\TankGame.exe File : wincore.cpp Line : 304 ......
-
How to end a threadI am doing a TankGame program,and I write a CBullet class.I write a thread function to make it move when it is created: UINT BulletGo(LPVOID pParam) { CBullet* bullet=(CBullet*)pParam; while(TRUE) { switch(bullet->m_bCanGo.GetDirection()) { case UP: bullet->GoUp(); break; case DOWN: bullet->GoDown(); break; case LEFT: bullet->GoLeft(); break; case RIGHT: bullet->GoRight(); break; } if(!bullet->m_bCanGo) break; else bullet->MoveWindow(bullet->GetPosition().x, bullet->GetPosition().y, bullet->GetThisRect().Height(), bullet->GetThisRec().Width()); Sleep(30); } return 0; } int CBullet::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CStatic::OnCreate(lpCreateStruct) == -1) return -1; m_bCanGo=TRUE; m_pThread=AfxBeginThread(BulletGo,this); //begin thread return 0; } BOOL CBullet::GoDown() { if((m_ptPosition.y+m_rtThis.Height())>m_rtParent.bottom) { m_ptPosition.y+=2; m_bCanGo=TRUE; return TRUE; } else { this->DestroyWindow(); m_bCreated=FALSE; m_bCanGo=FALSE; return FALSE; } } When the bullet go down and hit the bottom of client rect the program apprear errors.Why...Don't the "break" in the BulletGo() end the thread?
-
BattleTank GameI am doing a program which is BattleTank Game(I believe most people here have played it before:)).I want to ask that how the maps are impremented?How to do with the tile when I shoot bullets to the it? Appreciating your hints~
-
Small questionThe computer I am using havn't been installed MSDN.I want to know that how to use CreatePolygonRgn(CONST POINT*,int,int).Could somebody send the information about the function in MSDN?Thank you. And is the function PtInRgn exist?I want to use the both function to judge if a point in a polygon region. Thanks for your help.
-
About realize the function of selecting discretioal imageBut the area is not a regular one... X|
-
About realize the function of selecting discretioal imageBut the section was selected by the mouse,so the section is not a rect.
-
About realize the function of selecting discretioal imageYes,I want to cut the section I select from the image.
-
About realize the function of selecting discretioal imageIn Windows' Drawing Tool,there is a funtion that is we can select the discretioal part of the image.How can it realize? Have I make a clear expression?;P I appreciate your hint.
-
Where can I get msdn?Hoho..Thanks a lot.What John said amazing me just now.:-D
-
Where can I get msdn?Where can I download msdn?What I downloaded can't be setup at all..:(( Thanks~
-
Cut a bitmap under GDI+I am not so familiar with GDI+,so I don't know that the code your provided can wheather achieve my purpose definitely.What I mean is the region in the bitmap is not necessarily a rect,it is mainly region that I draw with mouse.So it is a irregular region.Could you get it?;P
-
Cut a bitmap under GDI+I want to cut a bitmap and save the selection I cut what is anomalistic under GDI+.Is there any program that I can refer to? Thanks.
-
Is there any technology for curing myopia?Thanks,my English is not good enough,but I will work hard to improve it.:) Do someone know that in China there are many technologies for curing short sight,such as through looking at light in different frequency,tradional Chinese Medicine,but not effective to everybody.So I want to know that is there any new technologies for curing short sight.;)