|
Hi I’ve been trying to write a routine that will scan 1 bitmap to see if a second bitmap is within it. I’m not having a problem with the algorithm to do the search I’m having problems getting the pixel colors from both the bitmaps. For testing I loaded the first image by calling ::LoadImage() which returns an HBITMAP. For the second image I’m loading into I.E. and using some code to get the hwnd and pull the HBITMAP calling CopyWindowToBitmap().
So now that I have 2 variables of type HBITMAP. How do I get there pixels?
This is what I’ve tried with no success.
HBITMAP bmpOne;
HBITMAP bmpTwo;
… Some code to get bmpOne and bmpTwo ..
HDC hDC = ::GetDC(NULL);
HDC hDCBMPOne = ::CreateCompatibleDC(hDC);
HDC hDCBMPTwo = ::CreateCompatibleDC(hDC);
::SelectObject(hDCBMP1 , bmpOne);
::SelectObject(hDCBMP2 , bmpTwo);
COLORREF PixelOne;
COLORREF dPixelTwo;
PixelOne = ::GetPixel(hDCBMPOne, x, y);
PixelTwo = ::GetPixel(hDCBMPTwo, x, y);
If I do the following…
int red = GetRValue(PixelOne);
int green = GetGValue(PixelOne);
int blue = GetBValue(PixelOne);
Even though the color at x,y is not white I always get
red = 255, green= 255 and blue = 255;
I know that the HBITMAP bmpOne and bmpTwo are loaded because I display them in a dialog.
Any thoughts? Is there a way to get the pixel data directly from HBITMAP? Thanks.
|
|
|
|
|
I think you can do this by select the bitmap(s) into a device context (one at a time) and then calling GetPixel() [^].
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
GetPixel is terribly slow, can you create a HBITMAP so that it's also a DIBSECTION ? Then you'll have a pointer to the underlying bytes for this sort of work.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I second that. GetPixel() is horribly slow! The only downside with dibsections is that you'd have to take bitdepths into consideration. A small price to pay for good performance though.
--
Pictures[^] from my Japan trip.
|
|
|
|
|
I have a class called CFileObject derived from CObject and a class called CFileTree derived from CObList. At a particular point in my program, I have an if statement that tests if an object (could be a CFileObject or CFileTree) is a CFileObject. At a point in the execution, the object is a CFileTree but when it runs the test, it returns true, saying it's a CFileObject which is incorrect. Do I need to declare my two types as being the types that they are so IsKindOf() can resolve properly?
|
|
|
|
|
From the MSDN documentation[^]:
"This function works only for classes declared with the DECLARE_DYNAMIC , DECLARE_DYNCREATE , or DECLARE_SERIAL macro. Do not use this function extensively because it defeats the C++ polymorphism feature. Use virtual functions instead."
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
You could try using dynamic_cast instead. But as Ravi said, it's not good OO practice.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
|
hi
you can use the CString constructor to do this
CString strInfo(IDS_INFO);
or the Format method of CString if the reseource string needs additional paramaters
like this:
CString strHelloWorld;<br />
strHelloWorld.Format(IDS_HELLO, "world");
Regards
codito ergo sum
|
|
|
|
|
You can also use AfxFormatString1 & AfxFormatString2
if your resource HELLO_ID is: "Hello %1"
you can do:
CString result;
AfxFormatString1(result HELLO_ID, "World");
it gives u Hello World
Eric
Premature optimization is the root of all evil
|
|
|
|
|
CString strFoo;
VERIFY (strFoo.LoadString (IDS_Foo)); /ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Hmm... seems like it won't work:
---------------------------
#include <afx.h>
#include "stdafx.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
CString errors;
errors.LoadString(IDS_ERROR1);
MessageBox(NULL, errors, "Hello", MB_OK);
return 0;
}
---------------------------
Errors:
---------------------------
C:\VCProjs\KixWTF\KixWTF.cpp(14) : error C2065: 'CString' : undeclared identifier
C:\VCProjs\KixWTF\KixWTF.cpp(14) : error C2146: syntax error : missing ';' before identifier 'errors'
C:\VCProjs\KixWTF\KixWTF.cpp(14) : error C2065: 'errors' : undeclared identifier
C:\VCProjs\KixWTF\KixWTF.cpp(16) : error C2228: left of '.LoadStringA' must have class/struct/union type
C:\VCProjs\KixWTF\KixWTF.cpp(16) : error C2065: 'IDS_ERROR1' : undeclared identifier
---------------------------
Anyone know?
Thanks!
PS: <code> tag didn't work.
Sulfurik K. Nosferathus (Darth_Sulfur)
www.SulfurMidis.com
www.SulfurSoft.tk
http://www.BeepXtreme.tk
[ftp://][http://][hotline://]tsfc.ath.cx
|
|
|
|
|
I assumed you were building an MFC app. Here's[^] a link to the Win32 version of the API.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
|
Darth_Sulfur wrote: Do you know how to make a MFC app, but without a main window?
Create a console application and select MFC support.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
|
Darth_Sulfur wrote: but I have a DOS box in the background... How do I take that out?
Create an MFC dialog based application and don't create the dialog in your app's InitInstance() method. Instead, just execute whatever (non-GUI) code you wish to call. Note, your app will exit when it returns from InitInstance() .
Hope this helps!
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
|
[edit]
Fixed!
MessageBox(NULL, "Hellawz!!1!11", "Hello", MB_OK);
[/edit]
Hello everyone!
OK, I want to make a program that just displays a message box and exits. How do I do that? When I make a MFC AppWizard (exe), I get a dialog, which I don't want. When I try Win32 Application, I get a C2550 error:
'MessageBoxA' : function does not take 3 parameters
no matter if I select empty, simple, or hello world.
How can I reach what I listed? Thanks!
Sulfurik K. Nosferathus (Darth_Sulfur)
www.SulfurMidis.com
www.SulfurSoft.tk
http://www.BeepXtreme.tk
[ftp://][http://][hotline://]tsfc.ath.cx
-- modified at 4:40 Sunday 6th November, 2005
|
|
|
|
|
Hi
I used a Win32 Console application and didn't have any problems:
#include "stdafx.h"
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
MessageBox(NULL, "Hello", "Hello", MB_OK);
return 0;
}
codito ergo sum
|
|
|
|
|
In MFC, the MessageBox function works within a dialog and takes 3 paramaters, but the non MFC version takes 4, the one that is omitted is the first one, the handle to the parent window.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Try out the AfxMessageBox function ....
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
|
Hi,
I am creating a shell namespace extension by implementing IShellView and IShellFolder interfaces. The extension will show all the files inside a zip archive. Since the files doesn't physically exist on the disk, I am creating a shell extension which will show the files in the archive just like how XP shows zip files.
But I am having a problem in retrieving the context menu for the file types. If the user right-clicks on a txt file, I would like to show exactly the same context menu, which is shown by right-click on a txt file in explorer.
Could anyone please tell me how this can be done.
Any pointers to sample code / article would be really helpful.
Thanks and Regards
Jugs
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
|
|
|
|
|
This might be a very trivial question for most of you. I want to know how to write a program in vc++ for scanning a particular port on the lan. I have written a chat program, I want that whenever a user starts the client, it scans the network and finds the ip for connecting, if no server is found it will become a server. Most messengers do the same thing I suppose. Thanks in advance.
I dream so I do.
|
|
|
|