[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C++ for experts help please!

Posted on 2003-11-30
4
Medium Priority
?
326 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
ID: 9845056
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
ID: 9846765
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
ID: 9846886
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 1500 total points
ID: 9854190
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

834 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