Solved

C++ for experts help please!

Posted on 2003-11-30
4
320 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 500 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
why "." vs "->" 23 120
c++ getting the first 10 characters of a char* string 11 93
Dynamically allocate memory 9 58
operator overload: incompatible type and too many params 5 77
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

770 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