Solved

The proper use of Getbitmapbits in Borland OWL

Posted on 1998-05-10
16
363 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:ronzi
  • 10
  • 6
16 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1175368
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
 

Author Comment

by:ronzi
ID: 1175369
I'm using a 32 bit application.
0
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 1175370
Answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175371
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
 
LVL 22

Expert Comment

by:nietod
ID: 1175372
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
 

Author Comment

by:ronzi
ID: 1175373
Thanks nietod ,

what is "DISPLAY" and how can I tell what to use for it ?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175374
"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
 

Author Comment

by:ronzi
ID: 1175375
Hi nietod,
 
The compiler doesnt recognize the RGB sturcture. How can I define it ?

Thanks, ronzi
 
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 22

Expert Comment

by:nietod
ID: 1175376
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
 

Author Comment

by:ronzi
ID: 1175377
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
 
LVL 22

Expert Comment

by:nietod
ID: 1175378
In what sense?  What circumstances?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175379
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
 

Author Comment

by:ronzi
ID: 1175380
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
 
LVL 22

Expert Comment

by:nietod
ID: 1175381
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
 

Author Comment

by:ronzi
ID: 1175382
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
 
LVL 22

Expert Comment

by:nietod
ID: 1175383
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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now