Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

The proper use of Getbitmapbits in Borland OWL

Posted on 1998-05-10
16
Medium Priority
?
370 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 300 total points
ID: 1175370
Answer coming.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

876 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