|
If you use CreateDIBSection[^] to create a DIB, you get a pointer at the pixel data in memory and reading/writing the memory directly is much much much much faster than SetPixel/GetPixel.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
|
|
|
|
|
Just for my curiosity, I really don't want to be offensive: on a previous post (getting pixel color values by GetDiBit function[^]) you said that you are experienced in C# programming, but you have a very limited knowledge on C/C++.
Then, why are you searching for a solution on a C/C++/MFC forum? As I already answered, you can use the GetDIBits() and SetDIBits() from C# using the P-Invoke; is not that more confortable for you?
|
|
|
|
|
actually i got the solution of my problem in c#. and that worked. actually at first i was thinking that there is no way in c# to access pixels with high speed so therefore i thought to work in c++.
therefore i had posted my question here in C++ forum. but now i have the solution in c#.
thanks
|
|
|
|
|
thank you sauro viti i got the solution..
|
|
|
|
|
that's great!
|
|
|
|
|
hi
i want to get the pixel RGB values and then want to change them by simple plus or minus and then set again. i don't want to use getpixel and setpixel because they are too slow. i want to use GetDiBit and SetDiBit functions. but i don't know how to use..please someone help me to write a very simple code that uses GetDiBit and SetDiBit to access a bitmap pixel RGB values and change then Set,including with headerfiles..the code should be as to just copy and paste and run so that i will understand properly.
thanks
|
|
|
|
|
Don't ask for code! The right way starts from here:
|
|
|
|
|
let me tell you sir my actual problem. I am doing project of "Face detection" in live video in c#. and i know c#. but the problem is that i can't use GetPixel and SetPixel methods because they are too slow. then i googled and i came to know about GetDiBit and SetDiBit that they are very fast, but unfortunately i don't understand advance c++, i can just print hello hi etc.then i tried a lot to understand these GetDiBit functions but i don't understand at any way. i searched the code as well on google but didn't get.
so at last i thought that if i get proper code so i can use them and can play with RGB values. i will make DLLs of codes and i will call them in c#.
so this seems to me as solution.
plz help me
|
|
|
|
|
Here[^] you find a basic sample about using GetDIBits .
Pheraps you prefer to write your code using C#; you can starts from these links:
|
|
|
|
|
|
Hello Friends
I am Loading a bitmap using HBITMAP and then attaching it to CBitmap.
HBITMAP hBmp = (HBITMAP)::LoadImage(NULL,strFile, IMAGE_BITMAP,0,0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bmp;
bmp.Attach(hBmp);
Then I am Creating CompatibleDC using CClientDC.then using Bitblt to show image in tht Window.
CClientDC dcbkImage(pDoc->m_pWndTissu->hbkimg);
CDC bmDC;
bmDC.CreateCompatibleDC(&dcbkImage);
CBitmap *pOldbmp = bmDC.SelectObject(&bmp);
BITMAP bi;
bmp.GetBitmap(&bi);
dcbkImage.BitBlt(0,0,bi.bmWidth,bi.bmHeight,&bmDC,0,0,SRCCOPY);
bmDC.SelectObject(pOldbmp);
After that I hv another functionality in my application is that I can create stripes vertically or Horizontally on tht window which contains my Image and that coloured stripes are getting draw pixel by pixel.
Now,the prob is tht stripes are getting draw but coming behind the image.
How can I make those stripes above the iamge?
Thanks In Advance.
Regards
Yogesh
|
|
|
|
|
Try this.
CDC *dc=NULL;
dc->Attach()
CDC bmDC;
bmDC.CreateCompatibleDC(dc);
CBitmap *pOldbmp = bmDC.SelectObject(&bmp);
BITMAP bi;
bmp.GetBitmap(&bi);
dcbkImage.BitBlt(0,0,bi.bmWidth,bi.bmHeight,&bmDC,0,0,SRCCOPY);
bmDC.SelectObject(pOldbmp);
|
|
|
|
|
GAJERA wrote: CDC *dc=NULL;
dc->Attach()
There are two big errors in this code:
- the
CDC::Attach() method wants an HDC as parameter, then this code doesn't compile. To which HDC do you want to attach? - you have initialized
dc to NULL and then you use that pointer to call one of its non-static members: this will give you a memory protection fault.
|
|
|
|
|
Get HDC from pDoc->m_pWndTissu->hbkimg.
|
|
|
|
|
Thanks Guys For Your reply.
I got the solution but in another way.I changed the last parameter of Bitblt to SRCAND which merges two colors.
Now,the prob is when I draw stripes OnPaint function is calling which hides my background image.So what can i do to keep my image there as background permanently?
Thanks In Advance.
Regards
Yogesh
|
|
|
|
|
OnPaint method always redraw window.
Does you load background image in OnPaint Method?
check with InvalidateRect API.
|
|
|
|
|
Yes,Background iMage is loading on OnPaint.
If I Load once on some other button then also it is coming but as i do some other Functionality like zoom,Draw stripes then tht Image gets hide bcoz on these functionalities OnPaint is calling.
Is there any other solution?
Thanks & Regards
Yogesh
|
|
|
|
|
show me your OnPaint code
|
|
|
|
|
Hello,
do suppose I create a thread with the following:
CWinThread* m_pThread = AfxBeginThread ((AFX_THREADPROC) ThreadFunc, this,
THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
and that I embed this in a class. Say in the methos "Start".
Then...
1. If the class is instantiated onto the stack no problem whatsoever,
otherwise
2. if the class is instantiated onto the heap I get memory leaks after
destruction of the object.
Question is the following: do I should delete explicitely the "m_pThread"
object returned by AfxBeginThread after the thread ends ?
Where do come from the thread related memory leaks I met ?
Anyone has already encountered / solved this problem ?
Cheers
Federico
|
|
|
|
|
If you have to explicitly delete the returned m_pThread depends on the m_bAutoDelete member of that CWinThread object: if the variable is set to TRUE , the object automatically deletes itself when the thread execution terminates (I'm not very sure, but I remember that this is the default).
|
|
|
|
|
I was thinking along the same lines, the fact is I got
memory leaks when and only when I instantiate objects
on the heap that start threads, the class interface
is the following:
#ifndef CONSUMER_H
#define CONSUMER_H
#include <afx.h>
#include <afxwin.h>
#include <set>
using namespace std;
typedef set<CWnd*> ObserverListConsumerDef;
#include "ThreadMessages.h"
class CConsumer
{
public:
CConsumer(void);
virtual ~CConsumer(void);
public:
bool Start(void);
bool Stop (void) { m_bStop = true; return true; }
bool Abort(void);
bool WaitForThread(DWORD dwWait);
bool IsRunning() { return m_bIsRunning; };
bool IsSuccess() { return m_bSuccess; };
virtual bool Execute() = 0;
protected:
static UINT ThreadFunc(LPVOID pVoid)
{
return( ((CConsumer*) pVoid)->LocalThreadFunc() );
}
UINT LocalThreadFunc(void);
bool m_bIsRunning;
bool m_bSuccess;
bool m_bStop;
CWinThread* m_pThread;
HANDLE m_hThread;
public:
void SetObserver(CWnd *pWnd);
void DelObserver(CWnd *pWnd);
protected:
ObserverListConsumerDef m_ObserverList;
void SendMessageToObs(UINT nMsg, WPARAM wP, LPARAM lP);
};
#endif // ! defined (CONSUMER_H)
|
|
|
|
|
When the thread ends, the CWinThread could be automatically deleted (depending on its m_bAutoDelete member), but the object of CConsumer class that you have dinamically allocated, should be deleted; you can explicitly test for the thread termination and delete the object, or make it auto-delete.
- explicitly delete the object:
CConsumer pConsumer = new CConsumer;
...
if (!pConsumer->IsRunning())
delete pConsumer; - add auto-delete feature to
CConsumer :
class CConsumer
{
...
protected:
static UINT ThreadFunc(LPVOID pVoid)
{
CConsumer* pConsumer = (CConsumer*)pVoid;
UINT retVal = pConsumer->LocalThreadFunc();
if (pConsumer->m_bAutoDelete)
delete pConsumer;
return retVal;
}
BOOL m_bAutoDelete;
...
};
|
|
|
|
|
Thanks, but I'm already deleting CConsumer objects from the heap
when the thread ends. The point is still I've got some memory leaks
related to the threads... i.e. <strcore> stuff.
I cannot understand these leaks, as I memory manage the CConsumer
objects in a proper way !
Cheers
|
|
|
|
|
Unfortunately, memory leaks are one of the hardest problems to investigate and the support given by Visual C++ to identify and fix them is not so good.
Personally, I had a try to Bounds Checker (you can get a trial version from here[^]) and I think that it's a great product: when you start a debug session, it instruments all of your executables (exe, dll, etc.) and keep trace of almost everything (memory allocations, handles, GDI resources, etc.). Finally, when you close the application it gives you a report with all the found issues: for example for each memory leak it give you a lot of informations, and it's able to point out the line in your source code where the memory was been allocated.
Hope this could help...
Cheers
|
|
|
|
|
hello guys... i have two projects. i copied all the files(*.cpp and *.h) of Proj1 into Proj2 and added them into Proj2 by right clicking "Source Files" and from the popup menu select Add->Existing Item. But compiler complains that "header.h" is not included, but it is included (in the "Header Files"). whats wrong im doing? thnx
|
|
|
|