Solved

C++ for experts help please!

Posted on 2003-11-30
4
318 Views
Last Modified: 2010-04-02
Hello experts!  

I need to convert an algorithm into a bitmap image.  This is the same as a surface graph from 90 elevation and 0 rotation.  I run a program in VB that looks like this:

Dim a, b as Long

Surface.Elevation = 90
Surface.Rotation = 0
For a = 0 to 999
     For b = 0 to 100
          FunctionNeededPopulateSurface a, b
     Next b
Next a
ExportSurface "MySurface.bmp"

I populate a graphing component with this code.  I then have to export the .bmp from the component.  I would like to bypass the graphing component and build the .bmp directly.  This is 100,000 datapoints that I am calculating here. The bmp is used in a "stretch environment".   It takes about 15 seconds to get the output on my machine.  I would like to build a C++ DLL library that I can reference and call a function once and have it do the math and create the .bmp for me.  I think this should drastically cut some time.  

Any ideas on how to accomplish this?  Can I get away with only one pixel per datapoint?

Many thanks!
0
Comment
Question by:OptionsMM
  • 2
  • 2
4 Comments
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Just create an HBITMAP of the desired size, select it into a DC, and then use SetPixel() API.  The question is rather vague as to the algorithm you want to apply to a,b... but assuming a is a horizontal coordinate and b is a vertical coordinate, then all you need to do is

     SetPixel( hdc, a,b, RGB(0,0,0) ); // make the point black

Note: SetPixel() can be rather slow, but it is *always* the first pass, and then we can work on faster functions.

When you are done, you can output the bitmap to a file, or otherwise do whatever you want.

Do you need help with any of these steps?  Or do you need to also draw a grid and a legend, etc.?  Or is the difficult part the algorothim you need to "have it do the math"?  If so, please explain.  Thanks!

-- Dan
0
 

Author Comment

by:OptionsMM
Comment Utility
Hi Dan!  

Thanks for the quick reply!  I am not a c++ programmer.  I am building a 3d surface graph in a contour mode (like a topographical map).  The problem I am running into is the component gets overwhelmed trying to store 100,000 datapoints and rendering the picture as the graph spins and zooms.  I was able to solve the problem by creating a hidden instance of the chart, and then populating it with the 100,000 points.  Next I would export a .bmp and, and set the "flloor" of the graph to the bmp.  This gave me all the functionality without the slow performance.  

My idea was that simce it is a simple .bmp why not build a c++ program to generate the image and bypass creating an instance of the chart method i described above. However, perhaps it is best to write it in VB first?

I have never worked with an image before.  the code you posted didnt make any sense to me.

Thanks!




0
 

Author Comment

by:OptionsMM
Comment Utility
Here is where I am at however I only get "-1" as an output

Sub SavePic()

    Dim Pic As New StdPicture
    Dim A As Long
    Dim B As Long

    Set Pic = LoadPicture("C:\Dot.bmp")
    B = CreateCompatibleDC(0)
    A = SetPixel(B, 1, 1, RGB(255, 0, 0))
   
    SavePicture Pic, "C:\Dot.bmp"
    MsgBox A
   
End Sub
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
Comment Utility
The SetPixel() API function will not affect the variables A and B.  It only places a dot onto a bitmap.  The return value of SetPixel just indicates success of failuer -- it returns -1 when the call fails (most usually because you did not send in a valid HDC parameter)

I am still trying to understand your question.
Do you already have a function that will make A and B (or preferrably variables named X and Y) into screen cordinates?
0

Featured Post

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

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

772 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

11 Experts available now in Live!

Get 1:1 Help Now