ronzi
asked on
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
Thanks alot, Ron
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.)
ASKER
I'm using a 32 bit application.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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),"Bi tMapName") ; // Get handle to bitmap.
HDC DCHnd = CreateDC("DISPLAY",NULL,NU LL.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_C OLORS);
int Pxiels = BitMapInfo.bmiHeader.biWid th * BitMapInfo.bmiHeader.biHei ght;
RGB *PixelPtr = new RGB[Pixels]; // Allocate enough room for pixel data.
// Now get pixel data.
GetDIBits(DCHnd,BitMapHnd, 0,BitMapIn fo.bmiHead er.biHeigh t,PixelPtr ,&BitMapIn fo,DIB_RGB _COLORS);
ReleaseDC(DCHnd);
DeleteObject(BitMapHnd);
HBITMAP BitMapHnd = Loadbitmap(GetModuleHandle
HDC DCHnd = CreateDC("DISPLAY",NULL,NU
BITMAPINFO BitMapInfo;
// file in BitMapInfo, but don't get pixel data yet.
GetDIBits(DCHnd,BitMapHnd,
int Pxiels = BitMapInfo.bmiHeader.biWid
RGB *PixelPtr = new RGB[Pixels]; // Allocate enough room for pixel data.
// Now get pixel data.
GetDIBits(DCHnd,BitMapHnd,
ReleaseDC(DCHnd);
DeleteObject(BitMapHnd);
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.
ASKER
Thanks nietod ,
what is "DISPLAY" and how can I tell what to use for it ?
what is "DISPLAY" and how can I tell what to use for it ?
"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.)
ASKER
Hi nietod,
The compiler doesnt recognize the RGB sturcture. How can I define it ?
Thanks, ronzi
The compiler doesnt recognize the RGB sturcture. How can I define it ?
Thanks, ronzi
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.
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.
ASKER
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.
Now it works. The last thing I'd like to know is what command I should use to create a new bitmap.
In what sense? What circumstances?
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.
ASKER
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.
Thanks.
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.
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.
ASKER
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),fil eTitle);
it says it 'cannot convert 'const HINSTANCE__near*' to 'TResId'
Thank you
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),fil
it says it 'cannot convert 'const HINSTANCE__near*' to 'TResId'
Thank you
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.