Solved

Questions on Graphics programming

Posted on 1998-11-10
11
243 Views
Last Modified: 2009-07-29
Now I have a BITMAPFILEHEADER and BITMAPINFOHEADER structure for handle the bitmap. bitmap size is A4 with 150-200 dpi. (about 1646x2331)
I want to do some processing on this bitmap, How can I
 1 Get/Set a specific pixel
 2 Draw sth. on current bitmap
 3 Create the projection (profile) of this bitmap
 4 Select the area of skew regtangle
and some other pixel level functions that is very fast.
0
Comment
Question by:mrbird
  • 7
  • 4
11 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1177506
Create a memory DC with CreateCompatibleDC().

Create a device dependant bitmap (DDB) from the device indipendant bitmnap DIB  you currently have with CreateDIBitmap().

Then select the DDB bitmap into the DC.

Use the API functions to draw to it.

When you are done, get the new image back into a DIB with GetDIBits().

0
 
LVL 22

Expert Comment

by:nietod
ID: 1177507
Once you have the DDB selected into the memory DC, you can use:

GetPixel() to get a pixel value.
SetPixel(0 to set a pixel value
Other API functions for drawing text and shapes.

There is no support for shearing in windows 95 & 98.  There is in NT, however.  but if you need this to work on all platforms, you will have to do it "manually".  You would do this by copying pixels to where you want them to go.  Another option would be to create a 2nd memory DC and 2nd DDB for it.  Then copy whole scan lines from the one DC to he other with the BitBlt() procedure.   The lines would be stagered to skew the image.  This sounds like more work for you, but is probably much less work for the computer, single pixel operations are very slow and should be avoided if possible.

let me know if you have qestions.

If you are unfamial with windows graphics, especially using DCs and memory DCs, let me know.  There are a bunch of pitfals to worry about.
0
 

Author Comment

by:mrbird
ID: 1177508
I'm very new to windows graphics and I don't understand DIB, DDB and DCs well.
Now I'm using Borland C++Builder3, Do you think are there any limitations with it? (I heard that C++Builder does not support DIB)
The information I have now (BITMAPFILEHEADER and BITMAPINFOHEADER) is it DIB or DDB. How can I convert to TBitmap, DCs etc. What functions I should know to perform commands according to previous question?
Thank you very much
0
 
LVL 22

Expert Comment

by:nietod
ID: 1177509
Just so you know, It is not necessary to reject an answer, if you want to "work" to a solution with an expert.  You should reject an answer only if you want other experts to assist you.  Do you?

>> I heard that C++Builder does not support DIB
It does in one sense at least.   Builder is just a C++ compiler.  Any C++ compiler (in windows) can use the full windows API (application programming interface), the huge set of functions that Windows provides that allow your programs to "do windows things", like draw graphics.  So yes, builder supports DIB.  However, builder comes with a framework, or library, called VCL.  This is a bunch of classes and procedures that "interface" with the windows API for you to make progamming windows applications easier.  This framework might not support DIB (Although I would doubt it.)  If you aren't using VCL, then this doesn't even matter.  If you are using VCL, you may have to add classes to it that would allow you to use DIB.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1177510
>> The information I have now (BITMAPFILEHEADER and BITMAPINFOHEADER)
>> is it DIB or DDB

That is a DIB.  It probably comes from a bitmap file on disk, right?  That bitmap has to be device independant, that is, it can't use a color system or data format that is appropriate for only one device, because it could be displayed on lots of devices.  For example it could be desplayed on a the screen, on a printer, or on a plotter.  Each of these devices could have color formats as well.  So the image must be stored in a device independant way, the DIB.  Then when you have a DC for the device you want to display on, you then convert the DIB to a device dependant bitmap (DDB) that is appropriate for that device (and possibly only that device).  
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 22

Expert Comment

by:nietod
ID: 1177511
I think the next question is, are you using VCL?  If so, I can't help you to use it to do this stuff.  (Unfortunately, almost no one can.  Its not very popular (yet?) so most often VCL questions seem to go unanswered.)  If you are writting in the standard windows API, then I can help you.  
0
 

Author Comment

by:mrbird
ID: 1177512
Sorry nietod, I didn't know that if I accept answer, I still can work with an expert. Please post the answer again :)

Ofcourse, I would like to use API. Please suggest me some "must know" function for doing image processing such as rotate, scale, projection (profile), select some area from bitmap. Can I select the area of skew regtangle?

I had tried to use GetPixel() with DIB I had, the result is very slow... Is it will be faster (very fast) with DC?

Thank you

0
 

Author Comment

by:mrbird
ID: 1177513
Sorry nietod, I didn't know that if I accept answer, I still can work with an expert. Please post the answer again :)

Ofcourse, I would like to use API. Please suggest me some "must know" function for doing image processing such as rotate, scale, projection (profile), select some area from bitmap. Can I select the area of skew regtangle?

I had tried to use GetPixel() with DIB I had, the result is very slow... Is it will be faster (very fast) with DC?

Thank you

0
 
LVL 22

Accepted Solution

by:
nietod earned 300 total points
ID: 1177514
>> Please suggest me some "must know" function for doing image
>> processing such as rotate, scale, projection (profile), select some
>> area from bitmap. Can I select the area of skew regtangle?
The windows API graphics procedures are pretty poor (in a sense).  They are mostly very low level, (like drawing lines and rectangles, etc).  Then there is a bunch of high level functions that are very specialized, like for drawing window captions, or menu check marks etc.  They really are missing general purpose high-level graphics functions, like you are asking about.  For these sort of things, you tend to have to write them youself.  It is best to do that in a library so that you can careate the functions they shoudl have, and can use them whenever you need them.   As for rotating and skewing images.  There may be indirect support in NT, using SetWorldTransform().  But that is not available on other windows platforms, so you probably need to give up on that and write it yourself.)  

>> I had tried to use GetPixel() with DIB I had, the result is very slow...
>> Is it will be faster (very fast) with DC?
No.   It is best to avoid single pixel operations, if possible.  Often it is.  I don't think you could rotate an image without doing single pixel operations, but you could skew it.  The bit blight (bitblt()) procedure (actually, there are a variety of these blighting procedures) is used to copy a rectangular area from one DDB to another DDB (the two DDB must be compatible--same color format etc)  You can use this to skew the image, without accessing each pixel individually.  You would use it to copy one line (or column) from one image to a new image and would stagger the destination of each line a little.  That would skew the image.  That would be slow, yet it would probably several orders of magnitude faster than single pixel operations.  (Graphics operations tend to be slow.)
0
 
LVL 22

Expert Comment

by:nietod
ID: 1177515
If you are not familiar with the windows graphics API, then I would recommend that you forget programming for a bit.  I would read everything you can find in the VC help on graphics (and or get a windows programming book that covers it).  Do two things.  

First, read it twice.  That is, when you are done, go back and read it again.  It makes an amazing difference.  This stuff is so interdependant, that most of the information in the beginning doesn't make any sense (that's okay read it anyways) but when you come back to it, having covered other stuff it begins to make sense.  (This is true about everythign in windows.

Second, make a list of questions as you read.   Most of them will get answered as you go along.  A few won't (like 1,000).  Those you can ask me.  (I'lll probably be able to answer about 10.)  

I would expect it to take about 4 to 8 hours to learn about this stuff.  
0
 

Author Comment

by:mrbird
ID: 1177516
thank you nietod
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

743 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

12 Experts available now in Live!

Get 1:1 Help Now