?
Solved

C++ for experts help please!

Posted on 2003-11-30
4
Medium Priority
?
324 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 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.
Suggested Courses

765 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