The proper use of Getbitmapbits in Borland OWL

I'm trying to access the data of a bitmap but I keep getting errors using the Getbitmapbits function. Could I get an example of the proper use of this function, including prior definitions ,if any ? I'm using Borland C++ 4.5 .

Thanks alot, Ron
ronziAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nietodCommented:
First of all, is this a 16 or 32 bit application?  GetDIBits should be used for a 32 bit application.  (It should be used for a 16 bit application, if possible, but I'm not sure if it is avaliable for 16 bit.)
0
ronziAuthor Commented:
I'm using a 32 bit application.
0
nietodCommented:
Answer coming.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

nietodCommented:
I'm not sure 100% what you need.  I'l assume the bitmap in question is screen compatible (it will be if obtaied with LoadBitmap()) so the DC you use should be screen compatible.  (In any case the bitmap should be compatible to the specified DC).  I'll also assume you don't know the dimensions of the Bitmap and show you how to determine the dimensions and number of pixels before getting the data.  If you know this ahead of time it is simpler.

HBITMAP BitMapHnd = Loadbitmap(GetModuleHandle(NULL),"BitMapName"); // Get handle to bitmap.
HDC DCHnd = CreateDC("DISPLAY",NULL,NULL.NULL); // Get DC handle.
BITMAPINFO BitMapInfo;

// file in BitMapInfo, but don't get pixel data yet.
GetDIBits(DCHnd,BitMapHnd,0,0,NULL,&BitMapInfo,DIB_RGB_COLORS);
int Pxiels = BitMapInfo.bmiHeader.biWidth * BitMapInfo.bmiHeader.biHeight;

RGB *PixelPtr = new RGB[Pixels]; // Allocate enough room for pixel data.

// Now get pixel data.
GetDIBits(DCHnd,BitMapHnd,0,BitMapInfo.bmiHeader.biHeight,PixelPtr,&BitMapInfo,DIB_RGB_COLORS);

ReleaseDC(DCHnd);
DeleteObject(BitMapHnd);
0
nietodCommented:
Let me know if you need more or if this isn't working for you, or if you need help tailoring this to your specific needs.
0
ronziAuthor Commented:
Thanks nietod ,

what is "DISPLAY" and how can I tell what to use for it ?
0
nietodCommented:
"DISPLAY" is "DISPLAY" (At least in this case.)  That parameter takes the name of the device that you want to create the DC for.  This is the name of some printer ot video driver.  However, 99 times out of 100 you need the current video driver, so as a special case you may specify "DISPLAY" to get it.  This gets you a DC that can access the entire screen.  You could also use GetDC() to get a screen DC associated with a window.  (If you have a window to specify.)
0
ronziAuthor Commented:
Hi nietod,
 
The compiler doesnt recognize the RGB sturcture. How can I define it ?

Thanks, ronzi
 
0
nietodCommented:
It shouldn't.  Small mistake.  RGB is a macro that is often used to initialize a COLORREF.  COLORREF is the type that I should have used.  That is, it should read,

COLOREF *PixelPtr = new COLOREF[Pixels]; // Allocate enough room for pixel data.

I hope that helps.  Just so you know.  I'm going away tomorrow afternoon and will be gone for 4 days.  I won't be available for help while I'm gone.  If you need more help, ask soon.
0
ronziAuthor Commented:
Thanks alot nietod,

Now it works. The last thing I'd like to know is what command I should use to create a new bitmap.
0
nietodCommented:
In what sense?  What circumstances?
0
nietodCommented:
There is CreateCompatibleBitmap() that creates a bitmap that is compatible with (can be displayed on/ or edited in) with a specified DC.   This is probably what you want.
0
ronziAuthor Commented:
The bottom line of what I want to do is access a bitmap's data, change it (only the pixels), then create a new bitmap and save it as a new bitmap file or display it on the screen. My problem is creating the new bitmap since CreateCompatibleBitmap() isnt recognised by my compiler. All I need to do now is get the new image somehow on the screen.

Thanks.
0
nietodCommented:
CreateCompatibleBitmap() is what you need.  Unless I missunderstand what you mena by "it isn;t recognized by your compiler" you must have typed it wrong.  It is part of the windows API (16 and 32).  I didn't make a mistake this time.  

To do the copying part you will need to use BitBlt() or StretchBlt().  However, first you have to get the bitmap created.  Try CreateCompatibleBitMap again.
0
ronziAuthor Commented:
Hi nietod,

I think I 'm not using CreateCompatibleBitmap() properly . could you please show me an example , suppose I want to create a new Bitmap called Ron.

Besides that I get errors on the line :

HBITMAP BitMapHnd = LoadBitmap (GetModuleHandle(NULL),fileTitle);

it says it 'cannot convert 'const HINSTANCE__near*' to 'TResId'

Thank you
0
nietodCommented:
First of all, are you using some sort of library like MFC or OWL?  The reason I ask is that the TResId is not a standard windows type.  2nd why don't you post the code that is not working, that is usually more helpful  than my posting unrelated code that works.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.